Beispiel #1
0
        /// <summary>
        /// Protect the King prevent the King's capture (called "checkmate")
        /// The piece and the King piece are the same side
        /// </summary>
        /// <param name="i">row number the piece move to</param>
        /// <param name="j">columns number the piece move to</param>
        /// <returns></returns>
        public bool ProtectTheKing(int i, int j)
        {
            bool turn = true;
            int row = Row;
            int col = Col;
            var tmp = new Piece();

            if (!Board.Position[i, j].IsEmpty)
            {
                if (Board.Position[i, j].Name.Equals("KING")) tmp = Game.Players[Board.Position[i, j].Side].KingPiece;
                if (Board.Position[i, j].Name.Equals("ADVISOR"))
                    tmp = Game.Players[Board.Position[i, j].Side].AdvisorPieces[Board.Position[i, j].Index];
                if (Board.Position[i, j].Name.Equals("ELEPHANT"))
                    tmp = Game.Players[Board.Position[i, j].Side].ElephantPieces[Board.Position[i, j].Index];
                if (Board.Position[i, j].Name.Equals("HORSE"))
                    tmp = Game.Players[Board.Position[i, j].Side].HorsePieces[Board.Position[i, j].Index];
                if (Board.Position[i, j].Name.Equals("CHARIOT"))
                    tmp = Game.Players[Board.Position[i, j].Side].ChariotPieces[Board.Position[i, j].Index];
                if (Board.Position[i, j].Name.Equals("CANNON"))
                    tmp = Game.Players[Board.Position[i, j].Side].CannonPieces[Board.Position[i, j].Index];
                if (Board.Position[i, j].Name.Equals("SOLDIER"))
                    tmp = Game.Players[Board.Position[i, j].Side].SoldierPieces[Board.Position[i, j].Index];
            }

            Game.ResetChessPoint(Row, Col);
            Board.Position[i, j].IsEmpty = false;
            Board.Position[i, j].Side = Side;
            Board.Position[i, j].Name = Name;
            Board.Position[i, j].Index = Index;
            Row = i;
            Col = j;
            if (tmp.Side != 2)
            {
                tmp.State = 0;
                tmp._pbPiece.Visible = false;
            }

            // Test
            if (Game.TestCaptureKing(Game.Players[Side].KingPiece)) turn = false;

            Row = row;
            Col = col;
            Game.ResetChessPoint(i, j);
            Board.Position[row, col].IsEmpty = false;
            Board.Position[row, col].Side = Side;
            Board.Position[row, col].Name = Name;
            Board.Position[row, col].Index = Index;
            if (tmp.Side != -1)
            {
                tmp.State = 1;
                tmp.PbPiece.Visible = true;
                Board.Position[i, j].IsEmpty = false;
                Board.Position[i, j].Name = tmp.Name;
                Board.Position[i, j].Side = tmp.Side;
                Board.Position[i, j].Index = tmp.Index;
            }
            return turn;
        }
Beispiel #2
0
 /// <summary>
 /// Set a piece to new position
 /// </summary>
 /// <param name="p"></param>
 /// <param name="i"></param>
 /// <param name="j"></param>
 public static void SetPiece(Piece p, int i, int j)
 {
     Board.Position[i, j].IsEmpty = false;
     Board.Position[i, j].Side = MarkedPiece.Side;
     Board.Position[i, j].Name = MarkedPiece.Name;
     Board.Position[i, j].Index = MarkedPiece.Index;
     MarkedPiece.Row = i;
     MarkedPiece.Col = j;
     MarkedPiece.PbPiece.Width = MarkedPiece.PbPiece.Height = 39;
     MarkedPiece.PbPiece.Top = i*48 + 38;
     MarkedPiece.PbPiece.Left = j*48 + 13;
 }
Beispiel #3
0
        public static void Undo()
        {
            if (OldPosition.PbPiece.Image != null)
            {
                OldPosition.PbPiece.Image = null;
            }
            var tmp1 = new Piece();
            var tmp2 = new Piece();

            if (Marked) return;

            if (TurnCount > 0)
            {
                if (GameLog[TurnCount - 1].PieceFrom.Name.Equals("KING"))
                    tmp1 = Players[GameLog[TurnCount - 1].PieceFrom.Side].KingPiece;
                if (GameLog[TurnCount - 1].PieceFrom.Name.Equals("ADVISOR"))
                    tmp1 =
                        Players[GameLog[TurnCount - 1].PieceFrom.Side].AdvisorPieces[
                            GameLog[TurnCount - 1].PieceFrom.Index];
                if (GameLog[TurnCount - 1].PieceFrom.Name.Equals("ELEPHANT"))
                    tmp1 =
                        Players[GameLog[TurnCount - 1].PieceFrom.Side].ElephantPieces[
                            GameLog[TurnCount - 1].PieceFrom.Index];
                if (GameLog[TurnCount - 1].PieceFrom.Name.Equals("HORSE"))
                    tmp1 =
                        Players[GameLog[TurnCount - 1].PieceFrom.Side].HorsePieces[
                            GameLog[TurnCount - 1].PieceFrom.Index];
                if (GameLog[TurnCount - 1].PieceFrom.Name.Equals("CHARIOT"))
                    tmp1 =
                        Players[GameLog[TurnCount - 1].PieceFrom.Side].ChariotPieces[
                            GameLog[TurnCount - 1].PieceFrom.Index];
                if (GameLog[TurnCount - 1].PieceFrom.Name.Equals("CANNON"))
                    tmp1 =
                        Players[GameLog[TurnCount - 1].PieceFrom.Side].CannonPieces[
                            GameLog[TurnCount - 1].PieceFrom.Index];
                if (GameLog[TurnCount - 1].PieceFrom.Name.Equals("SOLDIER"))
                    tmp1 =
                        Players[GameLog[TurnCount - 1].PieceFrom.Side].SoldierPieces[
                            GameLog[TurnCount - 1].PieceFrom.Index];

                int capturedmove;
                capturedmove = GameLog[TurnCount - 1].PieceDest == null ? 0 : 1;

                switch (capturedmove)
                {
                    case 0: // last move doesn't eat any pieces
                        Board.Position[GameLog[TurnCount - 1].PieceFrom.Row, GameLog[TurnCount - 1].PieceFrom.Col].
                            IsEmpty = true;
                        Board.Position[
                            GameLog[TurnCount - 1].PieceFrom.Row,
                            GameLog[TurnCount - 1].PieceFrom.Col].Side = -1;
                        Board.Position[
                            GameLog[TurnCount - 1].PieceFrom.Row,
                            GameLog[TurnCount - 1].PieceFrom.Col].Name = "";
                        Board.Position[
                            GameLog[TurnCount - 1].PieceFrom.Row,
                            GameLog[TurnCount - 1].PieceFrom.Col].Index = -1;

                        // Reset to old position
                        tmp1.Row = GameLog[TurnCount - 1].RowFrom;
                        tmp1.Col = GameLog[TurnCount - 1].ColFrom;
                        tmp1.PbPiece.Width = tmp1.PbPiece.Height = 39;
                        tmp1.PbPiece.Top = tmp1.Row*48 + 38;
                        tmp1.PbPiece.Left = tmp1.Col*48 + 13;
                        Board.Position[tmp1.Row, tmp1.Col].IsEmpty = false;
                        Board.Position[tmp1.Row, tmp1.Col].Side = tmp1.Side;
                        Board.Position[tmp1.Row, tmp1.Col].Index = tmp1.Index;
                        Board.Position[tmp1.Row, tmp1.Col].Name = tmp1.Name;

                        // delete the last move from Log
                        if (TurnCount >= 1) TurnCount--;
                        GameLog.RemoveAt(TurnCount);
                        CaptureKing();
                        if (PbGameOver.Visible)
                        {
                            PbGameOver.Visible = false;
                        }
                        // rollback turn
                        ChangeTurn();
                        break;
                    case 1: // last move eat a other's piece
                        if (GameLog[TurnCount - 1].PieceDest.Name.Equals("KING"))
                            tmp2 = Players[GameLog[TurnCount - 1].PieceDest.Side].KingPiece;
                        if (GameLog[TurnCount - 1].PieceDest.Name.Equals("ADVISOR"))
                            tmp2 =
                                Players[GameLog[TurnCount - 1].PieceDest.Side].AdvisorPieces[
                                    GameLog[TurnCount - 1].PieceDest.Index];
                        if (GameLog[TurnCount - 1].PieceDest.Name.Equals("ELEPHANT"))
                            tmp2 =
                                Players[GameLog[TurnCount - 1].PieceDest.Side].ElephantPieces[
                                    GameLog[TurnCount - 1].PieceDest.Index];
                        if (GameLog[TurnCount - 1].PieceDest.Name.Equals("HORSE"))
                            tmp2 =
                                Players[GameLog[TurnCount - 1].PieceDest.Side].HorsePieces[
                                    GameLog[TurnCount - 1].PieceDest.Index];
                        if (GameLog[TurnCount - 1].PieceDest.Name.Equals("CHARIOT"))
                            tmp2 =
                                Players[GameLog[TurnCount - 1].PieceDest.Side].ChariotPieces[
                                    GameLog[TurnCount - 1].PieceDest.Index];
                        if (GameLog[TurnCount - 1].PieceDest.Name.Equals("CANNON"))
                            tmp2 =
                                Players[GameLog[TurnCount - 1].PieceDest.Side].CannonPieces[
                                    GameLog[TurnCount - 1].PieceDest.Index];
                        if (GameLog[TurnCount - 1].PieceDest.Name.Equals("SOLDIER"))
                            tmp2 =
                                Players[GameLog[TurnCount - 1].PieceDest.Side].SoldierPieces[
                                    GameLog[TurnCount - 1].PieceDest.Index];

                        //reset to old position
                        Board.Position[GameLog[TurnCount - 1].PieceFrom.Row, GameLog[TurnCount - 1].PieceFrom.Col].
                            IsEmpty = false;
                        Board.Position[GameLog[TurnCount - 1].PieceFrom.Row, GameLog[TurnCount - 1].PieceFrom.Col].
                            Side = GameLog[TurnCount - 1].PieceDest.Side;
                        Board.Position[GameLog[TurnCount - 1].PieceFrom.Row, GameLog[TurnCount - 1].PieceFrom.Col].
                            Name = GameLog[TurnCount - 1].PieceDest.Name;
                        Board.Position[GameLog[TurnCount - 1].PieceFrom.Row, GameLog[TurnCount - 1].PieceFrom.Col].
                            Index = GameLog[TurnCount - 1].PieceDest.Index;

                        tmp2.State = 1;
                        tmp2.PbPiece.Width = tmp2.PbPiece.Height = 39;
                        tmp2.PbPiece.Top = tmp2.Row*48 + 38;
                        tmp2.PbPiece.Left = tmp2.Col*48 + 13;
                        tmp2.PbPiece.Cursor = Cursors.Hand;

                        if (tmp2.Side == 0) // BLACK
                        {
                            if (tmp2.Name.Equals("KING")) tmp2.PbPiece.Image = Resources.B_K;
                            if (tmp2.Name.Equals("ADVISOR")) tmp2.PbPiece.Image = Resources.B_A;
                            if (tmp2.Name.Equals("ELEPHANT")) tmp2.PbPiece.Image = Resources.B_E;
                            if (tmp2.Name.Equals("HORSE")) tmp2.PbPiece.Image = Resources.B_H;
                            if (tmp2.Name.Equals("CHARIOT")) tmp2.PbPiece.Image = Resources.B_R;
                            if (tmp2.Name.Equals("CANNON")) tmp2.PbPiece.Image = Resources.B_C;
                            if (tmp2.Name.Equals("SOLDIER")) tmp2.PbPiece.Image = Resources.B_S;
                            BlackCount--;
                        }
                        else // RED
                        {
                            if (tmp2.Name.Equals("KING")) tmp2.PbPiece.Image = Resources.R_K;
                            if (tmp2.Name.Equals("ADVISOR")) tmp2.PbPiece.Image = Resources.R_A;
                            if (tmp2.Name.Equals("ELEPHANT")) tmp2.PbPiece.Image = Resources.R_E;
                            if (tmp2.Name.Equals("HORSE")) tmp2.PbPiece.Image = Resources.R_H;
                            if (tmp2.Name.Equals("CHARIOT")) tmp2.PbPiece.Image = Resources.R_R;
                            if (tmp2.Name.Equals("CANNON")) tmp2.PbPiece.Image = Resources.R_C;
                            if (tmp2.Name.Equals("SOLDIER")) tmp2.PbPiece.Image = Resources.R_S;
                            RedCount--;
                        }

                        tmp1.Row = GameLog[TurnCount - 1].RowFrom;
                        tmp1.Col = GameLog[TurnCount - 1].ColFrom;
                        tmp1.PbPiece.Width = tmp1.PbPiece.Height = 39;
                        tmp1.PbPiece.Top = tmp1.Row*48 + 38;
                        tmp1.PbPiece.Left = tmp1.Col*48 + 13;
                        Board.Position[tmp1.Row, tmp1.Col].IsEmpty = false;
                        Board.Position[tmp1.Row, tmp1.Col].Side = tmp1.Side;
                        Board.Position[tmp1.Row, tmp1.Col].Index = tmp1.Index;
                        Board.Position[tmp1.Row, tmp1.Col].Name = tmp1.Name;

                        if (TurnCount >= 1) TurnCount--;
                        GameLog.RemoveAt(TurnCount);
                        if (Winner != -1) Winner = -1;
                        CaptureKing();
                        ChangeTurn();
                        break;
                }
            }
        }
Beispiel #4
0
        public static void SaveGameLog(Object sender, Piece p)
        {
            if (sender.GetType() == typeof (ChessForm))
            {
                TurnCount++;
                GameLog.Add(new Move());
                GameLog[TurnCount - 1].PieceFrom = MarkedPiece;
                GameLog[TurnCount - 1].RowFrom = p.Row;
                GameLog[TurnCount - 1].ColFrom = p.Col;
            }

            if (sender.GetType() == typeof (PictureBox))
            {
                TurnCount++;
                GameLog.Add(new Move());
                GameLog[TurnCount - 1].PieceFrom = MarkedPiece;
                GameLog[TurnCount - 1].RowFrom = MarkedPiece.Row;
                GameLog[TurnCount - 1].ColFrom = MarkedPiece.Col;
                GameLog[TurnCount - 1].PieceDest = p;
                GameLog[TurnCount - 1].RowDest = p.Row;
                GameLog[TurnCount - 1].ColDest = p.Col;
            }
        }
Beispiel #5
0
 static Game()
 {
     Playing = false;
     Marked = false;
     RedCount = 0;
     BlackCount = 0;
     OldPosition = new Piece();
     GameLog = new List<Move>();
     RCapturedPiece = new List<CapturedPiece>();
     BCapturedPiece = new List<CapturedPiece>();
     Players[0] = new Player(0);
     Players[1] = new Player(1);
     //
     // Capture king alert
     //
     PbCaptureKing.BackColor = Color.Transparent;
     PbCaptureKing.Image = Resources.CaptureKingAlert;
     PbCaptureKing.Width = 160;
     PbCaptureKing.Height = 70;
     PbCaptureKing.Top = 60;
     PbCaptureKing.Left = 450;
     PbCaptureKing.Visible = false;
     //
     // GameOver Panel
     //
     PbGameOver.BackColor = Color.Transparent;
     PbGameOver.Image = Resources.Gameover;
     PbGameOver.Size = new Size(160, 70);
     //PbGameOver.Controls.Add();
     //PbGameOver.Controls.Add();
     PbGameOver.Top = 60;
     PbGameOver.Left = 450;
     PbGameOver.Visible = false;
     //
     // RedTurn
     //
     RedTurn.SizeMode = PictureBoxSizeMode.Zoom;
     RedTurn.BackColor = Color.Transparent;
     RedTurn.Width = 30;
     RedTurn.Height = 30;
     RedTurn.Top = 340;
     RedTurn.Left = 600;
     RedTurn.Image = Resources.Turning;
     //
     // BlackTurn
     //
     BlackTurn.SizeMode = PictureBoxSizeMode.Zoom;
     BlackTurn.BackColor = Color.Transparent;
     BlackTurn.Width = 30;
     BlackTurn.Height = 30;
     BlackTurn.Top = 140;
     BlackTurn.Left = 600;
     BlackTurn.Image = Resources.NotTurn;
     //
     // btnGameOver
     //
     btnGameOver.BackColor = Color.NavajoWhite;
     btnGameOver.FlatAppearance.BorderColor = Color.DarkKhaki;
     btnGameOver.FlatStyle = FlatStyle.Flat;
     btnGameOver.Font = new Font("Segoe UI", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((163)));
     btnGameOver.Location = new Point(567, 34);
     btnGameOver.Size = new Size(69, 23);
     btnGameOver.TabIndex = 9;
     btnGameOver.Text = "Chịu thua";
     btnGameOver.UseVisualStyleBackColor = false;
     btnGameOver.Visible = false;
     //
     // btnTurnAgain
     //
     btnTurnAgain.BackColor = Color.NavajoWhite;
     btnTurnAgain.FlatAppearance.BorderColor = Color.DarkKhaki;
     btnTurnAgain.FlatStyle = FlatStyle.Flat;
     btnTurnAgain.Font = new Font("Segoe UI", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((163)));
     btnTurnAgain.Location = new Point(491, 34);
     btnTurnAgain.Size = new Size(69, 23);
     btnTurnAgain.TabIndex = 10;
     btnTurnAgain.Text = "Đi lại";
     btnTurnAgain.UseVisualStyleBackColor = false;
     btnTurnAgain.Visible = false;
 }
Beispiel #6
0
        public static void CapturePiece(Piece p)
        {
            int row = 0;
            int col = 0;
            p.State = 0;

            if (p.Side == 0) // BLACK
            {
                if (BlackCount >= 0 && BlackCount < 5)
                {
                    row = 0;
                    col = BlackCount;
                }
                if (BlackCount >= 5 && BlackCount < 11)
                {
                    row = 1;
                    col = BlackCount - 5;
                }
                if (BlackCount >= 10 && BlackCount < 15)
                {
                    row = 2;
                    col = BlackCount - 10;
                }
                BlackCount++;
                BCapturedPiece.Add(new CapturedPiece());
                BCapturedPiece[BlackCount - 1].Row = row;
                BCapturedPiece[BlackCount - 1].Col = col;
                BCapturedPiece[BlackCount - 1].PbPiece = p.PbPiece;
                if (p.Name.Equals("KING")) BCapturedPiece[BlackCount - 1].PbPiece.Image = Resources.Captured_B_K;
                if (p.Name.Equals("ADVISOR")) BCapturedPiece[BlackCount - 1].PbPiece.Image = Resources.Captured_B_A;
                if (p.Name.Equals("ELEPHANT")) BCapturedPiece[BlackCount - 1].PbPiece.Image = Resources.Captured_B_E;
                if (p.Name.Equals("HORSE")) BCapturedPiece[BlackCount - 1].PbPiece.Image = Resources.Captured_B_H;
                if (p.Name.Equals("CHARIOT")) BCapturedPiece[BlackCount - 1].PbPiece.Image = Resources.Captured_B_R;
                if (p.Name.Equals("CANNON")) BCapturedPiece[BlackCount - 1].PbPiece.Image = Resources.Captured_B_C;
                if (p.Name.Equals("SOLDIER")) BCapturedPiece[BlackCount - 1].PbPiece.Image = Resources.Captured_B_S;
                BCapturedPiece[BlackCount - 1].PbPiece.Width = 25;
                BCapturedPiece[BlackCount - 1].PbPiece.Height = 25;
                BCapturedPiece[BlackCount - 1].PbPiece.BackColor = Color.Transparent;
                BCapturedPiece[BlackCount - 1].PbPiece.Cursor = Cursors.Arrow;
                BCapturedPiece[BlackCount - 1].PbPiece.Top = BCapturedPiece[BlackCount - 1].Row*30 + 385;
                BCapturedPiece[BlackCount - 1].PbPiece.Left = BCapturedPiece[BlackCount - 1].Col*30 + 465;
            }
            else // RED
            {
                if (RedCount >= 0 && RedCount < 5)
                {
                    row = 0;
                    col = RedCount;
                }
                if (RedCount >= 5 && RedCount < 11)
                {
                    row = 1;
                    col = RedCount - 5;
                }
                if (RedCount >= 10 && RedCount < 15)
                {
                    row = 2;
                    col = RedCount - 10;
                }
                RedCount++;
                RCapturedPiece.Add(new CapturedPiece());
                RCapturedPiece[RedCount - 1].Row = row;
                RCapturedPiece[RedCount - 1].Col = col;
                RCapturedPiece[RedCount - 1].PbPiece = p.PbPiece;
                if (p.Name.Equals("KING")) RCapturedPiece[RedCount - 1].PbPiece.Image = Resources.Captured_R_K;
                if (p.Name.Equals("ADVISOR")) RCapturedPiece[RedCount - 1].PbPiece.Image = Resources.Captured_R_A;
                if (p.Name.Equals("ELEPHANT")) RCapturedPiece[RedCount - 1].PbPiece.Image = Resources.Captured_R_E;
                if (p.Name.Equals("HORSE")) RCapturedPiece[RedCount - 1].PbPiece.Image = Resources.Captured_R_H;
                if (p.Name.Equals("CHARIOT")) RCapturedPiece[RedCount - 1].PbPiece.Image = Resources.Captured_R_R;
                if (p.Name.Equals("CANNON")) RCapturedPiece[RedCount - 1].PbPiece.Image = Resources.Captured_R_C;
                if (p.Name.Equals("SOLDIER")) RCapturedPiece[RedCount - 1].PbPiece.Image = Resources.Captured_R_S;
                RCapturedPiece[RedCount - 1].PbPiece.Width = 25;
                RCapturedPiece[RedCount - 1].PbPiece.Height = 25;
                RCapturedPiece[RedCount - 1].PbPiece.BackColor = Color.Transparent;
                RCapturedPiece[RedCount - 1].PbPiece.Cursor = Cursors.Arrow;
                RCapturedPiece[RedCount - 1].PbPiece.Top = RCapturedPiece[RedCount - 1].Row*30 + 185;
                RCapturedPiece[RedCount - 1].PbPiece.Left = RCapturedPiece[RedCount - 1].Col*30 + 465;
            }
        }
Beispiel #7
0
        private void ValidMove_MouseClick(Object sender, MouseEventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if (sender.Equals(Board.Position[i, j].ValidMove))
                    {
                        if (Game.Marked)
                        {
                            Game.OldPosition.Row = Game.MarkedPiece.Row;
                            Game.OldPosition.Col = Game.MarkedPiece.Col;
                            Game.OldPosition.Side = Game.MarkedPiece.Side;
                            Game.OldPosition.PbPiece.BackColor = Color.Transparent;
                            Game.OldPosition.PbPiece.Image = Resources.OldPosition;
                            Game.OldPosition.PbPiece.Height = Game.OldPosition.PbPiece.Width = 40;
                            Game.OldPosition.PbPiece.Top = Game.MarkedPiece.Row * 48 + 37;
                            Game.OldPosition.PbPiece.Left = Game.MarkedPiece.Col * 48 + 12;
                            Controls.Add(Game.OldPosition.PbPiece);
                            switch (Board.Position[i, j].IsEmpty)
                            {
                                case true:
                                    if (Game.MarkedPiece.Side == 0) // BLACK
                                    {
                                        if (Game.MarkedPiece.Name.Equals("KING"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_K;
                                        if (Game.MarkedPiece.Name.Equals("ADVISOR"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_A;
                                        if (Game.MarkedPiece.Name.Equals("ELEPHANT"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_E;
                                        if (Game.MarkedPiece.Name.Equals("HORSE"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_H;
                                        if (Game.MarkedPiece.Name.Equals("CHARIOT"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_R;
                                        if (Game.MarkedPiece.Name.Equals("CANNON"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_C;
                                        if (Game.MarkedPiece.Name.Equals("SOLDIER"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_S;
                                    }
                                    else // RED
                                    {
                                        if (Game.MarkedPiece.Name.Equals("KING"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_K;
                                        if (Game.MarkedPiece.Name.Equals("ADVISOR"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_A;
                                        if (Game.MarkedPiece.Name.Equals("ELEPHANT"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_E;
                                        if (Game.MarkedPiece.Name.Equals("HORSE"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_H;
                                        if (Game.MarkedPiece.Name.Equals("CHARIOT"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_R;
                                        if (Game.MarkedPiece.Name.Equals("CANNON"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_C;
                                        if (Game.MarkedPiece.Name.Equals("SOLDIER"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_S;
                                    }
                                    Game.Marked = false;
                                    Game.SaveGameLog(this, Game.MarkedPiece);
                                    Game.ResetChessPoint(Game.MarkedPiece.Row, Game.MarkedPiece.Col);
                                    Game.SetPiece(Game.MarkedPiece, i, j);

                                    // Check capture king
                                    Game.CaptureKing();
                                    Game.ChangeTurn();
                                    // check gameover
                                    Game.GameOver();
                                    if (Game.Winner != -1)
                                    {
                                        Game.PbCaptureKing.Visible = false;
                                        Game.PbGameOver.Visible = true;
                                        Game.btnTurnAgain.Visible = true;
                                        Game.btnGameOver.Visible = true;
                                    }
                                    else
                                    {
                                        Game.PbGameOver.Visible = false;
                                        Game.btnTurnAgain.Visible = false;
                                        Game.btnGameOver.Visible = false;
                                    }
                                    Board.ResetValidMove();
                                    break;
                                case false: // not empty
                                    if (Game.MarkedPiece.Side == 0) // BLACK
                                    {
                                        if (Game.MarkedPiece.Name.Equals("KING"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_K;
                                        if (Game.MarkedPiece.Name.Equals("ADVISOR"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_A;
                                        if (Game.MarkedPiece.Name.Equals("ELEPHANT"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_E;
                                        if (Game.MarkedPiece.Name.Equals("HORSE"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_H;
                                        if (Game.MarkedPiece.Name.Equals("CHARIOT"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_R;
                                        if (Game.MarkedPiece.Name.Equals("CANNON"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_C;
                                        if (Game.MarkedPiece.Name.Equals("SOLDIER"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.B_S;
                                    }
                                    else // RED
                                    {
                                        if (Game.MarkedPiece.Name.Equals("KING"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_K;
                                        if (Game.MarkedPiece.Name.Equals("ADVISOR"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_A;
                                        if (Game.MarkedPiece.Name.Equals("ELEPHANT"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_E;
                                        if (Game.MarkedPiece.Name.Equals("HORSE"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_H;
                                        if (Game.MarkedPiece.Name.Equals("CHARIOT"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_R;
                                        if (Game.MarkedPiece.Name.Equals("CANNON"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_C;
                                        if (Game.MarkedPiece.Name.Equals("SOLDIER"))
                                            Game.MarkedPiece.PbPiece.Image = Resources.R_S;
                                    }

                                    int otherSide;
                                    if (Game.MarkedPiece.Side == 0) otherSide = 1;
                                    else otherSide = 0;

                                    var tmp = new Piece();

                                    if (Board.Position[i, j].Name.Equals("KING"))
                                        tmp = Game.Players[otherSide].KingPiece;
                                    if (Board.Position[i, j].Name.Equals("ADVISOR"))
                                        tmp = Game.Players[otherSide].AdvisorPieces[Board.Position[i, j].Index];
                                    if (Board.Position[i, j].Name.Equals("ELEPHANT"))
                                        tmp = Game.Players[otherSide].ElephantPieces[Board.Position[i, j].Index];
                                    if (Board.Position[i, j].Name.Equals("HORSE"))
                                        tmp = Game.Players[otherSide].HorsePieces[Board.Position[i, j].Index];
                                    if (Board.Position[i, j].Name.Equals("CHARIOT"))
                                        tmp = Game.Players[otherSide].ChariotPieces[Board.Position[i, j].Index];
                                    if (Board.Position[i, j].Name.Equals("CANNON"))
                                        tmp = Game.Players[otherSide].CannonPieces[Board.Position[i, j].Index];
                                    if (Board.Position[i, j].Name.Equals("SOLDIER"))
                                        tmp = Game.Players[otherSide].SoldierPieces[Board.Position[i, j].Index];

                                    Game.Marked = false;
                                    Game.SaveGameLog(sender, tmp);
                                    Game.CapturePiece(tmp);
                                    Game.ResetChessPoint(Game.MarkedPiece.Row, Game.MarkedPiece.Col);
                                    Game.SetPiece(Game.MarkedPiece, i, j);
                                    Game.CaptureKing();
                                    Game.ChangeTurn();
                                    // check gameover
                                    Game.GameOver();
                                    if (Game.Winner != -1)
                                    {
                                        Game.PbCaptureKing.Visible = false;
                                        Game.PbGameOver.Visible = true;
                                        Game.btnTurnAgain.Visible = true;
                                        Game.btnGameOver.Visible = true;
                                    }
                                    else
                                    {
                                        Game.PbGameOver.Visible = false;
                                        Game.btnTurnAgain.Visible = false;
                                        Game.btnGameOver.Visible = false;
                                    }
                                    Board.ResetValidMove();
                                    break;
                            }
                        }
                    }
                }
            }
        }
Beispiel #8
0
        private void ChessBoard_MouseClick(Object sender, MouseEventArgs e)
        {
            var tmp = new Piece();
            switch (Game.Marked)
            {
                case true:
                    Game.Marked = false;
                    if (Game.MarkedPiece.Name.Equals("KING")) tmp = Game.Players[Game.MarkedPiece.Side].KingPiece;
                    if (Game.MarkedPiece.Name.Equals("ADVISOR"))
                        tmp = Game.Players[Game.MarkedPiece.Side].AdvisorPieces[Game.MarkedPiece.Index];
                    if (Game.MarkedPiece.Name.Equals("ELEPHANT"))
                        tmp = Game.Players[Game.MarkedPiece.Side].ElephantPieces[Game.MarkedPiece.Index];
                    if (Game.MarkedPiece.Name.Equals("HORSE"))
                        tmp = Game.Players[Game.MarkedPiece.Side].HorsePieces[Game.MarkedPiece.Index];
                    if (Game.MarkedPiece.Name.Equals("CHARIOT"))
                        tmp = Game.Players[Game.MarkedPiece.Side].ChariotPieces[Game.MarkedPiece.Index];
                    if (Game.MarkedPiece.Name.Equals("CANNON"))
                        tmp = Game.Players[Game.MarkedPiece.Side].CannonPieces[Game.MarkedPiece.Index];
                    if (Game.MarkedPiece.Name.Equals("SOLDIER"))
                        tmp = Game.Players[Game.MarkedPiece.Side].SoldierPieces[Game.MarkedPiece.Index];

                    if (tmp.Side == 0) // BLACK
                    {
                        if (tmp.Name.Equals("KING")) tmp.PbPiece.Image = Resources.B_K;
                        if (tmp.Name.Equals("ADVISOR")) tmp.PbPiece.Image = Resources.B_A;
                        if (tmp.Name.Equals("ELEPHANT")) tmp.PbPiece.Image = Resources.B_E;
                        if (tmp.Name.Equals("HORSE")) tmp.PbPiece.Image = Resources.B_H;
                        if (tmp.Name.Equals("CHARIOT")) tmp.PbPiece.Image = Resources.B_R;
                        if (tmp.Name.Equals("CANNON")) tmp.PbPiece.Image = Resources.B_C;
                        if (tmp.Name.Equals("SOLDIER")) tmp.PbPiece.Image = Resources.B_S;
                    }
                    else // RED
                    {
                        if (tmp.Name.Equals("KING")) tmp.PbPiece.Image = Resources.R_K;
                        if (tmp.Name.Equals("ADVISOR")) tmp.PbPiece.Image = Resources.R_A;
                        if (tmp.Name.Equals("ELEPHANT")) tmp.PbPiece.Image = Resources.R_E;
                        if (tmp.Name.Equals("HORSE")) tmp.PbPiece.Image = Resources.R_H;
                        if (tmp.Name.Equals("CHARIOT")) tmp.PbPiece.Image = Resources.R_R;
                        if (tmp.Name.Equals("CANNON")) tmp.PbPiece.Image = Resources.R_C;
                        if (tmp.Name.Equals("SOLDIER")) tmp.PbPiece.Image = Resources.R_S;
                    }
                    Board.ResetValidMove();
                    break;
                case false:
                    break;
            }
        }