Exemplo n.º 1
0
 public void TryToShoot(BaseTile tileToShoot)
 {
     if (CanShootTo(tileToShoot))
     {
         GameObject unit = boardCalculator.GetUnitOnTile(new Vector2Int(tileToShoot.gridX, tileToShoot.gridY));
         if (unit)
         {
             unit.GetComponent <BaseUnit>().Damage(damageValue);
         }
     }
     else
     {
         Debug.Log("Could not shoot that tile..");
     }
 }
Exemplo n.º 2
0
        public override IEnumerator AITurn()
        {
            var availableMoves = GetComponent <UnitMovement>().GetAvailableMoves();
            var posHitPairs    = new List <FavourablePosition>();

            foreach (var tile in availableMoves)
            {
                List <BaseTile> neighbours = boardCalculator.GetNeighbours(tile);
                foreach (var neighbour in neighbours)
                {
                    GameObject unit = boardCalculator.GetUnitOnTile(new Vector2Int(neighbour.gridX, neighbour.gridY));
                    if (unit)
                    {
                        if (unit.GetComponent <BaseUnitPlayer>())
                        {
                            posHitPairs.Add(new FavourablePosition(tile, unit));
                        }
                    }
                }
            }

            Debug.Log("Here are the available hits for " + gameObject.name);
            foreach (var pair in posHitPairs)
            {
                Debug.Log($"Attacker position: {pair.AttackerPosition}, Receiver position: {pair.Receiver}");
            }

            if (posHitPairs.Count > 0)
            {
                yield return(StartCoroutine(TurnCoroutine(posHitPairs)));
            }
            else
            {
                Debug.Log("No possible moves.");
            }
        }