Skip to main content

Snake

Overview

A. Goals

This is a closed-ended project that provides you the opportunity to apply everything you have learned in CIS 1100 to building a game of Snake. You are given a small bit of starter code that you can use to reach the first checkpoint for the assignment. After completing the first checkpoint, you will need to make choices to expand your codebase with additional methods, instance variables, and data structures. We highly recommend taking time to think through the structure of your project before you start coding past the first checkpoint.

Start early and reach out if you have any questions or concerns.

You may be tempted to use code directly from the internet or use such code as a base template. Please do not do so. We are adept at catching such cases and strict action will be taken. As discussed in lecture, LLMs can be helpful, if overly powerful, tools for helping you learn & program. Using LLMs like ChatGPT to generate code for you is explicitly not permitted in this assignment. Some uses that are permissable & might be helpful: asking ChatGPT to explain a high level Java concept to you, to explain compiler or runtime errors, or to explain/summarize code from a previous assignment or class example.

B. Project Structure & Checkpoints

In this assignment, you will implement the classic game of Snake. Your project must use ​object-oriented​ design. A basic skeleton for you to use is provided, but you will need to expand it eventually. You do not need to adhere to any fixed set of classes or methods, but be aware that exercising your ability to use & design objects is an explicit learning goal of the assignment. If you implement your entire project as static, with no object instances, you will lose significant points.

This is a challenging assignment that you will be completing during a very busy time of the semester; consequently, we want to make sure that you have a clear picture of what grade you can expect as you progress through the assignment. This will allow you to make informed choices about how best to budget your own time.

To that end, there are several checkpoints laid out in these instructions. Each states the grade that will be earned by successfully meeting the requirements for that checkpoint. You may choose to stop at any checkpoint, and it is strongly recommended that each time you successfully reach a checkpoint, you save a copy of your codebase at that time. That way, if anything breaks in your implementation, you have a guaranteed minimum grade to fall back on.

C. Snake

Please take some time to play an example implementation of the Snake game, like the one available here. Your game will not behave or look exactly like this one, but it will be similar.

Snake is a game played on a 2D board. After the game starts, the snake will always be moving in a cardinal direction. The player can change the direction in which the snake is moving by pressing the W, A, S, or D keys on the keyboard (corresponding to “up”, “left”, “down”, and “right”, respectively). The snake has a body comprising several segments. The first segment is the head, and the snake starts with a single segment. When the snake moves, the head moves one square in the direction the snake is moving, and the rest of the segments of the body move to occupy the space that the segment in front of them previously occupied. When the snake eats a piece of food, the snake grows by one segment. The game ends when the snake collides with itself or with a wall.


Checkpoint 1

The starter files on Codio are SnakeGame.java, Board.java, and Snake.java. These files (copies of which can be found here) and the methods contained therein are the only ones that are needed to create a complete implementation of the first checkpoint. If you prefer to implement the project from the ground up on your own, that’s entirely acceptable as well—these starter files are intended to help you reach the first checkpoint more easily rather than to restrict you. Additionally, you may add methods to these classes and you may add any additional classes as you see fit. Probably you will find the first three classes sufficient for the first checkpoint, but you might find it helpful to write an additional method or two.

To meet the first checkpoint, your submission must meet all of the following requirements:

Throughout the assignment, you are welcome to leave the looks of the game very “barebones” or you may choose to make the game look nice. Either is fine, although submissions that have visible bugs in presentation (flickering shapes, inconsistent coloring, misaligned shapes, etc.) will lose points.

Things that are not required for this checkpoint, but will be addressed in future checkpoints:

After this checkpoint, your game should look similar to this.

Submissions that meet all of these requirements will receive a completeness & correctness score of 10/40 points. (With good style & a complete readme, this will likely lead to a 30% score on the assignment, which would permit you to use this assignment as your “drop”.)


Checkpoint 2

To reach checkpoint 2, your program must meet the requirements for checkpoint 1. Points will not be awarded for any of the features in this checkpoint if you do not have the features from the previous checkpoint.

The snake itself does not need to grow for this checkpoint.

After this checkpoint, your game should look similar to this.

Submissions that meet all of these requirements will receive a completeness & correctness score of 15/40 points.


Checkpoint 3

This will likely be the most challenging checkpoint to complete.

To reach checkpoint 3, your program must meet the requirements for the previous checkpoints. Points will not be awarded for any of the features in this checkpoint if you do not have the features from the previous checkpoint.

When testing submissions for this checkpoint, we will not be testing for what happens if the snake collides with itself or with a wall. Those collisions will be tested in the next checkpoint.

After this checkpoint, your game should look similar to this.

Submissions that meet all of these requirements will receive a completeness & correctness score of 25/40 points.


Checkpoint 4

To reach checkpoint 4, your program must meet all of the requirements for the previous checkpoints and must also meet all of the following requirements:

After this checkpoint, your game should look similar to this.

Submissions that meet all of these requirements will receive a completeness & correctness score of 30/40 points.


Checkpoint 5

To earn the remaining ten points for completeness & correctness, you must choose to implement some combination of the remaining features. You cannot earn more than 10 additional points, meaning that there is no extra credit.

  1. Add a “hard mode”. In hard mode, the snake moves faster than in normal mode. The snake should move at least twice as fast in hard mode as in normal mode. The player should be able to toggle between normal and hard mode by pressing a key. The game should start in normal mode. (5 pts)
  2. Add bonus food items that are worth more points than regular food items. These should appear an random locations at random intervals. Eating one of these bonus food items should grow the snake by the regular length but add some extra number of points to the score. (5 pts)
  3. Add a title screen to the game that appears when the game is launched or restarted (3 pts).
    1. The player must press a key to start the game like normal, but the screen that the player sees at the start of the game must be different than just a “paused” snake game.
  4. Add a “high score” feature that keeps track of the highest score achieved in the current session. The high score should be displayed somewhere on the screen at all times. (2 pts)
  5. Add obstacles to the game board that the snake cannot pass through. These obstacles should be present somewhere other than on the edges of the board in order to earn points. (3 pts)
  6. Before the game starts, allow the user to press a key/button that removes the condition that the player loses when the snake collides with a wall. Instead, the Snake should “teleport” (like in Furious Fish), segment by segment, to the opposite side of the board. The player should still lose if the snake touches itself or another obstacle that you may have implemented. (2 pts)
  7. Allow the player to write their initials after each game over to save their score. Write these scores using Out.java so that this history is permanent and maintained between executions of the program. Either or both of the following extensions can be completed for points:
    1. For 2 pts, allow the user to be able to press a key or navigate using a menu to see all saved scores in game. (2 pts)
    2. For 2 pts, display the top 5 scores (with the initials) on the title screen. (2 pts)

Submission

Submit all files necessary to run your game to Gradescope. You should also submit readme_snake.txt in which you must write how to run your game and explain the features you may have selected for Checkpoint 5.