End and Start a New Game
Learn to end and start a new game when the puzzle is solved.
Did the player win the game?
How can you tell if the user solved the puzzle? The puzzle is solved if the ball moves to the cell at endRow
and endCol
.
At the end of moveBall()
, check whether row
and col
are at endRow
and endCol
. If they are:
- Create a string called
message
, congratulating the user on solving the maze. - Display
message
in a message dialog using JOptionPane’sshowMessageDialog()
method.
...
private void moveBall(int direction) {
...
moveTo(row, col+1, Cell.RIGHT, Cell.LEFT);
}
}
break;
}
// puzzle solved?
if (_____________ && _______________) {
String message = "__________________________";
JOptionPane.showMessageDialog(_______________);
}
}
...
Get hands-on with 1200+ tech skills courses.