Example #1
0
 public Game()
 {
     rc[0]  = new Horse(0, 1, "傌", "red");
     rc[1]  = new Elephant(0, 2, "相", "red");
     rc[2]  = new Advisor(0, 3, "仕", "red");
     rc[3]  = new General(0, 4, "帅", "red");
     rc[4]  = new Advisor(0, 5, "仕", "red");
     rc[5]  = new Elephant(0, 6, "相", "red");
     rc[6]  = new Horse(0, 7, "傌", "red");
     rc[7]  = new Rook(0, 8, "俥", "red");
     rc[8]  = new Cannon(2, 1, "炮", "red");
     rc[9]  = new Cannon(2, 7, "炮", "red");
     rc[10] = new Soilder(3, 0, "兵", "red");
     rc[11] = new Soilder(3, 2, "兵", "red");
     rc[12] = new Soilder(3, 4, "兵", "red");
     rc[13] = new Soilder(3, 6, "兵", "red");
     rc[14] = new Soilder(3, 8, "兵", "red");
     rc[15] = new Rook(0, 0, "俥", "red");
     bc[0]  = new Horse(9, 1, "馬", "black");
     bc[1]  = new Elephant(9, 2, "象", "black");
     bc[2]  = new Advisor(9, 3, "士", "black");
     bc[3]  = new General(9, 4, "将", "black");
     bc[4]  = new Advisor(9, 5, "士", "black");
     bc[5]  = new Elephant(9, 6, "象", "black");
     bc[6]  = new Horse(9, 7, "馬", "black");
     bc[7]  = new Rook(9, 8, "車", "black");
     bc[8]  = new Cannon(7, 1, "砲", "black");
     bc[9]  = new Cannon(7, 7, "砲", "black");
     bc[10] = new Soilder(6, 0, "卒", "black");
     bc[11] = new Soilder(6, 2, "卒", "black");
     bc[12] = new Soilder(6, 4, "卒", "black");
     bc[13] = new Soilder(6, 6, "卒", "black");
     bc[14] = new Soilder(6, 8, "卒", "black");
     bc[15] = new Rook(9, 0, "車", "black");
     refresh(board, rc, bc);
 }
Example #2
0
        private void PlacePawns()
        {
            gameState = GameState.PLAYING;

            blackGeneral = new General(PlayerSide.BLACK);
            redGeneral   = new General(PlayerSide.RED);

            colBlackGeneral = 4;
            rowBlackGeneral = 0;

            colRedGeneral = 4;
            rowRedGeneral = 9;

            blackGeneralChecked = false;
            redGeneralChecked   = false;

            threateningPawn    = null;
            rowThreateningPawn = -1;
            colThreateningPawn = -1;

            selectedPawn = Rectangle.Empty;
            selectedCol  = -1;
            selectedRow  = -1;
            selectedPawnPossibleMovements = null;

            // Black side.
            gameBoardPositions[0, 0] = new Rook(PlayerSide.BLACK);
            gameBoardPositions[0, 1] = new Knight(PlayerSide.BLACK);
            gameBoardPositions[0, 2] = new Elephant(PlayerSide.BLACK);
            gameBoardPositions[0, 3] = new Advisor(PlayerSide.BLACK);
            gameBoardPositions[0, 4] = blackGeneral;
            gameBoardPositions[0, 5] = new Advisor(PlayerSide.BLACK);
            gameBoardPositions[0, 6] = new Elephant(PlayerSide.BLACK);
            gameBoardPositions[0, 7] = new Knight(PlayerSide.BLACK);
            gameBoardPositions[0, 8] = new Rook(PlayerSide.BLACK);

            gameBoardPositions[2, 1] = new Cannon(PlayerSide.BLACK);
            gameBoardPositions[2, 7] = new Cannon(PlayerSide.BLACK);

            gameBoardPositions[3, 0] = new Soldier(PlayerSide.BLACK);
            gameBoardPositions[3, 2] = new Soldier(PlayerSide.BLACK);
            gameBoardPositions[3, 4] = new Soldier(PlayerSide.BLACK);
            gameBoardPositions[3, 6] = new Soldier(PlayerSide.BLACK);
            gameBoardPositions[3, 8] = new Soldier(PlayerSide.BLACK);

            // Red side.
            gameBoardPositions[9, 0] = new Rook(PlayerSide.RED);
            gameBoardPositions[9, 1] = new Knight(PlayerSide.RED);
            gameBoardPositions[9, 2] = new Elephant(PlayerSide.RED);
            gameBoardPositions[9, 3] = new Advisor(PlayerSide.RED);
            gameBoardPositions[9, 4] = redGeneral;
            gameBoardPositions[9, 5] = new Advisor(PlayerSide.RED);
            gameBoardPositions[9, 6] = new Elephant(PlayerSide.RED);
            gameBoardPositions[9, 7] = new Knight(PlayerSide.RED);
            gameBoardPositions[9, 8] = new Rook(PlayerSide.RED);

            gameBoardPositions[7, 1] = new Cannon(PlayerSide.RED);
            gameBoardPositions[7, 7] = new Cannon(PlayerSide.RED);

            gameBoardPositions[6, 0] = new Soldier(PlayerSide.RED);
            gameBoardPositions[6, 2] = new Soldier(PlayerSide.RED);
            gameBoardPositions[6, 4] = new Soldier(PlayerSide.RED);
            gameBoardPositions[6, 6] = new Soldier(PlayerSide.RED);
            gameBoardPositions[6, 8] = new Soldier(PlayerSide.RED);

            // Fill null cells with empty pawns.
            for (int row = 0; row < 10; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    if (gameBoardPositions[row, col] == null)
                    {
                        gameBoardPositions[row, col] = new EmptyPawn();
                    }
                }
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            //创建棋盘和摆放棋子
            const bool red   = true;  //player red side
            const bool black = false; //player black side
            bool       turn  = red;



            Soldier  Sr1 = new Soldier(red, 6, 0); Soldier Sr2 = new Soldier(red, 6, 2);
            Soldier  Sr3 = new Soldier(red, 6, 4); Soldier Sr4 = new Soldier(red, 6, 6);
            Soldier  Sr5 = new Soldier(red, 6, 8);
            Canon    Cr1 = new Canon(red, 7, 1); Canon Cr2 = new Canon(red, 7, 7);
            Rook     Rr1 = new Rook(red, 9, 0); Rook Rr2 = new Rook(red, 9, 8);
            Horse    Hr1 = new Horse(red, 9, 1); Horse Hr2 = new Horse(red, 9, 7);
            Elephant Er1 = new Elephant(red, 9, 2); Elephant Er2 = new Elephant(red, 9, 6);
            Guard    Gr1 = new Guard(red, 9, 3); Guard Gr2 = new Guard(red, 9, 5);
            King     Kr = new King(red, 9, 4);

            Soldier  Sb1 = new Soldier(black, 3, 0); Soldier Sb2 = new Soldier(black, 3, 2);
            Soldier  Sb3 = new Soldier(black, 3, 4); Soldier Sb4 = new Soldier(black, 3, 6);
            Soldier  Sb5 = new Soldier(black, 3, 8);
            Canon    Cb1 = new Canon(black, 2, 1); Canon Cb2 = new Canon(black, 2, 7);
            Rook     Rb1 = new Rook(black, 0, 0); Rook Rb2 = new Rook(black, 0, 8);
            Horse    Hb1 = new Horse(black, 0, 1); Horse Hb2 = new Horse(black, 0, 7);
            Elephant Eb1 = new Elephant(black, 0, 2); Elephant Eb2 = new Elephant(black, 0, 6);
            Guard    Gb1 = new Guard(black, 0, 3); Guard Gb2 = new Guard(black, 0, 5);
            King     Kb = new King(black, 0, 4);

            Board B = new Board();

            B.placeThePieces(Sr1.GettheNameOfPiece(), Sr1.GetxCoordinate(), Sr1.GetyCoordinate());
            B.placeThePieces(Sr2.GettheNameOfPiece(), Sr2.GetxCoordinate(), Sr2.GetyCoordinate());
            B.placeThePieces(Sr3.GettheNameOfPiece(), Sr3.GetxCoordinate(), Sr3.GetyCoordinate());
            B.placeThePieces(Sr4.GettheNameOfPiece(), Sr4.GetxCoordinate(), Sr4.GetyCoordinate());
            B.placeThePieces(Sr5.GettheNameOfPiece(), Sr5.GetxCoordinate(), Sr5.GetyCoordinate());
            B.placeThePieces(Cr1.GettheNameOfPiece(), Cr1.GetxCoordinate(), Cr1.GetyCoordinate());
            B.placeThePieces(Cr2.GettheNameOfPiece(), Cr2.GetxCoordinate(), Cr2.GetyCoordinate());
            B.placeThePieces(Rr1.GettheNameOfPiece(), Rr1.GetxCoordinate(), Rr1.GetyCoordinate());
            B.placeThePieces(Rr2.GettheNameOfPiece(), Rr2.GetxCoordinate(), Rr2.GetyCoordinate());
            B.placeThePieces(Hr1.GettheNameOfPiece(), Hr1.GetxCoordinate(), Hr1.GetyCoordinate());
            B.placeThePieces(Hr2.GettheNameOfPiece(), Hr2.GetxCoordinate(), Hr2.GetyCoordinate());
            B.placeThePieces(Er1.GettheNameOfPiece(), Er1.GetxCoordinate(), Er1.GetyCoordinate());
            B.placeThePieces(Er2.GettheNameOfPiece(), Er2.GetxCoordinate(), Er2.GetyCoordinate());
            B.placeThePieces(Gr1.GettheNameOfPiece(), Gr1.GetxCoordinate(), Gr1.GetyCoordinate());
            B.placeThePieces(Gr2.GettheNameOfPiece(), Gr2.GetxCoordinate(), Gr2.GetyCoordinate());
            B.placeThePieces(Kr.GettheNameOfPiece(), Kr.GetxCoordinate(), Kr.GetyCoordinate());
            B.placeThePieces(Sb1.GettheNameOfPiece(), Sb1.GetxCoordinate(), Sb1.GetyCoordinate());
            B.placeThePieces(Sb2.GettheNameOfPiece(), Sb2.GetxCoordinate(), Sb2.GetyCoordinate());
            B.placeThePieces(Sb3.GettheNameOfPiece(), Sb3.GetxCoordinate(), Sb3.GetyCoordinate());
            B.placeThePieces(Sb4.GettheNameOfPiece(), Sb4.GetxCoordinate(), Sb4.GetyCoordinate());
            B.placeThePieces(Sb5.GettheNameOfPiece(), Sb5.GetxCoordinate(), Sb5.GetyCoordinate());
            B.placeThePieces(Cb1.GettheNameOfPiece(), Cb1.GetxCoordinate(), Cb1.GetyCoordinate());
            B.placeThePieces(Cb2.GettheNameOfPiece(), Cb2.GetxCoordinate(), Cb2.GetyCoordinate());
            B.placeThePieces(Rb1.GettheNameOfPiece(), Rb1.GetxCoordinate(), Rb1.GetyCoordinate());
            B.placeThePieces(Rb2.GettheNameOfPiece(), Rb2.GetxCoordinate(), Rb2.GetyCoordinate());
            B.placeThePieces(Hb1.GettheNameOfPiece(), Hb1.GetxCoordinate(), Hb1.GetyCoordinate());
            B.placeThePieces(Hb2.GettheNameOfPiece(), Hb2.GetxCoordinate(), Hb2.GetyCoordinate());
            B.placeThePieces(Eb1.GettheNameOfPiece(), Eb1.GetxCoordinate(), Eb1.GetyCoordinate());
            B.placeThePieces(Eb2.GettheNameOfPiece(), Eb2.GetxCoordinate(), Eb2.GetyCoordinate());
            B.placeThePieces(Gb1.GettheNameOfPiece(), Gb1.GetxCoordinate(), Gb1.GetyCoordinate());
            B.placeThePieces(Gb2.GettheNameOfPiece(), Gb2.GetxCoordinate(), Gb2.GetyCoordinate());
            B.placeThePieces(Kb.GettheNameOfPiece(), Kb.GetxCoordinate(), Kb.GetyCoordinate());

            B.printBoard();

            //-------------------------------------------------------------------------------------------
            Console.WriteLine("\n-----------------------------------\n");
            if (turn == red)
            {
                Console.WriteLine("It's RED side turn!\n");

                //输入所选位置
                int x0; int y0;
                Console.WriteLine("Please choose a Piece you want to move\n");

                Console.Write("x:");
                string X0 = Console.ReadLine();
                x0 = Convert.ToInt32(X0);

                Console.Write("y:");
                string Y0 = Console.ReadLine();
                y0 = Convert.ToInt32(Y0);

                //得到所选位置的名称
                B.getValue(x0, y0);

                //判断所选是否为我方棋子
                if (!B.getValue(x0, y0).Contains("r"))
                {
                    Console.WriteLine("you must choose a RED piece!");
                }
                //输入要移动到的位置
            }

            else if (turn == black)
            {
                Console.WriteLine("It's BLACK side turn!\n");
            }
            //turn = !turn;
        }