延迟或循环列表?

delaying or looping a list?

我正在为我的大学工作创建这个游戏,它基本上是 space 入侵者,我有一个 class 激光和一个 class 坏人 atm 它只是设置最多激活 5 个坏人从屏幕顶部掉落,我想要做的是循环列表,所以说 5 秒后列表重复,另外 5 个坏人出现在屏幕顶部,或者制作一个列表有 100 个坏人,但在 5 个之后延迟下一个 5 个等等

namespace SpaceInvaders

{

public partial class Form1 : Form
{

    private List<Invader> invaders = new List<Invader>();
    private List<Laser> lasers = new List<Laser>();

    int invaderNumber = 0;
    int score = 0;



    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode.Equals(Keys.W))
        {
            if (SpaceFighter.Top > 0)
            {
                SpaceFighter.Top = SpaceFighter.Top - 30;

            }
        }
        if (e.KeyCode.Equals(Keys.A))
        {
            if (SpaceFighter.Left > 0)
            {
                SpaceFighter.Left = SpaceFighter.Left - 10;

            }
        }
        if (e.KeyCode.Equals(Keys.D))
        {
            if (SpaceFighter.Right < this.Width)
            {
                SpaceFighter.Left = SpaceFighter.Left + 10;

            }
        }
        if (e.KeyCode.Equals(Keys.S))
        {
            if (SpaceFighter.Bottom < this.Height - 10)
            {
                SpaceFighter.Top = SpaceFighter.Top + 10;

            }
        }
        if (e.KeyCode.Equals(Keys.Space))
        {
            this.lasers.Add(new Laser(this, SpaceFighter));
        }
    }

    private void timer1_Tick(object sender, EventArgs e)
    {

            if (invaderNumber > 4)
            {
                timer1.Enabled = false;
                timer2.Enabled = true;
            }
            else
            {
                invaders.Add(new Invader(this));
                invaderNumber++;
            }



    }

    private void timer2_Tick(object sender, EventArgs e)
    {

        invaders.RemoveAll(ship => ship.isDisposed);
        foreach(Invader ship in invaders)
        {
            ship.MoveInvader(this);
            if (SpaceFighter.Bounds.IntersectsWith(ship.ship.Bounds))
            {
                timer2.Enabled = false;
                MessageBox.Show("You Lose!");
                return;

            }
        }

        lasers.RemoveAll(laser => laser.isDisposed);
        foreach (Laser laser in lasers)
        {
            laser.MoveLaser(this);
            foreach (Invader ship in invaders)
            {
                if (laser.laser.Bounds.IntersectsWith(ship.ship.Bounds))
                {
                    laser.isDisposed = true;
                    laser.laser.Dispose();
                    ship.isDisposed = true;
                    ship.ship.Dispose();
                    score = score + 2;
                    lblScore.Text = score.ToString();
                }
            }

        }

form
https://pastebin.com/P9enYPN5

laser class
https://pastebin.com/nvZ1VU8C

bad guys class
https://pastebin.com/eByLZ1Q8
// function for delaying     
System.Threading.Thread.Sleep(1000 * 5);

// loop with delay
while (true/* condition */)
{
    // some more code
    //..

    // delay
    System.Threading.Thread.Sleep(1000 * 5);
}

尝试这样做可能会奏效

// initialize 
int delayNoOfBadGuy = 0;

// before releasing every badguy increment with 1
delayNoOfBadGuy++;

if (delayNoOfBadGuy >= 5)
{
    // set to zero
    delayNoOfBadGuy = 0;

    // add delay
    System.Threading.Thread.Sleep(1000 * 5);
}

// rest of code