Esempio n. 1
0
        /// <summary>
        /// When a ship is hit by a projectile then remove the a health point remove
        /// the projectile form the world
        /// </summary>
        private void HitAProjectile(Ship ship, Projectile projectile)
        {
            if (kingIsOn)
            {
                // find the owner of the projectile
                int shipID = projectile.GetOwner();
                if (allShips.TryGetValue(shipID, out Ship projectileShip))
                {
                    // if the projectile is from the king or the ship is the king then...
                    if (ship.IsKing() || projectileShip.IsKing())
                    {
                        // subtract a health point from the ship
                        ship.SetHP(ship.GetHP() - 1);

                        if (!ship.IsAlive())
                        {
                            // increase the ship's score who shot the projectile by 1
                            projectileShip.SetScore(projectileShip.GetScore() + 1);
                        }

                        // register that the projectile hit a non-team member
                        ship.ShotsHit++;
                    }

                    if (ship.IsKing() && !ship.IsAlive())
                    {
                        // make sure that the ship that died is no longer king
                        ship.SetKing(false);
                        ship.SetName(ship.GetName().Substring(5));

                        // select a new king
                        Ship newKingShip = RandomShip();
                        newKingShip.SetKing(true);
                        newKingShip.SetName("King " + newKingShip.GetName());
                    }
                }
                // set the projectile to dead
                projectile.Alive(false);
            }
            else
            {
                // subtract a health point
                ship.SetHP(ship.GetHP() - 1);

                if (!ship.IsAlive())
                {
                    // find the owner of the projectile
                    int shipID = projectile.GetOwner();
                    allShips.TryGetValue(shipID, out Ship projectileShip);

                    // increase the ship's score who shot the projectile by 1
                    projectileShip.SetScore(projectileShip.GetScore() + 1);
                }

                // set the projectile to dead
                projectile.Alive(false);
                // register that the projectile hit a ship
                ship.ShotsHit++;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The passed in ship has hit a star so the health points of the
        /// ship must be set to zero
        /// </summary>
        private void HitAStar(Ship ship)
        {
            // if king game mode is turned on
            if (kingIsOn)
            {
                if (ship.IsKing())
                {
                    // make sure that the ship that died is no longer king
                    ship.SetKing(false);
                    ship.SetName(ship.GetName().Substring(5));

                    // select a new king
                    Ship newKingShip = RandomShip();
                    newKingShip.SetKing(true);
                    newKingShip.SetName("King " + newKingShip.GetName());
                }
            }

            // kill the ship
            ship.SetHP(0);
        }