Пример #1
0
        public void MoveAllInvaders()
        {
            bool createNewInvaders = false;

            Invader maxWidthInvader = new Invader(new Point(boundaries.Left, 0));
            Invader minWidthInvader = new Invader(new Point(boundaries.Right), 0);

            foreach (Invader invader in invaders)
            {
                if (invader.Location.X <= minWidthInvader.Location.X)
                {
                    minWidthInvader = invader;
                }
                if (invader.Location.X >= maxWidthInvader.Location.X)
                {
                    maxWidthInvader = invader;
                }
            }

            foreach (Invader invader in invaders)
            {
                if (minWidthInvader.Location.X <= boundaries.Left)
                {
                    invader.Move(Parameters.Direction.Down, level);
                    invaderDirection = Parameters.Direction.Right;
                }
                else if (maxWidthInvader.Location.X + maxWidthInvader.Image.Width >= boundaries.Right)
                {
                    invader.Move(Parameters.Direction.Down, level);
                    invaderDirection = Parameters.Direction.Left;
                }

                if (invader.Location.Y + invader.Image.Height >= boundaries.Bottom)
                {
                    createNewInvaders = true;
                    break;
                }
                else
                {
                    invader.Move(invaderDirection, level);
                }
            }

            if (createNewInvaders)
            {
                ResetInvaders();
                GenerateInvaders();
            }

            if (mothership)
            {
                mother.Move(Parameters.Direction.Right);
                if (mother.Location.X >= boundaries.Right || mother.Location.X <= boundaries.Left)
                {
                    RemoveMothership();
                }
            }
        }
Пример #2
0
        public void CreateMothership()
        {
            if (mothership)
            {
                return;
            }

            mother     = new Invader(new Point(boundaries.Left, boundaries.Top));
            mothership = true;
            //System.Windows.Forms.MessageBox.Show(mother.Image.Width.ToString());
        }
Пример #3
0
        public void GenerateInvaders()
        {
            Invader newInvader     = new Invader(new Point(Parameters.invaderInitialLeft, Parameters.invaderInitialTop));
            int     invadersPerRow = Parameters.invadersPerRow + level / 5;

            if (invadersPerRow > 10)
            {
                invadersPerRow = 10;
            }

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < invadersPerRow; j++)
                {
                    switch (i)
                    {
                    case 0:
                        newInvader.SetImage(Parameters.InvaderTypes.bug);
                        break;

                    case 1:
                        newInvader.SetImage(Parameters.InvaderTypes.saucer);
                        break;

                    case 2:
                        newInvader.SetImage(Parameters.InvaderTypes.satellite);
                        break;

                    case 3:
                        newInvader.SetImage(Parameters.InvaderTypes.spaceship);
                        break;

                    case 4:
                        newInvader.SetImage(Parameters.InvaderTypes.star);
                        break;

                    default: break;
                    }

                    invaders.Add(newInvader);
                    newInvader = new Invader(new Point(newInvader.Location.X + Parameters.invaderHorizontalSpacing, newInvader.Location.Y));
                }

                newInvader.Location = new Point(Parameters.invaderInitialLeft, newInvader.Location.Y + Parameters.invaderVerticalSpacing);
            }
        }