Exemplo n.º 1
0
        /// <summary>
        /// 撤销走子记录
        /// </summary>
        public void CancelRecord()
        {
            Player[]   players    = gameMgr.players;
            Chessboard chessBoard = gameMgr.chessBoard;

            Record record = Pop();

            record.orgPiece.IsFirstMove = record.orgPieceIsFirstMove;

            chessBoard.AppendPiece(record.orgPiece, record.orgBoardIdx);
            chessBoard.AppendPiece(record.dstPiece, record.dstBoardIdx);
            chessBoard.LastActionPieceAtBoardIdx     = record.lastActionPieceAtBoardIdx;
            chessBoard.LastActionPieceAtPrevBoardIdx = record.lastActionPieceAtPrevBoardIdx;

            players[record.orgPlayerIdx].DelBoardPieceRef(record.dstBoardIdx.x, record.dstBoardIdx.y);
            players[record.orgPlayerIdx].AddBoardPieceRef(record.orgBoardIdx.x, record.orgBoardIdx.y);

            if (record.type == ChessRecordType.Eat)
            {
                players[record.dstPlayerIdx].AddBoardPieceRef(record.dstBoardIdx.x, record.dstBoardIdx.y);
            }
        }
Exemplo n.º 2
0
        void CreateStandardPlayerBoardPieces(Player player, ChessColor color, BoardDirection dir)
        {
            int pawnY = 1;
            int kingY = 0;

            if (dir == BoardDirection.Reverse)
            {
                kingY = 7;
                pawnY = 6;
            }

            //pawn
            for (int i = 0; i < 8; i++)
            {
                Pawn pawn = new Pawn();
                pawn.Color           = color;
                pawn.PieceAtBoardDir = dir;
                pawn.IsFirstMove     = true;
                chessBoard.AppendPiece(pawn, i, pawnY);
                player.AddBoardPieceRef(i, pawnY);
            }

            //Rook
            Piece piece = Tools.Instance.CreatePiece(PieceType.Rook);

            piece.Color = color;
            chessBoard.AppendPiece(piece, 0, kingY);
            player.AddBoardPieceRef(0, kingY);

            piece       = Tools.Instance.CreatePiece(PieceType.Rook);
            piece.Color = color;
            chessBoard.AppendPiece(piece, 7, kingY);
            player.AddBoardPieceRef(7, kingY);

            //Knight
            piece       = Tools.Instance.CreatePiece(PieceType.Knight);
            piece.Color = color;
            chessBoard.AppendPiece(piece, 1, kingY);
            player.AddBoardPieceRef(1, kingY);

            piece       = Tools.Instance.CreatePiece(PieceType.Knight);
            piece.Color = color;
            chessBoard.AppendPiece(piece, 6, kingY);
            player.AddBoardPieceRef(6, kingY);

            //Bishop
            piece       = Tools.Instance.CreatePiece(PieceType.Bishop);
            piece.Color = color;
            chessBoard.AppendPiece(piece, 2, kingY);
            player.AddBoardPieceRef(2, kingY);

            piece       = Tools.Instance.CreatePiece(PieceType.Bishop);
            piece.Color = color;
            chessBoard.AppendPiece(piece, 5, kingY);
            player.AddBoardPieceRef(5, kingY);

            //King
            piece       = Tools.Instance.CreatePiece(PieceType.King);
            piece.Color = color;
            chessBoard.AppendPiece(piece, 3, kingY);
            player.AddBoardPieceRef(3, kingY);

            //Queen
            piece       = Tools.Instance.CreatePiece(PieceType.Queen);
            piece.Color = color;
            chessBoard.AppendPiece(piece, 4, kingY);
            player.AddBoardPieceRef(4, kingY);
        }