CS-2510 Fall 2011: Assignment 4

Due: October 13th @ 10:00 pm

Updated: October 13th @ 06:00 pm

To submit, simply copy the files together into one file (removing the second set of import statements). Both Example classes should run fine in this state.

Purpose:

To practice the design and implementation of Worlds. Note that there are many ways to implement some of the features... so use whichever technique you think best solves the problem. You will likely want to reference the World Documentation for some of the methods you will be writing.




Programming Problem 1: (Snake.java)

Grab the Lecture 9_1 notes as a starting point, and complete the implementation of Snake. There are lots of features missing; in particular make sure that you add the following:

  1. Restrict the movement of the snake such that it can not move backwards, only "left" and "right" of its current orientation.
  2. Change the tickRate() function such that it reads the rate from a field. Then make it so the tick rate is increased a small amount every time the snake eats a food object. (Hint: You will want to change the world constructor to take a tickRate and increase it for the new world when you detect a food has been eaten)
  3. Design methods to determine if the head of the Snake is hitting any of its body segments, or if any of the segments are off the grid. Combine these to create a deadHuh method in the Snake class.
  4. Design the public method boolean stopWhen() for SnakeWorld that determines when the game should stop (i.e., when the snake is dead).
  5. Design the public method Scene lastScene() for SnakeWorld that returns a game-over screen (the Scene displayed when the game stops). You can use onDraw() to get a base-scene, then place "Game Over" on top.
  6. Clean up any messy code and make sure you test your methods.

Programming Problem 2: (Zombies.java)

Finish the zombie game from Lab. In particular, add the following features:

  1. Design the public method onKey that moves the hero up/down/left/right by some amount. The signature should be as follows, though you should substitute your world class for "World":
    public World onKey(String key)
                  
    This will make the game more challenging.
  2. Make a class Zombie that extends your position class. Add a boolean that represents whether or not the Zombie is still alive.
  3. Update your methods/drawing/moving etc... Dead zombies don't move, and should be drawn differently. Here's an image you can use:
    Dead
    It's up to you how much to change; you're the designer. Note that your list classes might not need to change, unless you depend on some Zombie-specific methods later.
  4. Design methods to determine if any of the zombies are close to each other. When zombies are too close to one another (dead or alive) they die. So, you need to compare each zombie to the others to see if it should be dead... get the idea? (think about it as some combination of map and/or fold)
  5. Design methods to determine if any of the zombies are close to the hero. If you're smart about it... you could do this just once in an abstract class?
  6. Design the public boolean method stopWhen() for your World class determines if (1) all the zombies are dead, or (2) the hero has been eaten by a live zombie. Note: you'll need more than just one method.
  7. Design the public method lastScene() for your World class that returns a game-ending screen (the Scene displayed when the game stops). You can use onDraw() to get a base-scene, but use a custom message if the player wins (all dead zombies) or loses (eaten).
  8. Clean up any messy code and make sure you test your methods and have purpose statements for all classes and methods.