棋盘游戏,令牌运动C#

时间:2011-07-27 11:35:08

标签: c#

有人会帮助我移动我的令牌,这可以在diceroll()方法中找到, 如果用户点击骰子滚动按钮,则令牌将围绕棋盘。问题是令牌是在董事会之外

我已经将x的第一个值设置为15,将y设置为12 (如果你想看到整个游戏文件:http://www.mediafire.com/?1rz1689di15o8sq

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GAME
{
    public partial class GameInterface : Form
    {
        int curx, cury, tempx, tempy;
        private int x, y;
        public int Seconds;
        public int minutes = 5;
        Int32 dice;
        public GameInterface()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            token.Location = new Point(15, 12);
            x = 15;
            y = 12;
            button1.Enabled = false;
        }

        private void Quit_Click(object sender, EventArgs e)
        {
            quitting quit = new quitting();
            quit.ShowDialog();

        }

        private void Dice_Click(object sender, EventArgs e)
        {
            diceroll();
            timer1.Enabled = true;
        }


        public void coorx(int x)
        {
              curx = x;
        }

        public void coory(int y) 
        {
              cury = y;
        }

        public int getx() 
        {
            return curx;
        }

        public int gety() 
        {
            return cury;
        }

        public void diceroll()
        {

            System.Random diceroll = new Random();
            dice = diceroll.Next(6) + 1;
            DiceBox.Text = Convert.ToString(dice);


            if (x >= 15 && y <= 102)
            {
                x = getx();
                tempx = x + (105 * dice);
                token.Location = new Point(tempx, y);
                coorx(tempx);
            }

            if (x >= 608 && y <= 12)
            {
                y = gety();
                int tempy = y + (95 * dice);
                token.Location = new Point(x, tempy);
                coory(tempy);
            }

            if (x >= 707 && y <= 552)
            {

                x = getx();
                tempx = x - (105 * dice);
                token.Location = new Point(tempx, y);
                coorx(tempx);

            }

            if (x >= 113 && y <= 642)
            {
                y = gety();
                int tempy = y - (95 * dice);
                token.Location = new Point(x, tempy);
                coory(tempy);

            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if ((minutes == 0) && (Seconds == 0))
            {
                timer1.Enabled = false;
                MessageBox.Show("Game Over!");

                label3.Text = "05";
                label5.Text = "00";
            }
            else
            {
                if (Seconds < 1)
                {
                    Seconds = 60;
                    timer1.Interval = 1000;
                    if (minutes != 0)
                        minutes -= 1;
                }
                else
                {
                    Seconds -= 1;
                    label3.Text = minutes.ToString();
                    label5.Text = Seconds.ToString();
                }
            }
        }

        private void GameInterface_Load(object sender, EventArgs e)
        {

        }
    }
}

1 个答案:

答案 0 :(得分:1)

看起来它可能同时属于几种if条件。

假设x = 150,y = 12且dice = 6

这将属于这个if语句: if(x> = 15&amp;&amp; y&lt; = 102)并且这个:if(x> = 113&amp; y&lt; = 642)

因为X和Y值没有得到更新,只有curx和cury,这可能解释了奇怪的令牌移动。