private void createNewNumber() {
while (true) {
int x = getRandomNumber(SIDE);
int y = getRandomNumber(SIDE);
if (getCellNumber(x, y) == 0) {
setCellNumber(x, y, getRandomNumber(10) == 9 ? 4 : 2);
break;
}
}//TODO: my solution is not accepted although it works perfectly
My program is working but fails the test why?
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
18 December 2020, 17:03solution
You have 2 components in this game to consider, the database (gameField) which actually stores all the values, and the view that is displayed to the user. The handling of printing the view to the user is delegated to the draw scene method which takes all the values in the database and displays them in the correct cell on the screen.
Now with the code that you shared here the method is setting the value on the screen but not setting the value in the database. Because the printing is handled in the display() method, it would be the incorrect to do so in the createNewNumber() method. While your logic, otherwise, is correct; this method should only be setting the database value and not printing to the screen.
+3
Liliane Top Backend Developer at Procura
18 December 2020, 17:16
I'm so happy you're still around!!
+1