

The head is the Square in the List located at index 0. The snake is defined as the Squares on the board that are also contained in a particular List. That's how the snake gets longer when an apple is eaten. The tail of the snake can either leave its former Square empty or not depending on whether the head has "eaten" the apple. The head of the snake is also used to determine the game over conditions based on whether it has hit the edge of the board or another snake body part. The direction that the snake head assigns to the next Square is based on which arrow key the user has most recently pressed. The head of Snake assigns these directions. The basic idea of the program is that each Square stores the direction that the snake body part on that Square should move in when the next frame loads. An instance of the GameLogic class is created by the GUI class, which handles the UI.

Every instance of Square in addition to being a Label, also has added instance variables whose getters and setters are used in conjunction with the GameLogic class. The GridPane is used to display the game to the user, and the 2D array is used internally to handle the game logic. The game board is stored as both a GridPane and as a 2D array of Square objects. The basic UI for the start screen uses FXML, but all of the UI elements in the actual game Scene were added programmatically. My game uses an anonymous instance of the AnimationTimer class as the game loop. I have made a Snake clone using Java 14 and JavaFX 14.
