Пример #1
0
 public void AddShip(Ship s)
 {
     ships.Add(s);
 }
Пример #2
0
 public void RemoveShip(Ship s)
 {
     ships.Remove(s);
 }
Пример #3
0
        //Preforms Attacking Think Axis and Allies
        public bool Attack(List <Ship> attack, List <Ship> defense, Planet p, Planet surrender)
        {
            Random die      = new Random();
            Player defender = null;
            int    ahits    = 0;
            int    dhits    = 0;

            //Gets Defender
            foreach (Player player in board.players)
            {
                if (player.ownedPlanets.Contains(p))
                {
                    defender = player;
                }
            }

            if (!defender.Equals(null))
            {
                //Gets Number Of Hits
                foreach (Ship aship in attack)
                {
                    int roll = die.Next(1, 21);
                    if (roll <= aship.getAttack())
                    {
                        ahits++;
                    }
                }

                foreach (Ship dship in defense)
                {
                    int roll = die.Next(1, 21);
                    if (roll <= dship.getDefence())
                    {
                        dhits++;
                    }
                }

                //Removes Ships
                for (int i = 1; i <= ahits; i++)
                {
                    if (defense.Count > 0)
                    {
                        int  index = die.Next(0, defense.Count);
                        Ship temp  = defense[index];
                        defense.Remove(temp);
                        defender.ships.Remove(temp);
                        p.planetShips.Remove(temp);
                    }
                }
                for (int i = 1; i <= dhits; i++)
                {
                    if (attack.Count > 0)
                    {
                        int  index = die.Next(0, attack.Count);
                        Ship temp  = attack[index];
                        attack.Remove(temp);
                        this.ships.Remove(temp);
                    }
                }

                //Takeover Planet
                if (defense.Count <= 0 && attack.Count > 0)
                {
                    defender.ownedPlanets.Remove(p);
                    this.ownedPlanets.Add(p);
                    foreach (Ship ship in attack)
                    {
                        p.planetShips.Add(ship);
                    }
                    return(true);
                }
            }
            return(false);
        }