Draw Required Balls on Maze
Learn to draw the current, end position balls and add methods for drawing the path taken.
Adding cell methods for drawing balls
Next, look at how to solve the puzzle. You will mark the end of the puzzle with a red ball and the user’s current position in the puzzle with a green ball.
- Add private Boolean instance variables called
current
andend
, each initialized to false.
...
private boolean[] wall = {true, true, true, true};
private boolean current = false;
private boolean end = false;
...
MazeGenerator will need a way to make the cell current.
- Add a public method called
setCurrent()
. It should take one parameter, a Boolean calledcurrent
, and return nothing. - Use
this.
to set the instance variablecurrent
to the current parameter value. - Repaint the cell using JPanel’s
repaint()
method.
...
______________ setCurrent(_____________) {
_________.current = __________;
____________;
}
...
Get hands-on with 1200+ tech skills courses.