0

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! :)

2 Answers 2

3

Change the stopping condition to: array.flatten.any?{|v| v=="."} (i.e while this is true carry on with whatever)

Sign up to request clarification or add additional context in comments.

Comments

0

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 

1 Comment

Sorry, I guess my question wasn't clear. But basically i'm making a game and this is a very basic version of it. The point is that the user changes the "."s manually and when there are no more to change, the programme ends.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.