Reputation: 545
I have my array:
array = Array.new(10) { Array.new(10 , 0)}
Which when printed out contains a 10x10 grid of 0s.
During the programme some of the elements of the array are replaced with "."
The user then has to change all the elements which contain "." so that they contain "x".
So I'm trying to make a loop which keeps asking the user to input numbers which refer to elements until the array contains no more "."s and puts "Game Over"
Therefore I need to make a loop which keeps going until all elements of the array are not equal to "." So this is what I came up with which doesn't work
until array != "." do
Sorry, I have very little knowledge of Ruby so my terminology isn't great.
Thank you! :)
Upvotes: 0
Views: 72
Reputation: 300
Change the stopping condition to: array.flatten.any?{|v| v=="."}
(i.e while this is true carry on with whatever)
Upvotes: 3
Reputation: 5755
Loop through all the elements of each subarray, changing the elements if they are equal to '.'
array.each do |subarray|
subarray.each do |e|
e = 'x' if e == '.'
end
end
Upvotes: 0