计时器重启后无法移动

时间:2018-08-11 19:37:01

标签: timer move

我正在开发乒乓球游戏,我有两个球员,我写了一些代码让他们移动

        Y = oyuncu1.Location.Y;
        Y2 = oyuncu2.Location.Y;
        Y3 = O1Alt.Location.Y;
        Y4 = O2Alt.Location.Y;
        Y5 = O1Üst.Location.Y;
        Y6 = O2Üst.Location.Y;

        if(e.KeyCode == Keys.W)
        {
            Y = Y - 6;
            Y3 = Y3 - 6;
            Y5 = Y5 - 6;
        }
        if (e.KeyCode == Keys.S)
        {
            Y = Y + 6;
            Y3 = Y3 + 6;
            Y5 = Y5 + 6;
        }
        if (e.KeyCode == Keys.Up)
        {
            Y2 = Y2 - 6;
            Y4 = Y4 - 6;
            Y6 = Y6 - 6;
        }
        if (e.KeyCode == Keys.Down)
        {
            Y2 = Y2 + 6;
            Y4 = Y4 + 6;
            Y6 = Y6 + 6;
        }
        oyuncu1.Location = new Point(38, Y);
        oyuncu2.Location = new Point(1080, Y2);
        O1Üst.Location = new Point(38, Y5);
        O2Üst.Location = new Point(1080, Y6);
        O1Alt.Location = new Point(38, Y3);
        O2Alt.Location = new Point(1080, Y4);

通常,玩家1随W移动,玩家2随上下箭头移动。

我有一个函数Timer1_Tick,它使球移动。如果球碰到墙壁,计时器将停止

  if(top.Left <= oyuncu1Sınır.Right)
        {
            Point2++;
            hızX = 0;
            hızY = 0;
            Player2Point.Text = Point2.ToString();
            timer1.Stop();

            ResumeBtn.Visible = true;

        }
        if(top.Right >= oyuncu2Sınır.Left)
        {

            Point1++;
            hızX = 0;
            hızY = 0;
            Player1Point.Text = Point1.ToString();
            timer1.Stop();
            ResumeBtn.Visible = true;

        }

当我单击ResumeBtn时,计时器再次启动

但是当timer1重新启动时,我无法移动播放器1和2。 为什么?有人可以帮忙吗?

0 个答案:

没有答案