CS 2510 Spring 2012: Lab 5 - Designing World Games

copyright 2012 Felleisen, Proulx, et. al.

Goals

The goal of this is to learn how to use the funworld library for designing interactive graphics-based games. and to work a bit on our design skills.


Partner change

Switch partners and report the new partnership to your TA, so we can set up a repository for the new groups.

1  The funworld library.

Start the lab by looking at the early release web pages for the funworld library. Browse through the pages and see how the World is built. Build a project named WorldGames and import the files and TickyTack.java inton it. Download three additional jar files: funworld.jar, colors.jar, and geometry.jar and add them tho the classpath. The links are given at the FunWorld instruction page. Add the tester.jar to the classpath, set us a new RunConfiguration that allows you to run the program for each of these two programs, and run each of the games.

You can use these programs as a guide for how to use the various features of our library.

2  Getting familiar with the Ocean World.

We will now design most of the game that has been the topic of several lectures: the OceanWorld.

  1. Start a new project named OceanWorld and import into it the file OceanWorld.java. It contains most of the code shown on the course blog with some additions and changes.

    You will also need two images that the program uses: shark.png and pink-fish.png. Download them anad save them in your project directory --- the one that contains the src subdirectory.

    Read the code, then run the program and check the results.

  2. Design the method onKeyEvent that moves the shark up and down in response to the "up" and keys. Make sure you follow the design recipe and have tests for all methods.

  3. Design the method onTick that moves the school of fish 3 pixels to the left. Make sure you follow the design recipe and have tests for all methods.

  4. Modify the method onTick so that every fish that escaped to the left is replaced by a new one on the right. Make sure you follow the design recipe and have tests for all methods.

  5. Design the method worldEnds that ends the world when the shark's health is below some fixed threshold (for example 3). Make sure you follow the design recipe and have tests for all methods.

Make sure you keep updating the TEMPLATE as you go along.

When designing a method, copy the template from its fixed position, add to the template any new information based on the arguments the method consumes, then design the method. Once you have the method body, you can delete the template you have used.


2  Designing the game

You are now on your own -- we want you to finish designing this game.

  1. Design the method that modifies the way school of fish moves, so that if the fish has moved off the canvas, it is replaced by a new fish somewhere on the left.

  2. Design the method worldEnd that ends the world when the shark starves to death. The user should see a message that indicates what had happened.

  3. Design the method that produces the food value of the first fish in the school that is close enough to the shark to be shark's food.

  4. Design the method eatFish(int foodValue) that produces a healthier shark, after the shark has devoured the given fish.

  5. Suppose a fish is to be eaten by a shark. Design the method sharkFood in the class Fish that produces a new fish, now that this on has vanished.

  6. Now design the method that replaces the first fish in the school that can be eaten by the shark by a new fish at the other end of the ocean.

  7. By now you should have all the parts of the game and should be able to play the game.

ENJOY!

Last modified: Tue Feb 7 09:47:07 EST 2012