Exemplo n.º 1
0
        protected static void Battle(Combatant attacker, Combatant defender)
        {
            bool attackerDead = false;
            bool defenderDead = false;

            int attackerStrength = attacker.CalculateStrength(defender);
            int defenderStrength = defender.CalculateStrength(attacker);

            CommunicationController.SpawnExplosion(defender.tile, attacker.tile);
            CommunicationController.SpawnExplosion(attacker.tile, defender.tile);

            while (!attackerDead && !defenderDead)
            {
                if (Random.Range(0f, 1f) < attackerStrength * 1f / (attackerStrength + defenderStrength))
                {
                    CommunicationController.SpawnExplosion(defender.tile, attacker.tile);
                    defenderDead = defender.TakeDamage();
                }
                else
                {
                    CommunicationController.SpawnExplosion(attacker.tile, defender.tile);
                    attackerDead = attacker.TakeDamage();
                }
            }

            if (attackerDead)
            {
                attacker.OnDefeat(defender);
            }

            if (defenderDead)
            {
                defender.OnDefeat(attacker);
                attacker.OnVictory(defender);
            }

            CommunicationController.UpdateState(0.3f);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Moves the unit onto the tile.
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        public bool Move(Tile tile)
        {
            if (!tile.CanEnter(this))
            {
                return(false);
            }

            this.tile.RemoveUnit(this);
            if (transportedIn != null)
            {
                transportedIn.RemoveCargo(this);
            }
            if (sleeping)
            {
                sleeping = false;
            }

            SetTile(tile);
            tile.PlaceUnit(this);

            moves -= tile.MovementCost(this);

            CommunicationController.UpdateState(0.3f);

            if (fuel != -1)
            {
                fuel--;
                if (fuel == 0)
                {
                    CommunicationController.SpawnExplosion(tile, tile);
                    Destroy();
                    CommunicationController.UpdateState(0.3f);
                }
            }

            return(true);
        }