Hungry Snake

Recommended levellevel
A long serpentine creature slithers across a limited field, obeying the player's orders (moving right, left, down, and up). And there's no way to stop it from moving. Just don't touch the boundaries or you'll die! And don't bite yourself or... well, you get the idea. Along the way, the creature encounters food that makes it even longer. As it grows, it gets more and more cramped... Stop the madness! You probably recognize this comedic storyline from the famous game "Snake". This game originated in the 1970s. That's when it first appeared on arcade machines. In the 21st century, it was popularized by Nokia, which pre-installed Snake on almost all their mobile phones. Between these two milestones, there were versions for the Commodore VIC-20, MS-DOS, ZX Spectrum, Windows, Mac OS… If you go to Google Play or the App Store, you'll probably find a couple dozen different versions of Snake. It's hard to imagine a platform that doesn't have its own version of Snake. Why? On the one hand, it's an interesting game that is perfect for passing the time. On the other hand, Snake is simple enough to create on your own. See for yourself! Use Java to write your own version of this game about the adventures of a growing reptile. On CodeGym, we've already described every step, which will help a novice player handle this task without problems. Carry on!
Comments (68)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Level 19, Tampa, United States
14 April, 22:41
@CodeGym There seems to be a small bug somewhere in the setScreenSize method it creates the screen but it is funky it has black squares. I checked a small bunch of completed ones and seem mlike all of them have this bug. Sorry if this is not the correct way to submit a ticket.
Level 41, Solar System
17 April, 14:57
Please send a screenshot or, even better, a video, to
11 April, 18:20
how do you play it🤨🤨
Level 0, India
7 April, 14:47
Dave Shapiro
Level 27, Co. Kerry , Ireland
16 March, 14:31
Heads up for anyone publishing their game! Colours aren't applied to Unicode characters in the published (browser) version. A helpful person has advised me of a handy workaround - using coloured Unicode characters. if you search for e.g. "Unicode large green circle java source code", you can find the codes in the correct format, e.g. (scroll down for the correct java encoding).
Level 1
21 February, 14:42
Raja Kumar
Level 0, Bangalore
18 February, 16:27
does any body know how to see what are the different methods inside the game class or key class. so that to see the contents of the predefine function which we are using in this game development for getting the idea how the things work in this game. in this game they have just told to inherit the game class and use the access of those method. I want to see what is inside that Game class or Key class.
Raja Kumar
Level 0, Bangalore
16 February, 05:30
whenever i compile and run there is app publish error .what is this error I'm not able to get
Level 0
13 February, 19:13
hi everyone .i am beginner programmer.i cant, please help me
Level 28
16 February, 10:02
hello, did you even try?
Level 19, Khon Kaen, Thailand
10 April, 07:54
what do you need help with?
Level 28
12 February, 09:58
I found the games to be quite poorly worded. First I tried making the Minesweeper game; I was already I believe level 12-15 something like that. I got stuck around level 6. Now I am trying to do Snake. Again, because of the way the conditions are worded (very lackluster and poorly worded) I find it very difficult to do it on my own. I don't understand how a level 5-6 would be able to complete these. It's quite disappointing and discouraging to work on these games. Is anyone else having troubles like me or is it just me?
Level 28
16 February, 09:55
I finally did it, it's a buggy version, but nonetheless I have finished it. Yay me!
Level 0
31 January, 17:26
Hi everyone. Could anybody explain me why I should use this in snake.draw(this) statement? I completely don't understand it.
Derya A.
Level 4, York, United Kingdom
31 January, 18:16
Hi cyntia. Because public void draw(Game game) is a method of Snake class, you need to call it in order to print snake to the screen. Here method accepts the Game object as a parameter because the method wants to know where to draw the Snake. In this case, because we are calling this method in the Snake Game class, this keyword refers to the Snake Game object itself.
Level 0
31 January, 19:53
thank you Derya