In my simulation, it just makes sense to implement the decorator pattern to represent the different potions that may be added to the game. Right now since it is mostly a movement and single action game, the only potion to add is a speedBoost Potion. I have given the Player super-class a method (speed()) that returns a value to the speed. (I am still in the developmental stage of figuring out how this speed is actually going to change how fast the player moves). When the speedBoost Potion is added to the character it will double the speed. This speed value will also be used to determine how fast a player is able to raise the flag to claim a new area. This raises another question to the readers: I want to have the town that the player will change ownership of to control the method to 'changeOwner()'. How do I get the player to call this function so that it will set the correct faction? As for the removing of the 'potion' I have another method call in this class (removeSpeedBoost()) and it will return a value for the speed by taking the current speed and then reducing it by half.
Decorator pattern looks good. Where is changeOwner? I don't see this method. If I understand you correctly, maybe you could pass the player to changeOwner? Your driver could handle having the correct player call changeOwner?
ReplyDeleteCome see one of us during office hours, I'm not sure I understand your question from the description here.
As to the bug in DecoratorPattern..you are trying to cast SpeedBoost as Bishop..SpeedBoost extends Player and Bishop extends Player, but SpeedBoost does not extend Bishop. Hence the error.
~GTF PAUL
As to the catchup assignment, the error I get is because 'piece-home.gif' is not loaded in your data folder. As to the typecasting, if you define some of the common methods in Player (like setCanvas, for example) you won't have to typecast every time you do a common method.
ReplyDelete~GTF PAUL