First Java Project: Snake Game

Yes I know, pretty basic

Screenshot of Snake

How the game is played

I hope from the screenshot below, you are able to tell what the classic game above is. It is called snake and the premise of it is to move the snake around the board to "eat" the apples. As the snake eats the apples, it becomes longer making it more difficult to maneuver around the board. The game is over when the snake either hits its own body or hits the edge of the board.

In action gameplay

How I built it

This was my first Java project and I found coding the language interesting as it is a statically typed language compared to something like python which is dynamically typed. This means that you must declare the data type of the variable before assigning a value to it. I was able to build the game by following along with a tutorial, which was helpful in understanding what each line of code intended to do for the application.

As for the components of the application, it is broken down into 2 parts, the game frame and the game panel. The game frame is pretty simple as this is just a class that incorporates the game panel and simply creates the Java application.

The game panel is where all the functionality of the game is located. Java's Abstract Window Toolkit (AWT) is the basic API that is used for the basic functionality of the snake. A grid is created with x and y coordinates and each colored block represents a body of part of snake. By using KeyEvent method, one is able to control the direction of the snake in order to eat the apple. The only uniqiue functionality here is that when moving in a certain direction one cannot move in the opposite direction (e.g. snaking is moving right and then hitting the left key) to avoid running in the body resulting in a game over.

Game Over Page

Java

what I know about it so far..

Disclaimer: I tend to be more comfortable coding in python, however I am currently in the process learning more Java in order to learn the structured rules of data management. From my research, the reason Java became an innovative programming language is that, compared to other programming languages such as C++, it does not compile to machine code but rather to byte code that came be run on any operating system. Pretty cool, I still have to do more research to exactly figure out what that means...