as part of my weekly get together with Mattie Righter, he and I are working through the ever craft kata.
I have not made quite as good of progress as he, although I am slowly making it through it. I’m spending most of my time attempting to make the kata purely functional with no side effects of any kind.
FEATURE: CREATE A CHARACTER
As a character I want to have a name so that I can be distinguished from other characters
can get and set Name So, I have already decided to violate/change the requirements of Feature 1. I to not like the idea of a character possession the ability to change their name. I am deciding to prevent the ability to change your name.
FEATURE: ALIGNMENT
As a character I want to have an alignment so that I have something to guide my actions
can get and set alignment alignments are Good, Evil and Neutral I decided to create a ‘sealed trait’ for Alignment with the possible values of Good, Bad and Neutral.
I like the idea of not seeing string values within the code. This also makes it very clear when reading the code and prevents others from accidentally creating unwanted ‘Alignments’.
I have decided to default a newly created character to an alignment of ‘Neutral’. I have not provided a constructor for anything other than Neutral. If the character is to be anything other than Neutral, then setting after creation will be required.
FEATURE: ARMOR CLASS & HIT POINTS
As a combatant I want to have an armor class and hit points so that I can resist attacks from my enemies
has an Armor Class that defaults to 10 has 5 Hit Points by default Nothing crazy here… I just followed the directions.
FEATURE: CHARACTER CAN ATTACK
As a combatant I want to be able to attack other combatants so that I can survive to fight another day
roll a 20 sided die (don’t code the die) roll must meet or beat opponents armor class to hit I created an Attack ‘sealed trait’ that will confine the possible Attack types to ‘Hit’ and ‘Miss’.
When a character attacks an opponent, the roll (1-20) is used to determine if the opponents hit points and the roll constitute an attack of ‘hit’.
FEATURE: CHARACTER CAN BE DAMAGED
As an attacker I want to be able to damage my enemies so that they will die and I will live
If attack is successful, other character takes 1 point of damage when hit If a roll is a natural 20 then a critical hit is dealt and the damage is doubled when hit points are 0 or less, the character is dead I am debating if the ‘attack’ should be part of the character. It seems like it should be a separate class that takes two opponents and a role value… and returns the result. This way the opponent is not required to own the attack logic.
FEATURE: CHARACTER HAS ABILITIES SCORES
As a character I want to have several abilities so that I am not identical to other characters except in name
Abilities are Strength, Dexterity, Constitution, Wisdom, Intelligence, Charisma Abilities range from 1 to 20 and default to 10 Abilities have modifiers according to the following table:
| Score | Modifier | Score | Modifier | Score | Modifier | Score | Modifier |
|---|---|---|---|---|---|---|---|
| 1 | -5 | 6 | -2 | 11 | 0 | 16 | +3 |
| 2 | -4 | 7 | -2 | 12 | +1 | 17 | +3 |
| 3 | -4 | 8 | -1 | 13 | +1 | 18 | +4 |
| 4 | -3 | 9 | -1 | 14 | +2 | 19 | +4 |
| 5 | -3 | 10 | 0 | 15 | +2 | 20 | +5 |