예제 #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++;
            }
        }
예제 #2
0
        /// <summary>
        /// Takes in a ship Id and adds it to a list of ships which must be
        /// removed from the world then sets the ships hp to zero
        /// </summary>
        public Ship AddShipToCleanup(int shipID)
        {
            shipsToCleanup.Add(shipID);
            Ship deadShip = allShips[shipID];

            deadShip.SetHP(0);
            return(deadShip);
        }
예제 #3
0
        /// <summary>
        /// Creates a ship at a random location in the world in a random direction
        /// </summary>
        public void Respawn(Ship ship)
        {
            // find random empty location in the world
            FindRandomLocation(ship);

            // make a new normalized direction vector pointing up
            Vector2D dir = new Vector2D(0, -1);

            dir.Normalize();

            // make a randomizing object
            Random r         = new Random();
            int    randAngle = r.Next(0, 360);

            //rotate by random angle
            dir.Rotate(randAngle);

            // sets a random direction for the ship
            ship.SetDirection(dir);

            // reset ship's velocity
            ship.SetVelocity(new Vector2D(0, 0));

            // if dead ship is king
            if (ship.IsKing())
            {
                // hit points go up beacuse ship is now king
                ship.SetHP(startingHitPoints + 3);
            }
            else
            {
                // reset the ship's health to original health
                ship.SetHP(startingHitPoints);
            }

            // reset ships death timer
            ship.ResetRespawnTimer();
        }
예제 #4
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);
        }