/// <summary> /// Attempts to attack a tile from the last clicked tile. /// </summary> /// <param name="tile">Tile to attack.</param> public void requestAttack(Tile tile) { // If two tiles have been clicked on in total, and they belong to two different colleges if (lastClickedTile != null && lastClickedTile.getCollege() != tile.getCollege()) { // If the two tiles that have been clicked on are adjacent to each other if (map.isAdjacent(lastClickedTile, tile)) { // Create an array to store the new gang strenghts of each tile int[] newStrengths = new int[2]; // Calculate the new strengths by evaluating the attack in the combat engine newStrengths = combatEngine.Attack(lastClickedTile.getGangStrength(), tile.getGangStrength()); // Set the new strengths lastClickedTile.setGangStrength(newStrengths[0]); tile.setGangStrength(newStrengths[1]); // Get the tiles adjacent to the previously selected tile Tile[] adjacents = map.getAdjacent(lastClickedTile); // Stop highlighting targets from the previously clicked on tile for (int i = 0; i < 4; i++) { if (adjacents[i] != null) { adjacents[i].resetColor(collegeColours); } } // Reset the tile that was last clicked on lastClickedTile = null; } } }
public void TestAttack() { CombatEngine combatEngineTest = new CombatEngine(); var random = NSubstitute.Substitute.For <System.Random>(); //uses constant random factor of 0.5 for testing random.NextDouble().Returns(0.5); combatEngineTest.setRandom(random); //Assign a attack with equal gangMember Strengths and both results should be 2 int[] results = combatEngineTest.Attack(5, 5); Assert.AreEqual(results[0], 2); Assert.AreEqual(results[1], 2); //Assign a attack where results should be 0 results = combatEngineTest.Attack(1, 1); Assert.AreEqual(results[0], 0); Assert.AreEqual(results[1], 0); }