开发者

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. 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)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using Sy开发者_StackOverflow中文版stem.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.

say x=150, y=12 and dice=6

It would fall into this if statement: if (x >= 15 && y <= 102) and this one: 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜