// Use this for initialization void Start() { //Generate first row of defender foreach (UnitRank rank in Enum.GetValues(typeof(UnitRank))) { if (!rank.Equals(UnitRank.Unknown)) { GameObject cell = Instantiate(UnitImage); cell.transform.SetParent(Parent); Image i = cell.GetComponent <Image>(); i.sprite = UnitImageManager.GetRankImage(rank); } } //Generate the attacker rows foreach (UnitRank attacker in Enum.GetValues(typeof(UnitRank))) { if (!attacker.Equals(UnitRank.Unknown)) { //Generate attacker cell GameObject cell = Instantiate(UnitImage); cell.transform.SetParent(Parent); Image i = cell.GetComponent <Image>(); i.sprite = UnitImageManager.GetRankImage(attacker); //Iterate over possibles foreach (UnitRank rank in Enum.GetValues(typeof(UnitRank))) { if (!rank.Equals(UnitRank.Unknown)) { GameObject rCell = Instantiate(UnitImage); rCell.transform.SetParent(Parent); Image ri = rCell.GetComponent <Image>(); BattleResult result = UnitUtilities.ResolveBattle(attacker, rank); switch (result) { case BattleResult.Success: { ri.sprite = check; break; } case BattleResult.Fail: { ri.sprite = redx; break; } case BattleResult.Split: { ri.sprite = split; break; } } } } } } }
public void HandleBattle(UnitPiece attacker, BoardPosition attackerPosition, UnitPiece defender, BoardPosition defenderPosition) { BattleResult result = UnitUtilities.ResolveBattle(attacker.Rank, defender.Rank); // Based on result, update players switch (result) { case BattleResult.Success: { // Remove from defender owner defender.Owner.Pieces.Remove(defender); break; } case BattleResult.Fail: { // Remove from attacker owner attacker.Owner.Pieces.Remove(attacker); break; } case BattleResult.Split: { //Remove both attacker.Owner.Pieces.Remove(attacker); defender.Owner.Pieces.Remove(defender); break; } default: { break; } } EventManager.Raise(new UnitBattleResultEvent(attacker, defender, attackerPosition, defenderPosition, result)); turnComplete = true; }