Press "Enter" to skip to content

Snake Game in Java

In my third semester at university, I had taken the ‘Computer Programming in Java’, while learning all the core concepts of java I thought it would be fun to try and make a game in the process. I tried making the snake game! The logic of the game is very simple and straight forward. If the snake head hits its own body or the edges of the screen then game over, if the snake head hits the apple then increment the length of the snake by 1 and increment the score also by 1, allow turning only in 90 degrees to avoid turning the snake head into itself – say for instance the snake is moving forward and the user presses the down arrow key; we would not want the snake to make a 180 degree turn as that will lead to a game over.

I learnt a lot of new stuff while making this game like – how to build a basic graphic user interface in java using the inbuilt packages, and how to use Key Adapters : they were used in making the snake turn when the arrow keys were pressed.

You can find the source code to the game here – https://github.com/AryanBhirud/SnakeGame_in_Java/

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *