CSE 113 - Fall 2010 - Banner
  • CSE 113 - Fall 2010
CSE 113 - Fall 2010 - Navigation
CSE 113 - Fall 2010 - Lab 6

Lab 6
Last modified: December 01 2010 02:21:46 PM

CSE 113 - Fall 2010 - Lab 6

An Adventure Game

We will now work with the ideas of actually controlling the movement of our actors with Vectors and using the methods in the Actor class to detect edges and other actors on the screen..

If you don't remember how to do any of the steps (like, copying, zipping, etc), please refer back to Lab 1.

First, you will need to copy over the scenario for this assignment. If you are working from home, you can download the scenario here. If you are in lab, the scenario is located in /eng/class/notes/cse113/Lab6.

Take note of the following classes in the scenario:

  • AdventureWorld - the world for this scenario
  • SmoothMover - the class we looked at in lecture and is discussed in Chapter 6
  • Hero - a subclass of SmoothMover

Required Lab Tasks

Create Additional Actors

You should create classes for each of the following objects that will be in the scenario: Mushroom, Flower, GoldBall, TeddyBear, Skull. (Note the spelling/case of these class names and follow them exactly.)

Populate the Scenario

Your scenario should open with the following at various locations throughout the world: one hero, six mushrooms, four flowers, one gold ball, one teddy bear.

Moving Hero

The hero in this scenario should move "forward" whenever act is called. Note that Hero is a subclass of SmoothMover, so calling the move() method (as is already in act()) will do the job IF a vector whose values are greater than (0,0) has been set as the SmoothMover's vector. You will need to fill in the constructor of Hero so that a proper Vector is given to the superclass via a call to the superclass' constructor.

Hero Checks for Edges and Wrap Around

The hero must check for the edges of the world and wrap around if it reaches an edge left/right and top/bottom. This code needs to be written in the SmoothMover class (there are comments in that file to direct you). Note that in the method in SmoothMover, it first changes the x & y position. From there, you need to make sure that the x & y have not gone off the screen, and if so move the SmoothMover to the opposite end of the world.

Hero Turns Right & Left

When the user presses the right arrow key, the hero should turn right (visually on the screen). The amount of degrees is up to you. Analogously, if the user presses the left arrow key, the hero should turn left. At this point, don't worry about the hero actually changing direction, simply have the graphic change. Note the methods turnRight() and turnLeft() and fill them in appropriately.

Hero Actually Rotates

Now go back and make the Hero actually rotate and then move in the direction of the rotation. Remember what we know about Vectors. Vectors are a direction (!) and a length. The direction will be the rotation of the actor and the length will remain unchanged. Recall that you can get the movement vector by calling getMovement() and storing it in a local variable. Then, you can setDirection() on that vector to be the new direction.

Hero Encounters a Skull

If the hero encounters a skull, the scenario should stop. Fill in the method named checkForSkull in your Hero class appropriately. In order to test out this functionality, you must manually add a skull to the world.


Submitting the Assignment

Once you have completed your work, you will submit the zipped up version of the Lab 6 scenario.

For directions on submitting, please see here.

Please recall that you must achieve a grade of at least 50% on each of the labs to be allowed to take the second practical exam. This means, that your labs are technically all due by the last day of class (December 10th). However, if you want to stay current with the course, I would recommend having this assignment completed soon (like a week), but this material will not be on the first lab practical exam.


Grading Information

Please make sure to look at your grading information on Web-CAT. See the grading information page for more details about how to interpret Web-CAT grade reports.

The following tests were run on your assignment submission. Each test was given equal weight, so 8.3333 points each part.

  1. There are classes named Mushroom, Flower, and GoldBall in the submission.
  2. There are classes named TeddyBear and Skull in the submission.
  3. There is one hero and six mushrooms placed randomly in the world at startup.
  4. There are four flowers, one teddy bear, and one gold ball placed randomly in the world at startup.
  5. The hero wraps around top to bottom and bottom to top on the edges.
  6. The hero wraps around left to right and right to left on the edges.
  7. The hero turns right properly.
  8. The hero turns left properly.
  9. The hero moves forward whenever act is called.
  10. The hero moves forward whenever act is called (repeated - it is worth 16.666 points)
  11. When the hero encounters a skull, the scenario stops.
  12. When the hero encounters a skull, the scenario stops (repeated - it is worth 16.666 points)

Lab authored by Adrienne Decker

CSE 113 - Fall 2010 - Footer

Page maintained by Adrienne Decker

Contact: adrienne@buffalo.edu | 130 Bell Hall | (716)645-3184