


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The creation of a snake game using java, with a focus on two-dimensional arrays and a singlylinkedlist. The game's objective is to control a snake, avoiding collisions with the board's edges or its own body, while eating targets to grow longer. Background information on the game, class instructions, and an assignment to create a coordinate class, edit the snakeboard class, and edit the snakegame class.
What you will learn
Typology: Lecture notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!
Objective : To use a two-dimensional arrays and a SinglyLinkedList to create the Snake game. Background : The Snake Game has been around since the 1970’s in one form or another. The first programs were rendered completely with ASCII characters on a terminal, then later with more sophisticated graphics on computers and eventually on handheld devices. The allure of the game is its simplicity in the interface and the rules while being completely addicting to play. Our game will be modeled on the original ASCII version played on a two-dimensional grid or “board". The “snake” will be a series of characters with the head (@) followed by tail segments (***). An example of the board below shows the snake with a head and a four segment tail. The user will control the snake and command the head to move up, down, left, or right with the body trailing behind. The snake can only move to open locations and cannot go off the board or cross over itself. In the game, you will lose immediately (snake dies) if either move was attempted. The objective of the game is for the snake to “eat” as many targets as it can. When a target is eaten, the snake’s tail grows by one segment and a new target location is chosen at random on the board. The longer the tail grows, the less open spaces are available, and the more difficult it is for the snake to move. In the figure below, the snake’s tail has become so long it is blocking a clear path to the target. In our game, we will use an array to represent the board and a SinglyLinkedList to represent the snake.
Coordinate and Snake classes : You will need to write a Coordinate class. A Coordinate object holds one location on the board. It has a row field and column field, and the constructor initializes those fields. There are also two accessor methods, getRow() and getCol() , and an equals() method. The Snake class is almost complete. Open the file and take a look. Notice the first line of the class definition. public class Snake extends SinglyLinkedList
Assignment - SnakeGame :