Topic 1 - Variables and Data Types
Topic 2 - Conditionals and Strings
Topic 3 - Loops
Topic 4 - Arrays
Topic 5 - File Handling
Semester 1 Projects
Topic 6 - Classes/Objects and Methods
Topic 7 - ArrayLists
Semester Projects

Part 1d: Creating the Initial Snake

In MainClass.java:

  • In run():
    • In this method, you’ll initialize the provided snakeBody ArrayList. 
  • Create a method drawSnake() 
    • You’ll need to create 10 SnakePart objects and add them to the snakeBody ArrayList (or however long you want the initial snake to be).
    • Once added, loop through the ArrayList and add each SnakePart to the canvas. 
    • Think carefully about how to set the x and y coordinates of each SnakePart. You’ll want to think about where the “front” or “head” of the snake is. Each of the snakeParts extends GRect, so look at the documentation for that class for any useful methods.
    • You may start the snake on any part of the board that you would like. You can also use any color or style that you would like. If you want to use something other than GRect for the SnakePart objects, you’ll have to make the appropriate changes.
    • Take a close look at the SnakePart constructor for info on how to initialize those objects.