For this homework, you will need to use the ProfessorJ Intermediate language.
Examples class that contains all
your tests. Before you turn in your final program, please comment out
any test that draws on the Canvas.
return true;. Later on
you can go back and reimplement the method the way you actually want it to
work.)
draw for all classes that represent
components of this game, as well as for the class that represents your
game world.
onTick() in the Star class.
onTick() in the classes that
represent a list of Stars.
onTick() in the UFO class.
makeStar that
produces a new Star at a random horizontal position at the top of the
Canvas, with some randomly-chosen lifespan.
The following code can be used to generate a random number in the range 0 to 4:
// produce a random number in the range 0 to 4
int randomNum(){
return new Random().nextInt() % 5;
}
Modify this method as needed to generate a number in the desired range. You
must also
add the following import statement to the other import statements at the
beginning of your program:
import java.util.Random;The introduction of random numbers makes testing trickier. You can construct tests that check that each field of the newly-created Star satisfies some condition.
foundStar() in the classes that represent a
list of Stars. foundStar() consumes a UFO and determines
whether or not there is a Star in the list that is close enough to the UFO to
be caught. You may use the built-in method Math.abs()
that computes the absolute value of
a number; for example, the expression
Math.abs(-4)produces the value 4.
caughtStar() in the classes that represent
a list of Stars. caughtStar() consumes a UFO and produces a Star
that the UFO can catch. This method must not be activated unless you have
already verified that there is a Star in the list that is close enough to
be caught. If there are two or more such Stars, the method should produce the
first one it finds.
You will need to implement this method in your empty list of Stars class, even though the method will never be activated on an empty list of Stars. You can just have the method produce any old Star for this circumstance.
catchStar() in the UFO class. It consumes
a Star and produces a UFO with its fuel supply increased by the Star's
lifespan.
replace() in the classes that represent
a list of Stars. replace() consumes a Star and replaces that
Star in the list with a new Star produced by the makeStar()
method. (Hint: remember we talked about Java's Object class, and the
fact that Object defines a method equals() that returns true
if this Object is the exact same Object as that one? equals()
will be useful here.)
onKeyEvent() in the UFO class. The
method consumes a String that represents the arrow key pressed by the
player of the game and produces a UFO at a new location.
onKeyEvent() in the class that represents
your game world. The method should consume a String as above, and return a
new game world based on the player's input.
onTick() in the class that
represents your game world. It
needs to check to see if the UFO has run out of fuel, or if the UFO has
caught a Star. If a Star has been caught, it should be replaced. If neither
of these conditions is true, the method just lets the clock tick.
Have you tested everything? If so, then go ahead and try playing the game.
Define a method called go() in your game world class, and activate
it from the Examples class, as shown in the Exploding Sun example. Have fun!
Using web-based turnin, turn in a single file hw4.username.ijava (where username is the wpi login name of one of the partners in your hw pair) containing all code and documentation for this assignment. Both partners' names and wpi login names should appear in a comment at the top of the file.