Ashley Bye wrote:I'd be more than willing to get into a discussion about how to make the code better and more OO.
Ashley Bye wrote:I've not used JUnit before - if you can point me in the direction of a good tutorial I'd like to start using it.
Ashley Bye wrote:Going back to an earlier comment, why are interfaces better than abstract classes? I'll have to look up the book you mentioned.
Ashley Bye wrote:Before I go ahead and make any changes to the code, does this mirror what you're thinning or should I be thinking about it in some other way?
Ashley Bye wrote:What tests show the different ways an enemy can be used?
Test that the interaction returns the correct string.
Test the fight method (correct weapon kills enemy, incorrect weapon enemy remains alive, enemy remains alive until health is 0).
Looking at the rest of the code in the fight() method dealing with if it was a dragon, I should just test if the enemy killed was a dragon then deal with the outcome in one of the calling classes, probably game.
The Dragonslayer - a text-based, single player, role playing game (RPG).
The game starts with the Player occupying the first Space of the World/Map/Board (for brevity, let's go with "World" for now). The World is made up of a number of contiguous Spaces. While the game is in play, the Player can move from the Space he currently occupies to another adjacent Space. Sometimes, it may not be possible to move to an adjacent Space because there is something (what do we call this?) that blocks entry from that direction. A Space can be occupied by the Player and one (or two? more than two?) other "Character". The other Character can be friendly (a Companion) or unfriendly (a Foe). If a Companion occupies the Space, (what happens?). If a Foe occupies the Space, the Player can engage in a battle to the death or evade the Foe by moving out of the Space. Avoiding a battle with a Foe is not guaranteed, however, since once the Foe "sees" the Player move into the Space, it may or may not choose to chase the Player. How long a Foe chases the Player depends on the Foe's inherent tracking ability and speed. If Foe has "excellent" tracking ability and can match the Player's speed, the Foe can catch up to the player and immediately engage the Player in battle. ... and so on...
DragonSlayer - A single player, text based, RPG. The object if the game is to control a player on a quest through a magical world to slay the Dragon and rescue the Princess.
The game starts with the Player in his village, the first space of a World. The World is made of a grid of spaces (in a maze like structure) next to each other, and the Player must navigate from one to another on his quest. Not all spaces lead to the next in the sequence due to being blocked by a Barrier (such as a river, lake or impassable mountains, etc.).
The Player can only be in one Space at a time. On the way through the world, the Player meets other Characters who are either a Friend or an Enemy. Friends can give the Player gifts, food and medicine (but may just wish him well on his quest), which the Player stores in an inventory for ease of carrying. Once a Friend has given the Player a gift they will not be able to give them anything further. Friends can talk to the Player and tell him about what they are doing. A type of enemy can appear in different spaces and will always want to fight the Player before the Player can move into the space occupied by the Enemy. The Player can either fight the enemy to try and defeat it or run away to the previous space occupied. Once an enemy has been killed it no longer exists in that space.
Any weapon owned by the Player may be used to strike an Enemy but each enemy has a specific weapon that must be used to carry out the killing blow. Both the Player and the Enemy have a health level (the enemies is set but the players can increase by taking the medicine and eating food). Each weapon the Player uses has a set strength, which will remove that much health from the enemy. The enemy then attacks the player in return, reducing the players health by a percent of the health removed from the enemy (10% of the enemies strength).
If the Player chooses to run away, the enemy can randomly decide whether to give chase. If the enemy chases the Player, they can only chase him as far as the previously occupied space. It is entirely random whether the enemy catches the Player. Once caught, there is no option but to fight the enemy.
One of the spaces the Player enters will contain a treasure, a diamond. Some of the other spaces will contain a weapon. These are also kept in the Players inventory.
The final space of the world contains both the Dragon and the Princess. When the Player defeats the Dragon and rescues the Princess, the overall outcome varies depending on whether the Player has a diamond, which he can choose either to give to the Princess or keep for himself.
Goal: PLAYER is able to NAVIGATE from one SPACE in a WORLD to another.
Nouns: Player, Space, World.
Interactions: Move (Navigate), Direction.
Goal: Prevent PLAYER from moving into a SPACE due to the presence of a BARRIER.
Nouns: Player, Move (Navigate), Barrier.
Goal: PLAYER can find TREASURE and WEAPONS in SPACES.
Nouns: Player, Treasure, Weapon, Space;
Interactions: Collect (Store).
Goal: PLAYER can speak with and collect GIFTS from FRIENDS if they are present in a SPACE.
Nouns: Player, Gift, Friend.
Interactions: Collect (Store), Speak.
Goal: PLAYER can FIGHT or RUN AWAY from ENEMIES if they are present in a SPACE.
Nouns: Player, Enemy, Space.
Interactions: Fight, Run, Kill, Health (of Enemy and Player), Weapon.
Goal: PLAYER must KILL an ENEMY with a specific WEAPON.
Nouns: Player, Enemy, Weapon.
Interactions: Fight, Kill, Health.
Goal: ENEMY may choose to chase PLAYER into the previous SPACE if the PLAYER chooses to run away, where the ENEMY will then either FIGHT the PLAYER or give up the chase.
Nouns: Enemy, Player, Space.
Interactions: Fight, Kill, Health (of Enemy and Player), Weapon.
Goal: PLAYER and ENEMY HEALTH can decrease during a FIGHT.
Nouns: Player, Enemy, Health.
Goal: PLAYER can increase HEALTH by CONSUMING certain GIFTS given by FRIENDS.
Nouns: Player, Health, Gift, Friend.
Interactions: Health, Consume.
Goal: PLAYER can choose to GIVE the PRINCESS a DIAMOND if it was COLLECTED in one of the SPACES.
Nouns: Player, Princess, Space.
Interactions: Speak, Give.
Ashley Bye wrote:It feels like I'm not really writing unit tests but functional tests.
Junilu Lacar wrote: Idon't see many people following the method naming scheme that I adapted from author Neal Ford but I sure wish more did because I just find it reveals intent and design much better.
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton