public void TestUndoCycle() // Tests a particularly insidious case of UndoMove wherein one Undo forces another in a cycle. { const int NumArmies = 5; var manager = new ArmyManager(); var player = new Player(manager, new Color(0, 0, 0)); var armies = new List <Army>(); for (int i = 0; i < NumArmies; i++) { var army = new Army(100); armies.Add(army); player.AddArmy(army, new Pos(i, i)); } for (int i = NumArmies - 1; i >= 0; i--) { manager.MoveArmy(armies[i], new Pos(i + 1, i + 1)); } manager.MoveArmy(armies[NumArmies - 1], new Pos(0, 0)); manager.UndoMove(armies[NumArmies - 1]); for (int i = 0; i < NumArmies; i++) { Assert.AreEqual(new Pos(i, i), manager.ArmyPosition(armies[i])); } }
public void TestInitialAdd() { var manager = new ArmyManager(); var player = new Player(manager, new Color(0, 0, 0)); player.AddArmy(new Army(100), new Pos(1, 1)); Assert.AreEqual(1, player.ArmyList.Count); Assert.AreEqual(new Pos(1, 1), manager.ArmyPosition(player.ArmyList[0])); Assert.AreEqual(player.ArmyList[0], manager.ArmyAt(new Pos(1, 1))); }
public void TestUndoParam(Pos source, Pos dest) { var manager = new ArmyManager(); var player = new Player(manager, new Color(0, 0, 0)); var army = new Army(100); player.AddArmy(army, source); manager.MoveArmy(army, dest); manager.UndoMove(army); Assert.AreSame(army, manager.ArmyAt(source)); Assert.AreEqual(source, manager.ArmyPosition(army)); }
public void TestMovementParam(Pos source, Pos dest) { var manager = new ArmyManager(); var player = new Player(manager, new Color(0, 0, 0)); var army = new Army(100); player.AddArmy(army, source); manager.MoveArmy(army, dest); Assert.IsTrue((manager.ArmyAt(source) != null) == source.Equals(dest)); // source != dest implies that army will no longer be at source. Assert.AreSame(army, manager.ArmyAt(dest)); Assert.AreEqual(dest, manager.ArmyPosition(army)); }
private void AttackPlayer(Player moving, Player player) { foreach (var attacking in moving.ArmyList) { foreach (var defending in player.ArmyList) { if (armies.ArmyPosition(attacking).IsInRange(armies.ArmyPosition(defending), attacking.Range)) { defending.TakeDamage(generator.Next(1, DAMAGE)); } } } for (int i = 0; i < player.ArmyList.Count; i++) { var army = player.ArmyList[i]; if (army.Health <= 0) { player.ArmyList.RemoveAt(i); i--; } } }
public Pos ArmyPosition(int armyId) { return(manager.ArmyPosition(GetArmy(armyId))); }