 |
| The Thing class hierarchy. |
For this thy sixth homework, which does appear after the fifth but before the seventh, you shall implement the simple game of Camelot. Camelot, you see, is a silly place where peasants pathetically move about insisting they are not dead yet while brave knights honor thy King by slashing them to bits.
You will implement the classes shown in in the figure, along with a Game class which holds the board description. The specific methods that each class will implement are explained in detail in
the Javadoc documents for Camelot (which you
must read and follow). Notice that the documentation tells you exactly which methods and which properties you need to implement for every class. The
Animated class has a
protected enum Direction {N,S,E,W}; which shows up as
Animated.Direction in the javadocs.
The program will have a
main in the
Game class which looks like this:
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
Game g = new Game();
g.add(new Sword(3,3));
User user = new User(1,4);
g.add(user);
g.add(new Knight(5,5));
g.add(new Peasant(9,5));
g.add(new Peasant(6,7));
g.add(new Peasant(4,8));
g.add(new Peasant(7,2));
g.add(new Peasant(3,5));
String command = "";
do {
System.out.println(g); //print out the game board
System.out.print("Your move:");
command = keyboard.next();
user.move(command); //move the user
g.moveAll(); //move everyone
g.resolveConflicts(); //resolve any conflicts between those in the same row,col
} while (user.isAlive());
}A sample run of the program looks like:
__________
____Y_____
__________
___S_P____
________P_
_____K____
_______P__
__P_______
__________
_____P____
Your move:south
Knight moves S
Peasant moves E
Peasant too weak to move.
Peasant too weak to move.
Peasant too weak to move.
Peasant too weak to move.
Peasant too weak to move.
__________
__________
____Y_____
___S_P____
________P_
__________
_____K_P__
__P_______
__________
______P___
Your move:west
Knight moves W
Peasant moves S
Peasant too weak to move.
Peasant moves E
Peasant too weak to move.
Peasant moves N
Peasant too weak to move.
Peasant too weak to move.
Peasant too weak to move.
______P___
__________
___Y______
___S_P__P_
__________
__________
____K___P_
__P_______
__________
__________
Your move:south
Knight moves W
Peasant moves N
Peasant too weak to move.
Peasant moves S
Peasant too weak to move.
Peasant too weak to move.
Peasant moves E
Peasant too weak to move.
Peasant moves E
Peasant too weak to move.
User picks up Sword
__________
__________
__________
___Y__P_P_
__________
__________
___K______
___P____P_
__________
______P___
Your move:east
Knight moves W
Peasant too weak to move.
Peasant too weak to move.
Peasant moves E
Peasant too weak to move.
Peasant moves W
Peasant too weak to move.
Peasant too weak to move.
__________
__________
__________
____Y_P__P
__________
__________
__K_______
__P_____P_
__________
______P___
Your move:east
Knight moves S
Peasant too weak to move.
Peasant moves S
Peasant too weak to move.
Peasant moves W
Peasant too weak to move.
Peasant too weak to move.
Peasant moves S
Peasant too weak to move.
Bloodthristy Knight kills a P
__________
__________
__________
_____Y__P_
______P___
__________
__________
__K_______
________P_
______P___
Your move:south
Knight moves W
Peasant moves W
Peasant too weak to move.
Peasant moves W
Peasant too weak to move.
Peasant moves N
Peasant too weak to move.
Peasant moves S
Peasant too weak to move.
__________
__________
________P_
__________
_____Y____
______P___
__________
_K________
_______P__
_____P____
Your move:quit
Knight moves W
Peasant moves E
Peasant too weak to move.
Peasant moves S
Peasant too weak to move.
Peasant moves S
Peasant too weak to move.
Peasant too weak to move.
Basically, the user tells the
User how to move (N,S,E,W). The knights move randomly (one of N,S,E,W) on each turn. The peasants flip a coin, if heads they stay put otherwise they move randomly (one ofN,S,E,W). The world is 10 by 10 and wraps around.
The
resolveconflicts method is described in the javadocs. It goes over every
Thing. If there is another
Thing in the same row,col position then, if the Thing is a Knight it kills (removes) any Thing else there. If it is the user then if it finds the sword there it picks it up (thus killing it) and it is it a peasant it kills it.
I recommend you implement this program in the following order:
- The Thing hierarchy, start at the top and work your way down. Start with the properties, then the toString() methods, then the move() methods.
- The Game class, its properties and constructor.
- Game.toString(), test it.
- Game.add()
- Game.remove()
- Game.thingsAt()
- Game.moveAll(): this should just call move() on every thing.
- Finally, Game.removeConflicts()