DateTime _lastTick = DateTime.Now; // when did we last tell the sprites that time had passed?

        #endregion Fields

        #region Constructors

        public SpaceControl()
        {
            DoubleBuffered = true;  // keeps redraws and screen refresh from happening at the same time

            InitializeComponent();  // standard Windows Forms control init function

            Ship ship = new Ship();  // create the player's ship
            ship.Position = new Vector2F(100, 100);

            aiship = new AIShip();
            aiship.Position = new Vector2F(800, 100);

            Planet planet = new Planet();  // create the big Planet
            planet.Position = new Vector2F(400, 300);

            float orbit = 200;  // how far from the planet's center are the targets?
            List<Planet> targets = new List<Planet>();
            for (int i = 0; i < NumTargets; ++i)
            {
                // Create a target.  We're using "Planet", but we could use Sprite or a custom Target class.
                Planet target = new Planet();
                target.ImageFileName = "Images/FlatTarget.gif";  // standard target art
                target.Space = this;  // add the target to the simulation

                // Divide the targets uniformly around the planet.
                double angle = i * 2 * Math.PI / NumTargets;
                Vector2F offset = new Vector2F(Math.Cos(angle), Math.Sin(angle));
                target.Position = planet.Position + offset * orbit;
            }

            // Add planet, AIShip and ship to simulation.
            planet.Space = this;
            ship.Space = this;
            aiship.Space = this;
        }
Example #2
0
        // Add up the score!
        protected void Score()
        {
            Dictionary <Planet, int> d_PlanetToNumMissiles = new Dictionary <Planet, int>();

            long score   = 0;
            long aiscore = 0;

            foreach (Sprite sprite in this._Sprites)
            {
                Missile missile = sprite as Missile;
                if (null != missile)
                {
                    if (missile.Parent is Missile)
                    {
                        // Assign scores accordingly to fires by which ship.
                        if (missile.firerID == 0)
                        {
                            score += 1;
                        }
                        else
                        {
                            aiscore += 1;
                        }
                    }
                    else if (missile.Parent is Planet && missile.Parent.ImageFileName == "Images/FlatTarget.gif")
                    {
                        if (missile.firerID == 0)
                        {
                            score += 50;
                        }
                        else
                        {
                            aiscore += 1;
                        }

                        Planet target = (Planet)missile.Parent;
                        if (d_PlanetToNumMissiles.ContainsKey(target))
                        {
                            d_PlanetToNumMissiles[target]++;
                        }
                        else
                        {
                            d_PlanetToNumMissiles[target] = 1;
                        }
                    }
                    else if (missile.Parent is Planet)
                    {
                        if (missile.firerID == 0)
                        {
                            score -= 100;
                        }
                        else
                        {
                            aiscore -= 100;
                        }
                    }
                }
            }


            if (d_PlanetToNumMissiles.Count >= NumTargets)
            {
                int min = int.MaxValue;
                foreach (int missiles in d_PlanetToNumMissiles.Values)
                {
                    if (missiles < min)
                    {
                        min = missiles;
                    }
                }

                score += min * 1000;
            }

            labelScore.Text = score.ToString();
            labelAI.Text    = aiscore.ToString();
        }