This was one of my first few arcade games that I worked on at the beginning.
Firstly as you can see these are all the images displaying the code that was used to build the Snake Game.
First piece of code on the first image is the class name: "Main" it's a main class to call unit all other classes by executing the functions made in other classes.
Composed of the the actual game window which we call "Board" that's out object
Then we have a Welcome statement and the exit default operation meaning to close the game when we exit
As I mentioned earlier in this class we develop the game board for the snake.
we use import to bring in the tools like the layout tool Grid, tool for Key identification and movement, and for array placement in the board. All incorporated into the Frame
We are using array list to set up the board with the width and heigh integers
We have numbers like 2 by 2, and 20 by 20 to develop the size of our grid. For which we use for loop to expand our layout.
This class as you can see represents even block by an int x and int y.
we use int like x and y to get the spacing between each block.
Snake color we call the first myColors1
and our panel which is the layout of the game board is in multiple squares.
We are using squares so we can organize our objectives like the food, the snake and the movement into number blocks.
We want to develop cases in which we organize our movement and snake-turning with our Key switches.
This class is quite long because it's focused on the square distribution for the board, also the snake size as you can see which is 3, but that is the starting size, meaning it will grow bigger every time it eats the Cue FOOD.
We also set up a function method called run() and this is true in all cases meaning that it will pause the game and run other function that will be used to perform certain action in the game.
As you can see in this class the movement and position of the snake is based on the loop that we use to increase the size of the snake whenever the snake reaches the food block. if it reaches the food block, then its size increases, and that makes the game quite different and even more difficult.
It focused on the Background color, as you saw earlier whenever this class is called upon, it uses background color to change the movement. This squarePanel which be changes to an object (repaint() ) Whenever we call repaint() we know it's related to background color.
If you noticed you can see how the tail of the snake is increasing in size because that's what we wanted when we wrote it in the code.
Next you can see how size has changed throughout the movement we made, and how difficult it is to navigate in a space that's quite limited.
Our game end with a closing statement letting us know ANACONDA ATE YOU! Game over
This was the development of the Snake Game in Java Program.
Thank you!