Skip to content
Advertisement

How do I restart Snake game (Java)? [closed]

I’m a beginner so I used Bro Code’s (a YouTuber) version of snake game. It’s almost identical with minor adjustments, but I’ve been trying to figure out how to restart the game when I die. I’ve tried making a restart button and tried to make it restart with a keystroke but I’ve got no experience coding so I couldn’t figure it out. Here’s the source code:

JavaScript

Advertisement

Answer

This is the solution, Pressing Enter will close the previous window and open a new game window. Let me know if you don’t understand something so I can explain it to you!

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement