Hello there how are you all. I am trying to make a Snake Game in Java and have managed to set up the cells required for the snake to move around in.
What i am trying to do now is place food randomly. This method should find a randomly chosen clear cell. I was hoping i'd use a do-while loop.
I understand to choose a cell, i will need to choose its X and Y values randomly an that these must lie in the range zero to one less than the size of grid.
To obtain two integers in range 0.0 to n-1, i was hoping i can use the following:
x = (int) (Math.random() * n);
y = (int) (Math.random() * n);
Any ideas on the do-while loop because i cannot get it to work.
Please Help
Kind regards
Shyam