Exemple #1
0
        public void MoveButton(Button button, string NameButton)
        {
            switch (NameButton)
            {
            case "W_T":
            case "B_T":
                Trooper t = new Trooper();
                sourceButton = button;

                Point pointTrooper = GetChess(Matrix, button);

                t.CanMove(Matrix, pointTrooper);
                t.CanKill(Matrix, pointTrooper);
                break;

            case "B_R":
            case "W_R":
                Rook r = new Rook();
                sourceButton = button;

                Point pointRook = GetChess(Matrix, button);
                r.CanMove(Matrix, pointRook);
                // r.CanKill(Matrix, pointRook);
                break;

            case "W_B":
            case "B_B":
                Bishop b = new Bishop();

                sourceButton = button;
                Point pointBishop = GetChess(Matrix, button);
                b.CanMove(Matrix, pointBishop);
                // r.CanKill(Matrix, pointRook);
                break;

            case "W_K":
            case "B_K":
                King k = new King();

                sourceButton = button;
                Point pointKing = GetChess(Matrix, button);
                k.CanMove(Matrix, pointKing);
                // r.CanKill(Matrix, pointRook);
                break;

            case "W_Q":
            case "B_Q":
                Queen q = new Queen();

                sourceButton = button;
                Point pointQueen = GetChess(Matrix, button);
                q.CanMove(Matrix, pointQueen);

                break;

            case "W_N":
            case "B_N":
                Knight n = new Knight();

                sourceButton = button;
                Point pointKnight = GetChess(Matrix, button);
                n.CanMove(Matrix, pointKnight);
                break;

            case "A":
                desnitationButton = button;
                Move(Matrix, sourceButton, desnitationButton);
                break;

            case "K":
                //Gán đích chuẩn bị thay thế
                desnitationButton = button;
                //Lấy ảnh đưa vào panel
                if (button.Name.Substring(0, 1) == "W")
                {
                    CurrentPoint = pointP2;
                }
                else
                {
                    CurrentPoint = pointP1;
                }
                PictureBox picture = new PictureBox()
                {
                    Width                 = 50,
                    Height                = 50,
                    BackgroundImage       = button.BackgroundImage,
                    Location              = new Point(CurrentPoint.X, CurrentPoint.Y),
                    BackgroundImageLayout = ImageLayout.Stretch,
                    BorderStyle           = BorderStyle.Fixed3D,
                    Name = button.Name
                };
                if (picture.Name.Substring(0, 1) == "B")
                {
                    PnlPlayer1.Controls.Add(picture);
                    IncreaseLocation(ref pointP1);
                }
                else
                {
                    PnlPlayer2.Controls.Add(picture);
                    IncreaseLocation(ref pointP2);
                }
                Kill(Matrix, sourceButton, desnitationButton);
                break;
            }
        }
Exemple #2
0
        public void MoveButton(Button button, string NameButton)
        {
            switch (NameButton)
            {
            case "W_T":
            case "B_T":
                Trooper t = new Trooper();
                while (stackButton.Count > 0)
                {
                    int    X   = stackButton.X;
                    int    Y   = stackButton.Y;
                    Button btn = stackButton.Pop();

                    Matrix[X][Y].BackColor = btn.BackColor;
                    Matrix[X][Y].Name      = btn.Name;
                }
                sourceButton = button;

                Point pointTrooper = GetChess(Matrix, button);
                if (pointTrooper.X == 0 || pointTrooper.X == 7)
                {
                    break;
                }
                t.CanMove(Matrix, pointTrooper);
                t.CanKill(Matrix, pointTrooper);
                break;

            case "B_R":
            case "W_R":
                Rook r = new Rook();
                //while (stackButton.Count > 0)
                //{
                //    int X = stackButton.X;
                //    int Y = stackButton.Y;
                //    Button btn = stackButton.Pop();

                //    Matrix[X][Y].BackColor = btn.BackColor;
                //    Matrix[X][Y].Name = btn.Name;

                //}
                sourceButton = button;

                Point pointRook = GetChess(Matrix, button);
                r.CanMove(Matrix, pointRook);
                // r.CanKill(Matrix, pointRook);
                break;

            case "W_B":
            case "B_B":
                Bishop b = new Bishop();
                //while (stackButton.Count > 0)
                //{
                //    int X = stackButton.X;
                //    int Y = stackButton.Y;
                //    Button btn = stackButton.Pop();

                //    Matrix[X][Y].BackColor = btn.BackColor;
                //    Matrix[X][Y].Name = btn.Name;

                //}
                sourceButton = button;
                Point pointBishop = GetChess(Matrix, button);
                b.CanMove(Matrix, pointBishop);
                // r.CanKill(Matrix, pointRook);
                break;

            case "B_K":
            case "W_K":
                King k = new King();
                //while (stackButton.Count > 0)
                //{
                //    int X = stackButton.X;
                //    int Y = stackButton.Y;
                //    Button btn = stackButton.Pop();

                //    Matrix[X][Y].BackColor = btn.BackColor;
                //    Matrix[X][Y].Name = btn.Name;

                //}
                sourceButton = button;

                Point pointKing = GetChess(Matrix, button);
                k.CanMove(Matrix, pointKing);
                // r.CanKill(Matrix, pointRook);
                break;

            case "B_Q":
            case "W_Q":
                Queen q = new Queen();
                //while (stackButton.Count > 0)
                //{
                //    int X = stackButton.X;
                //    int Y = stackButton.Y;
                //    Button btn = stackButton.Pop();

                //    Matrix[X][Y].BackColor = btn.BackColor;
                //    Matrix[X][Y].Name = btn.Name;

                //}
                sourceButton = button;

                Point pointQueen = GetChess(Matrix, button);
                q.CanMove(Matrix, pointQueen);
                // r.CanKill(Matrix, pointRook);
                break;

            case "B_N":
            case "W_N":
                Knight n = new Knight();
                //while (stackButton.Count > 0)
                //{
                //    int X = stackButton.X;
                //    int Y = stackButton.Y;
                //    Button btn = stackButton.Pop();

                //    Matrix[X][Y].BackColor = btn.BackColor;
                //    Matrix[X][Y].Name = btn.Name;

                //}
                sourceButton = button;

                Point pointKnight = GetChess(Matrix, button);
                n.CanMove(Matrix, pointKnight);
                // r.CanKill(Matrix, pointRook);
                break;

            case "A":
                desnitationButton = button;
                Move(Matrix, sourceButton, desnitationButton);
                break;

            case "K":
                desnitationButton = button;
                Kill(Matrix, sourceButton, desnitationButton);
                break;
            }
        }
Exemple #3
0
        public void MoveButton(Button button, string NameButton)
        {
            switch (NameButton)
            {
            case "W_T":
            case "B_T":
                Trooper t = new Trooper();
                sourceButton = button;

                Point pointTrooper = GetChess(Matrix, button);

                t.CanMove(Matrix, pointTrooper);
                t.CanKill(Matrix, pointTrooper);
                break;

            case "B_R":
            case "W_R":
                Rook r = new Rook();
                sourceButton = button;

                Point pointRook = GetChess(Matrix, button);
                r.CanMove(Matrix, pointRook);
                //r.CanKill(Matrix, pointRook);
                break;

            case "W_B":
            case "B_B":
                Bishop b = new Bishop();

                sourceButton = button;
                Point pointBishop = GetChess(Matrix, button);
                b.CanMove(Matrix, pointBishop);
                //r.CanKill(Matrix, pointRook);
                break;

            case "W_K":
            case "B_K":
                King k  = new King();
                King go = new King();
                sourceButton = button;
                Point pointKing = GetChess(Matrix, button);
                k.CanMove(Matrix, pointKing);
                //r.CanKill(Matrix, pointRook);
                break;

            case "W_Q":
            case "B_Q":
                Queen q = new Queen();

                sourceButton = button;
                Point pointQueen = GetChess(Matrix, button);
                q.CanMove(Matrix, pointQueen);

                break;

            case "W_N":
            case "B_N":
                Knight n = new Knight();

                sourceButton = button;
                Point pointKnight = GetChess(Matrix, button);
                n.CanMove(Matrix, pointKnight);
                break;

            case "A":
                desnitationButton = button;

                Point    pointDes    = GetChess(Matrix, desnitationButton);
                Point    pointSrc    = GetChess(Matrix, sourceButton);
                InfoUndo infoUndoDes = new InfoUndo(button.BackgroundImage, button.Name, pointDes.X, pointDes.Y);
                InfoUndo infoUndoSrc = new InfoUndo(sourceButton.BackgroundImage, sourceButton.Name, pointSrc.X, pointSrc.Y);

                stackUndo.Push(infoUndoSrc);
                stackUndo.Push(infoUndoDes);

                int x = GetChess(Matrix, sourceButton).Y - GetChess(Matrix, desnitationButton).Y;
                Move(Matrix, sourceButton, desnitationButton);


                if (x == 2 && (desnitationButton.Name == "B_K" || desnitationButton.Name == "W_K"))
                {
                    Point point = new Point();

                    point = GetChess(Matrix, desnitationButton);

                    Move(Matrix, Matrix[point.X][point.Y - 2], Matrix[point.X][point.Y + 1]);
                }
                else if (x == -2 && (desnitationButton.Name == "B_K" || desnitationButton.Name == "W_K"))
                {
                    Point point = new Point();

                    point = GetChess(Matrix, desnitationButton);

                    Move(Matrix, Matrix[point.X][point.Y + 1], Matrix[point.X][point.Y - 1]);
                }
                break;

            case "K":
                //Gán đích chuẩn bị thay thế
                desnitationButton = button;

                Point pointDess = GetChess(Matrix, desnitationButton);
                Point pointSrcs = GetChess(Matrix, sourceButton);

                InfoUndo infoUndoDess = new InfoUndo(button.BackgroundImage, button.Name, pointDess.X, pointDess.Y);
                InfoUndo infoUndoSrcs = new InfoUndo(sourceButton.BackgroundImage, sourceButton.Name, pointSrcs.X, pointSrcs.Y);

                stackUndo.Push(infoUndoSrcs);
                stackUndo.Push(infoUndoDess);

                //Lấy ảnh đưa vào panel
                if (button.Name.Substring(0, 1) == "W")
                {
                    CurrentPoint = pointP2;
                }
                else
                {
                    CurrentPoint = pointP1;
                }

                PictureBox picture = new PictureBox()
                {
                    Width                 = 50,
                    Height                = 50,
                    BackgroundImage       = button.BackgroundImage,
                    Location              = new Point(CurrentPoint.X, CurrentPoint.Y),
                    BackgroundImageLayout = ImageLayout.Stretch,
                    BorderStyle           = BorderStyle.Fixed3D,
                    Name = button.Name
                };
                if (picture.Name.Substring(0, 1) == "B")
                {
                    PnlPlayer1.Controls.Add(picture);
                    indexp1 += 1;
                    IncreaseLocation(ref pointP1);
                    if (Matrix[pointDess.X][pointDess.Y].Name == "B_K")
                    {
                        indexp1 = -9;
                    }
                }
                else
                {
                    PnlPlayer2.Controls.Add(picture);
                    indexp2 += 1;
                    IncreaseLocation(ref pointP2);
                    if (Matrix[pointDess.X][pointDess.Y].Name == "W_K")
                    {
                        indexp2 = -10;
                        indexp1 = -9;
                    }
                }

                Kill(Matrix, sourceButton, desnitationButton);
                if (indexp1 == -9)
                {
                    MessageBox.Show("Player 1 You Win ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    ChessBoard.Enabled = false;
                }
                else if (indexp2 == -10 && indexp1 == -9)
                {
                    MessageBox.Show("Player 2 You Win ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    ChessBoard.Enabled = false;
                }
                break;

            default:

                break;
            }
        }