Singleplayer Overview:

(Scroll to bottom for RULES and GAME DOWNLOAD)

My plan for this game was to recreate a classic game that I loved and to add to it using efficient and creative techniques.  The primary challenge I gave myself was to create the entire games functionality using a 2D array and to make my code as efficient as possible. The 2D array stores three unique values,

4 = The head of the snake, determines what the tail segments follow

2 = the body of the snake / the tail segments. If the heads next grid position equals 2, the player will die.

3 = Apples, whenever a player head overlaps an apple a tail segment will be  added to the end of the snake


The functionality of this game doesn't use Unity's built in update function, rather the functionality of the game occurs every nth seconds (depending on the difficulty) using the InvokeRepeating() feature. This therefore determines the speed of the snake as well as ensures that code isn't running every frame.

Every time a player eats an apple a new tail segment will be instantiated and added to a List<>.  Every time the main Movement function is called, starting from the last object in the List, each object will move to the position of the object in front of them.

All collisions including wall collisions are handled using the 2D grid system. 

Important Note: (Player's can not move the direction that they have just come from).

Multiplayer Overview:

(Scroll to bottom for RULES and GAME DOWNLOAD)

 This level uses the same system as singleplayer, however some notable changes include that there are now two seperate players. Player 1 is controlled using the WASD keys and Player 2 is controlled using the Arrow Keys. 

Player's will compete to achieve the highest score via collecting apples before the other player and cutting eachother off. At the end of each game the player's will be reported with 1 point for each apple they won throughout the game and 5 points if they cut off the other player, causing them to die. 

To make this game mode more enjoyable for the players, they will not be punished for running into walls and can even hide their length from the other player.

AI Overview:

(Scroll to bottom for RULES and GAME DOWNLOAD)

The AI level uses the A* Algorithm to control the snake and find the fastest path to each apple.  This of course means that its impossible for the snake to actually win the game as it is not considering the safest path, rather the quickest. However I have adapted this algorithm to give the snake AI the best possible chance of surviving.

Whenever the snake manages to cut itself off, instead of searching for the quickest path to the next apple (which would return null as there is no possible path), it will move the its nearest neighbour that isnt populated by the snake or any of its tail segments. 

The algorithm takes into account the grid positions that it's tail segments are currently in and will not accept that as a valid node position and therefore attempt to find a valid way around it.

This level uses a combination of custom Nodes as well as the same 2D array seen in the singleplayer mode. These nodes contain the 

  • GridValue (value of position in the 2D array, e.g 0, 2, 4)
  • xPosition (x value in 2D array)
  • yPosition (y value in 2D array)
  • GScore
  • HScore
  • FScore
  • indexPosition (The position of the node in the AllNodes array)
  • ConnectedNodes (array of nodes adjacent to the current node)
  • CameFrom (The previous node on the path)


Singleplayer Rules

  • WASD to move laterally.
  •  Eating Apples (Red Cubes) will grow the player's tail, granting you 10 points each.
  • Eating your tail will cause the game to end
  • Hitting a wall will cause the game to end
  • Try get a high score, with a max of 6250 to win!

Multiplayer Rules

  • Player 1 uses WASD to move, Player 2 uses the arrow keys
  • The player won't die if they hit a wall but will die if they run into themselves or the other player.
  • At the end of the game the player is granted 1 point for each apple they have eaten and 5 points if the other player caused the game to end (ran into them)

AI Level Rules

  • No rules, sit back and see how many points the AI can score


Snake For Windows 25 MB
Snake For Mac 34 MB

Install instructions

For Mac users if the game does not initially open due to privacy issues, go to 

Settings -> Security and Privacy  ->  Open Anyway.

For Windows uses select more info -> Run anyway. Or run the application as an administrator.

Leave a comment

Log in with to leave a comment.