Consider letting the less experienced member of the group do the typing if it seems like there's a mismatch in experience or comfort levels. That will help make sure they don't get left behind. Worst case, flip a coin to see who does the typing. Or have Java generate a random boolean value. (Type (new java.util.Random()).nextBoolean()
in the codepad.)
At the conclusion of the lab, make arrangements for the typer to share a copy of the code with the other member(s) of the group. (E.g. email it, or put it on a shared Google drive, etc.) My solutions to the lab will get posted as well.
Controller
, two different classes that can or will be controlled by it (AdventureGame
and MarsRover
), and a Tester
with a main method that starts a round of the adventure game. Run the Tester's main method and play around with the game:
AdventureGame
code to get a feel for the methods it contains and how it works. The graphical "remote" has five buttons on it, and each of those buttons causes one of AdventureGame
's methods to be called. Can you figure out which five methods in AdventureGame
those are?
Controller
. You don't need to understand the code that creates the GUI or handles the buttons as they're pressed, but make an effort to see how the code has been tailored to interact with an AdventureGame
instance. (Search for "AdventureGame", for example, to see where the class is referred to in the Controller
code.)
Controller
class so that instead of working with AdventureGame
, it works with the MarsRover
class instead. Edit Tester
and verify that the controller really does control the rover. (Uncomment the last two lines in main
, and comment out the line that created the original controller.) Note: An annoying delay has been introduced here when controlling the rover — in real life it takes between 4 and 20 minutes to get a signal to mars!
Controller
so that it can work with either an AdventureGame
or MarsRover
instance. That will require making it polymorphic: the constructor should be able to take either kind of object and control it. Since the game and the rover aren't very similar classes, we'll use an interface to pull this off:
Remoteable
interface in class.
Controller
class to use the interface, rather than AdventureGame
or MarsRover
.
AdventureGame
called TrickyGame
that cheats somehow. (For example, change the location of the flashlight every once in a while, or lie when giving hints.) Don't have it implement the interface — just extend AdventureGame
.
Tester
class and see if you can control a TrickyGame
with the polymorphic Controller
. Should it work? Does it?
TrickyGame
both extend AdventureGame
and implement your interface? Does that change the results of the last experiment?
Comparable
interface. Modify AdventureGame
so that it implements Comparable<AdventureGame>
— that is, add a compareTo
method that determines whether a given game instance is less than, equal to, or greater than another game instance. (You could base that decision off of the distance between the player's current position and the flashlight, for example, or the player's location — you decide.)
Comparable
interface, see if you can sort a collection of game instances. See this code for an example of how I sorted a group of Radio
s in class.
up()
on each of them, for example?
compareTo
method in AdventureGame
so that a caller could ask you to compare an AdventureGame
instance to any other kind of object?
AdventureGame
and MarsRover
being subclasses)? Which methods would be abstract and which would be concrete (fully defined)? Which approach seems best (interface or abstract class)?
MarsRover
throw an exception if the rover goes off the edge of the "world".