Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 反转游戏颜色检测_C#_Winforms_Visual Studio 2010_Multidimensional Array - Fatal编程技术网

C# 反转游戏颜色检测

C# 反转游戏颜色检测,c#,winforms,visual-studio-2010,multidimensional-array,C#,Winforms,Visual Studio 2010,Multidimensional Array,为了提高我的编程技能,我正在用c重新制作经典的游戏Reversi 但是我在检查颜色时遇到了一个问题。到目前为止,我已经设法从左边和上面反转颜色,但它不能正常工作,它只在我击中板上最后一个方块时反转颜色 任何帮助都将不胜感激 这是一张图片,可以解释我的意思,下面的代码是什么意思 我拥有的代码: namespace praprevers { public partial class Form1 : Form { private Button[,] squares;

为了提高我的编程技能,我正在用c重新制作经典的游戏Reversi 但是我在检查颜色时遇到了一个问题。到目前为止,我已经设法从左边和上面反转颜色,但它不能正常工作,它只在我击中板上最后一个方块时反转颜色

任何帮助都将不胜感激

这是一张图片,可以解释我的意思,下面的代码是什么意思

我拥有的代码:

namespace praprevers
{
    public partial class Form1 : Form
    {
        private Button[,] squares;
        //private Button[,] r0;
        public Form1()
        {
            InitializeComponent();

            squares = new Button[4, 4];
            squares = new Button[,] {
                                    {btn_0_0, btn_0_1, btn_0_2, btn_0_3},
                                    {btn_1_0, btn_1_1, btn_1_2, btn_1_3},
                                    {btn_2_0, btn_2_1, btn_2_2, btn_2_3},
                                    {btn_3_0, btn_3_1, btn_3_2, btn_3_3}
                                    };

        }

        int _turn = 0;
        private void DrawColor(object sender, EventArgs e)
        {

           Button b = sender as Button;
            string[] btnData = b.Name.Split('_');
            int x = int.Parse(btnData[1]);
            int y = int.Parse(btnData[2]);

            //check for possible combinations 
            int top = x - 3;
            int botton = x +3;

            int left = y - 3;
            int right = y + 3;

           for (int l = 0; l < 4; ++l)
            {
                if (top >= 0 && squares[top, y].BackColor == Color.Black)
                {
                    squares[top + l, y].BackColor = Color.Black;

                }
                else if (left >= 0 && squares[x, left].BackColor == Color.Black)
                {
                    squares[x, left + l].BackColor = Color.Black;
                }
           }
            if (_turn == 0)
            {
                _turn = 1;
                b.BackColor = Color.Black;


            }
            else
            {
                _turn = 0;
                b.BackColor = Color.Red;


            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            foreach (Button sqrr in squares)
            {
                sqrr.Click += new System.EventHandler(this.DrawColor);
            }

        }

    }
}

乍一看,一个问题可能是,更改按钮颜色的逻辑发生在您为单击的按钮着色之前。好的,这是另一个问题,但我最初的问题是正确反转颜色它们是相关的问题,因为你改变按钮颜色的逻辑似乎依赖于刚刚按下的按钮的颜色是否正确。好的,我正在尝试解决这个问题