To keep combat simple all attacks are successful. The only thing I customize is an actor’s health and damage. My actor class is really simple at the moment and has the bare minimum to implement the original requirements.
9 public interface IActor
10 {
11 /// <summary>
12 /// The amount of life force
13 /// </summary>
14 int Health { get; set; }
15 /// <summary>
16 /// The amount of life force an attack does
17 /// </summary>
18 int Damage { get; set; }
19 /// <summary>
20 /// The rate at which the actor does stuff
21 /// </summary>
22 int Speed { get; set; }
23 /// <summary>
24 /// Is true while health is greater than zero
25 /// </summary>
26 bool IsAlive { get; }
27 /// <summary>
28 /// The intelligence controlling this actor (AI or Human)
29 /// </summary>
30 IIntellect Intellect { get; set; }
31 }
So far we’ve used the IsAlive, Speed and Intellect properties to implement death, actor turns and actions performed during a turn. To simulate combat I implemented the following test.
14 [Test]
15 public void TestAttackSubtractsAttackerDamageFromDefenderHealth()
16 {
17 var attacker = new Actor() {Damage = 1, Health = 10};
18 var defender = new Actor() {Damage = 1, Health = 10};
19
20 var command = new AttackCommand(attacker, defender);
21
22 Assert.IsTrue(command.Execute());
23 Assert.AreEqual(9, defender.Health);
24 Assert.AreEqual(10, attacker.Health);
25 }
In the above test I create two actors, one attacker and one defender. I then execute an AttackCommand and verify that the attacker damage is subtracted from the defender’s health.
The next step is to put it all together.