简体   繁体   English

棋盘游戏,代币运动C#

[英]Board Game, Token Movement C#

will someone help me in this moving of my token, which is found in the diceroll() method, if the user clicks the dice roll button, the token will round the board. 有人会在diceroll()方法中找到的令牌移动过程中帮助我吗,如果用户单击掷骰子按钮,则令牌将使整个过程顺利进行。 the problem is the token is going outside the board 问题是令牌正在董事会之外

i already set a the first value of x as 15 and y as 12 (if you want to see the whole game file: http://www.mediafire.com/?1rz1689di15o8sq ) 我已经将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)
        {

        }
    }
}

It looks like it could fall into several of the if conditions at the same time. 看起来它可能同时属于多个if条件。

say x=150, y=12 and dice=6 说x = 150,y = 12,骰子= 6

It would fall into this if statement: if (x >= 15 && y <= 102) and this one: if (x >= 113 && y <= 642) 它会落入if语句中:if(x> = 15 && y <= 102)和this:if(x> = 113 && y <= 642)

since the X and Y values don't get updated, only curx and cury, that might explain the weird token movement. 由于X和Y值不会更新,只有curx和cury,这可能解释了怪异的令牌运动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM