The Thing class hierarchy. |
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()
This homework is due on Monday, March 12 @noon. Camelot, it is a silly place.
11 comments:
Why a sword? Well, initially I was going to make it so that the user must pick the sword and only then can he kill the knight, but I decided against it as it might prove too much coding for some.
But, if you feel up to it, go ahead and implement support for the user with a sword to kill the knight.
The Animated class has an enum called Direction, with values N, S, E, W. The Direction shows up as a class in the javadocs. It is not.
If you click thru to it http://jmvidal.cse.sc.edu/csce145/camelot-doc/Animated.Direction.html
You can see that it is an enum.
I describe the various resolveConflicts scenarios above. In all other scenarios, nothing happens.
So Animated.Direction is not a separate class, Direction is just the enum within Animated?
Yes, Direction is just an enum within Animated.
Ok, thanks. Also, do our methods need to be arranged exactly as they are in the Javadocs, like what class they are in, what they're called, how they work? Or can we use ways that are a little easier for us?
As the homework says "The specific methods that each class will implement are explained in detail in the Javadoc documents", in other words, you have to implement the methods as they are described in the Javadocs, that is the homework. Of course, you can always implement other methods if you want (HINT: you don't need to).
Cool, and last question: can main be changed at all or do we need to leave it exactly as we received it?
Yes, you can change main() if you want, just make sure that when we run it, it runs as described.
Ok that helps a lot, i'm just a little bit confused about Animated.Direction's purpose. But i'm working on it.
Post a Comment