A2: Drawing & Events


You will implement Snake, a classic 2D video game where the objective is to control a line as it grows in length while preventing it from hitting the edge of the screen or itself (Wikipedia).

Snake game.

There are various versions of Snake playable on the web such as this one. The general rules of the game are:

Functional Requirements

Technical Requirements

  1. Implementation must be done in Java 11 or higher, and run on a desktop OS (Windows, OS X, or Linux). You are allowed to use the Java platform libraries, but you are restricted to JavaFX toolkits for the GUI. You are not allowed to use any other libraries or source code.
  2. Your project should use Gradle to manage builds: "gradle build" should run your program, and "gradle run" should run it.
  3. Your project should be in a folder named "a2" and the directory structure should look something like this. (It doesn't need to match exactly, and will vary a little based on how it was created). Make sure that gradle can build and run it from within your "a2" directory.
  4.     a2/
        ├── a2.iml/
        ├── build/
        ├── build.gradle
        ├── gradle/
        ├── gradlew
        ├── gradlew.bat
        ├── settings.gradle
        ├── readme.md
        └── src
           └── Main.java
  5. Include a readme file (readme.txt or readme.md) with a description of the game, the enhancements, and the development environment (e.g. Operating System, JDK version, etc). Include anything else that TAs should know when grading.


Submit your assignment to your personal Git repository, under the a2/ directory.


Markers will test your application by building and running your code using Grade. Your submission will be assessed, roughly, as follows:

Code compiles and runs.
Includes a README.txt describing the development environment, and enhancements that you implemented.
Functional requirements: gameplay plays and progresses as described.
Technical requirements: event-handling, repainting properly, support for a reasonable framerate (25-50 FPS).


1.0. Aug 18, 2020. Initial draft.

1.1. Sept 14, 2020. Clarified movement, rules for creating new fruit. Added high score display.