1

我正在制作一艘船从窗口窗体的一侧移动到另一侧的动画,但是当船触及屏幕边缘时我必须通知用户,因为他赢了。有人知道怎么做吗?这是我到目前为止所拥有的:

  private void playerTimer_Tick(object sender, EventArgs e)
    {
        for (int i = 0; i < 6; i++)
        {
            if (PlayersActive[i])
            {
                Players[i].Move(randomNumber.Next(3,10));
                 //HERE IS WHERE I SHOULD CHECK TO SEE IF A BIKE HAS WON
                 //If player location is at the edge of the screen

            }
        }
        this.Invalidate();
    }

移动船的代码:

    private void GameForm_Paint(object sender, PaintEventArgs e)
    {

        Graphics g = e.Graphics;

        // Set variables used to store logic to default values.
        int playersStillRacing = 0;


        for (int i = 0; i < 6; i++)
        {
            // Check to see if the current player is still racing.
            if (playersRacing[i])
            {
                // Incremement playersStillRacing.
                playersStillRacing++;

                // Set the playerPictureBox associated with this player to the new location
                //  the player is located at.
                playerPictureBoxes[i].Image = Players[i].Image;
                playerPictureBoxes[i].Left = Players[i].X;
                playerPictureBoxes[i].Top = Players[i].Y;


                g.DrawImage(playerPictureBoxes[i].Image, Players[i].X, Players[i].Y);

            }
         }

     }
4

1 回答 1

3

这会奏效吗?我根据您提供的最新信息进行了一些编辑

private void playerTimer_Tick(object sender, EventArgs e)
{
    for (int i = 0; i < 6; i++)
    {
        if (PlayersActive[i])
        {
            Players[i].Move(randomNumber.Next(3,10));

            // EDIT BELOW in the if statement!
            // if the edge of the picture touches the end of the screen.
            if (Players[i].X + Players[i].Image.Width >= this.Width)
                MessageBox.Show("Congrats! Player" + i.ToString() + "won!");

            //Players[i].X is the X cordinates(The length) from the left side of the winform.
            //Players[i].Image.Width is the width of the picture ofcourse :D.
            // if X cordinates + picture width is greater than or equal to screen width. YOU WON :D
        }
    }
    this.Invalidate();
}

还是你想要别的东西?

于 2013-09-25T07:49:52.090 回答