Esempio n. 1
0
        public bool Combat(BaseShip attacker, BaseShip defender)
        {
            // To the death!
            bool attackerWins;

            while (true)
            {
                // Attacker hits first.
                defender.strength -= 1;
                if (defender.strength == 0)
                {
                    attackerWins = true;
                    break;
                }
                // Defender counter-attacks.
                attacker.strength -= 1;
                if (attacker.strength == 0)
                {
                    attackerWins = false;
                    break;
                }
            }
            if (attackerWins)
            {
                // The attacker won.  Return with false (as in, the attacking ship did not die).
                if (attacker.owner == (int)Global.PlayerOwners.User)
                {
                    Global.Instance.AssignUiSpecialMessage("Your ship attacked and it won!");
                    basicAI.RemoveAI(defender);
                }
                else
                {
                    Global.Instance.AssignUiSpecialMessage("Your ship was attacked and it lost!");
                }
                defender.RemoveShip();
                ships.Remove(defender);
                return(false);
            }
            else
            {
                // The defender won.  Return with true (as in, the attacking ship died).
                if (defender.owner == (int)Global.PlayerOwners.User)
                {
                    Global.Instance.AssignUiSpecialMessage("Your ship was attacked and it won!");
                    basicAI.RemoveAI(attacker);
                }
                else
                {
                    Global.Instance.AssignUiSpecialMessage("Your ship attacked and it lost!");
                }
                attacker.RemoveShip();
                ships.Remove(attacker);
                return(true);
            }
        }