Beispiel #1
0
        // Load piece coordinates on the board
        public void LoadPiecesPositionsFromBoard(Board board)
        {
            int rectangleCount = board.positions.GetLength(0);
            int pointsCountInRect = board.positions.GetLength(1);

            positions = new Position[rectangleCount, pointsCountInRect];
            positionsOnBoard = new bool[rectangleCount, pointsCountInRect];

            for (int i = 0; i < rectangleCount; i++)
            {
                for (int j = 0; j < pointsCountInRect; j++)
                {
                    positions[i, j].x = board.positions[i, j].x;
                    positions[i, j].y = board.positions[i, j].y;
                }
            }
        }
Beispiel #2
0
        // Move the pieces
        public void Move(string input, Piece opponent, Board board)
        {
            Position fromPos = GetPositionFromInput(input[0].ToString() + input[1].ToString());
            Position toPos = GetPositionFromInput(input[2].ToString() + input[3].ToString());

            if (CanBeMoved(fromPos, toPos, opponent))
            {
                positionsOnBoard[fromPos.x, fromPos.y] = false; // освобождаване на старата позиция
                DrawPieceAt(fromPos, board.PiecePlaceColor, opponent);

                DrawPieceAt(toPos, PiecesColor, opponent);
                positionsOnBoard[toPos.x, toPos.y] = true; // поставяне на новата позиция
            }
            else
            {
                throw new ArgumentException("Please try again!");
            }
        }
        private static void PlayGame()
        {
            byte gameMode;
            do
            {
                Console.Clear();
                Console.SetCursorPosition(0, 0);
                Console.Write("Press 1 for singleplayer or 2 for multiplayer: ");
            }
            while (!byte.TryParse(Console.ReadLine(), out gameMode) || (gameMode != 1 && gameMode != 2));

            List<string> playersName = (InputPlayersNames(gameMode));

            // SinglePlayer is started when the name of the 2nd player is 'PC'
            if (gameMode == 1)
            {
                playersName.Add("PC");
                secondPlayer = new Robot(new Piece(), playersName[1]);
            }
            else
            {
                secondPlayer = new RealPlayer(new Piece(), playersName[1], 0);
            }

            gameBoard = new Board();
            gameBoard.DrawBoard();

            firstPlayer = new RealPlayer(new Piece(), playersName[0], 0);

            firstPlayer.piece.LoadPiecesPositionsFromBoard(gameBoard);
            secondPlayer.piece.LoadPiecesPositionsFromBoard(gameBoard);

            firstPlayer.Display = new Position(35, 11);
            secondPlayer.Display = new Position(47, 17);

            secondPlayer.piece.PiecesColor = ConsoleColor.Red;

            PiecePlacing();
            PieceMoving();
        }