The Maze

SAMPLE APPLET:

HINTS:

Hint 1) You will need to make a 20x20 array to represent your maze. You should populate this with zeroes and ones (with the zeroes representing open cells and the ones representing walls). A similar technique has been used in previous lessons. Hint 2) The following code snippet shows you how to test for a certain key and then defines an action to take when that key is hit. This code snippet goes into your KeyPressed method. if(k.getKeyCode()==KeyEvent.VK_UP){ if(current/20>0 && grid[current-20]==0) current-=20; } Other keycodes are: KeyEvent.VK_DOWN, KeyEvent.VK_RIGHT, and KeyEvent.VK_LEFT. Of course, you don't HAVE to use the arrow keys, but you will have to figure out keycodes for other keys on your own if that's what you want to do! Hint 3) This code snippet shows you how to draw the maze in your paint method. Notice the use of the modulus and division operators. You will need to use these operators a few times in this applet. for(int i=0; i<grid.length; i++){ if(grid[i]==1) offG.setColor(Color.black); else offG.setColor(Color.white); offG.fillRect(10+10*(i%20), 20+10*(i/20), 10, 10); }