I have an applet. I'm trying to add restart possibility to my game. I have currently two classes. Window and Snake.
Windows class's draw:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| public void paint(Graphics g) { super.paint(g);
if (inGame) { g.drawImage(apple, apple_x, apple_y, this);
for (int z = 0; z < dots; z++) { if (z == 0) g.drawImage(head, x[z], y[z], this); else g.drawImage(cube, x[z], y[z], this); } g.setColor(Color.YELLOW); g.drawString("Points " + points, 5, 15); Toolkit.getDefaultToolkit().sync(); g.dispose(); }else{ gameOver(g); } } |
In the beginning I make int variable
counter that equals to 1. Where I put the code that is while (counter < 2){}? When you die, it sets counter to 3 and in KeyEvent when i press R it makes counter 1 again.
Currently, when i start it only grey box shows up.
Also, how can i play this applet on mobile phone?
EDIT: Sry for the spoiler, didnt know what it looks like since my mozilla has been buggin lately, and didnt know about the code thing. Thanks (: