Esempio n. 1
0
        //在棋盘上单击鼠标左键时引发的事件
        private void Image_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (isGameStart == false)
            {
                return;
            }
            Point point = e.GetPosition(canvas1);
            int   x     = (int)(point.X + 60) / 80;
            int   y     = (int)(point.Y + 60) / 80;

            if (!(x < 1 || x > max || y < 1 || y > max))
            {
                int i = x - 1;
                int j = y - 1;
                if (grid[i, j] == -1 && nextColor == tableSide)
                {
                    client.SetDot(tableIndex, i, j);
                    myFrist = false;
                }
                else if (grid[i, j] == tableSide && nextColor == tableSide)
                {
                    bool b1 = grid[i, j] == -1;
                    bool b2 = nextColor == tableSide;
                    nextX = i;
                    nextY = j;
                    //client.SetGetNext(i, j);
                    client.TalkNum(tableIndex, i, j);
                    numClick = 1;
                }
                else
                {
                    if (numClick == 1)
                    {
                        if (grid[i, j] != tableSide && nextColor == tableSide)
                        {
                            client.SetDoubleDot(tableIndex, tableSide, i, j, nextX, nextY);
                        }
                        else
                        {
                            numClick = 0;
                            nextX    = -1;
                            nextY    = -1;
                        }
                    }
                }


                //else if (grid[i,j] != tableSide)
                //{
                //    //这里要判断谁大谁小,先不写
                //    numClick = 2;
                //    client.SetDot(tableIndex, i, j);
                //}
            }
        }
Esempio n. 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button btn = e.Source as Button;
            int    i   = int.Parse(btn.Name.Substring(3, 1));
            int    j   = int.Parse(btn.Name.Substring(4, 1));

            if (grid_flag[i, j] == -1)
            {
                client.SetDot(tableIndex, i, j, grid[i, j]);
            }
        }
Esempio n. 3
0
        private void Image_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (isGameStart == false)
            {
                return;
            }
            Point point = e.GetPosition(canvas1);
            int   x     = (int)(point.X + 10) / 20;
            int   y     = (int)(point.Y + 10) / 20;

            if (!(x < 1 || x > max || y < 1 || y > max))
            {
                int i = x - 1;
                int j = y - 1;
                if (grid[i, j] == -1 && nextColor == tableSide)
                {
                    client.SetDot(tableIndex, i, j);
                }
            }
        }
Esempio n. 4
0
        //棋子移动与处理逻辑
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (btnStart.IsEnabled == false)
            {
                if (nextColor == tableSide)
                {
                    Button btn = e.Source as Button;
                    int    i   = int.Parse(btn.Name.Substring(3, 1));
                    int    j   = int.Parse(btn.Name.Substring(4, 1));

                    if (grid_flag[i, j] == -1)
                    {
                        grid_flag[i, j] = 1;
                        client.SetDot(tableIndex, i, j, grid[i, j], nextColor);
                    }
                    else
                    //            else if ((grid[i, j] > 0 && nextColor == 0) || (grid[i, j] < 0 && nextColor == 1))
                    //             {

                    if (grid_flag[i, j] == 0)
                    {
                        if (selectX != -1 && selectY != -1)
                        {
                            if ((selectX == i && (selectY - j == 1)) || (selectX == i && (selectY - j == -1)) || ((selectX - i == 1) && selectY == j) || ((selectX - i == -1) && selectY == j))
                            {
                                //某个grid下

                                grid[i, j]             = grid[selectX, selectY];
                                grid[selectX, selectY] = 0;

                                grid_flag[selectX, selectY] = 0; //移过去变为无子

                                grid_flag[i, j] = 1;             //移过来变为有子

                                client.SetDot_1(tableIndex, i, j, grid[i, j], selectX, selectY, nextColor, 0);

                                selectX = -1;
                                selectY = -1;
                            }
                            else
                            {
                                MessageBox.Show("无法移动!" + grid[selectX, selectY].ToString());
                            }
                        }
                    }
                    else if (grid_flag[i, j] == 1)
                    {
                        if (selectX != -1 && selectY != -1)
                        {
                            if ((selectX == i && (selectY - j == 1)) || (selectX == i && (selectY - j == -1)) || ((selectX - i == 1) && selectY == j) || ((selectX - i == -1) && selectY == j))
                            {
                                if (grid[i, j] * grid[selectX, selectY] > 0)
                                {
                                    MessageBox.Show("同类吃不掉");
                                }
                                else if (grid[i, j] * grid[selectX, selectY] == 0)
                                {
                                    grid[i, j]             = grid[selectX, selectY];
                                    grid[selectX, selectY] = 0;

                                    grid_flag[selectX, selectY] = 0; //移过去变为无子

                                    grid_flag[i, j] = 1;             //移过来变为有子

                                    client.SetDot_1(tableIndex, i, j, grid[i, j], selectX, selectY, nextColor, 0);

                                    selectX = -1;
                                    selectY = -1;
                                }
                                else
                                {
                                    if ((Math.Abs(grid[selectX, selectY]) == 1 && Math.Abs(grid[i, j]) == 8))
                                    {
                                        grid[i, j]                  = grid[selectX, selectY];
                                        grid[selectX, selectY]      = 0;
                                        grid_flag[selectX, selectY] = 0;
                                        int flag;
                                        flag = (nextColor == 0) ? -1 : 1;
                                        client.SetDot_1(tableIndex, i, j, grid[i, j], selectX, selectY, nextColor, flag);
                                        selectX = -1;
                                        selectY = -1;
                                    }
                                    else if (Math.Abs(grid[selectX, selectY]) > Math.Abs(grid[i, j]))
                                    {
                                        if ((Math.Abs(grid[selectX, selectY]) == 8 && Math.Abs(grid[i, j]) == 1))
                                        {
                                            MessageBox.Show("吃不掉");
                                        }
                                        else
                                        {
                                            grid[i, j]                  = grid[selectX, selectY];
                                            grid[selectX, selectY]      = 0;
                                            grid_flag[selectX, selectY] = 0;
                                            int flag;
                                            flag = (nextColor == 0) ? -1 : 1;
                                            client.SetDot_1(tableIndex, i, j, grid[i, j], selectX, selectY, nextColor, flag);
                                            selectX = -1;
                                            selectY = -1;
                                        }
                                    }
                                    else if (Math.Abs(grid[selectX, selectY]) == Math.Abs(grid[i, j]))
                                    {
                                        MessageBox.Show("你确定要与它同归于尽吗?");
                                        grid[i, j]                  = 0;
                                        grid[selectX, selectY]      = 0;
                                        grid_flag[i, j]             = 0;
                                        grid_flag[selectX, selectY] = 0;

                                        client.SetDot_1(tableIndex, i, j, grid[i, j], selectX, selectY, nextColor, 2);
                                        selectX = -1;
                                        selectY = -1;
                                    }
                                    else
                                    {
                                        MessageBox.Show("吃不掉");
                                    }
                                }
                            }
                            else if (selectX == i && selectY == j)
                            {
                                selectX = -1;
                                selectY = -1;
                            }
                            else
                            {
                                MessageBox.Show("不能这样走棋!" + grid[selectX, selectY].ToString());
                            }
                        }
                        else
                        {
                            if ((grid[i, j] > 0 && nextColor == 0) || (grid[i, j] < 0 && nextColor == 1))
                            {
                                selectX = i;
                                selectY = j;
                            }
                            else
                            {
                                MessageBox.Show("不是你的棋!");
                            }
                        }
                    }
                    //   }
                }
                else
                {
                    MessageBox.Show("不是你的回合!");
                }
            }
            else
            {
                MessageBox.Show("游戏未开始!");
            }
        }