Due: Monday, February 10, 4 PM (in class).
Here is a (partial) solution. The code is in the new version of the game package $CS680/games2.
This homework will serve as your introduction to the existing version of the game package. We'll be working on enhancing it and reengineering it for several weeks, learning design and design patterns along the way.
You will find all the code for version 1 of the games package in $CS680/games1.
game = (Game)(Class.forName(gameName).newInstance());
in PlayGame.java by the call
game = GameFactory.create(gamename);
That means you will have to design and write the factory class
GameFactory in package game. Read about the factory design pattern in
Jia, pages 294-295. Don't bother with a GameFactory interface. Just
write a static method in class GameFactory. You might want to check
out the reference in the footnote on page 295.
Since some of the classes are in the game package and some are not, you need to get the classpath right. In $CS680/games1 you can run PlayGame this way:
java -classpath classes:gamepackage/classes PlayGame Easy SpeedyTo compile and run your own versions, copy everything from games1 (including the makefile) and work from your own place. Use
cp -r
to copy subdirectories recursively.
114 m = ((ComputerPlayer)player).findbest(g);in PlayGame.java when the ComputerPlayer is an instance of class Speedy and the Game is Easy. (II haven't done this myself yet. It may be quite complex. If it gets too long, you may fudge some of the deeper stuff as long as you show clearly that you really understand how a UML sequence diagram works.)
The games to be translated are in $CS310/games1/c. Choose the one you want to work on. Follow this link to find the current assignments and a discussion of the port to Java from C.
No due date has yet been set for this part of the assignment.
Leave source code in a hw2 subdirectory of your cs680 course directory. Do not alter any permissions.