コード例 #1
0
        public static bool IfCellEmpty(string[,] gameBoard, boardCoordinate coordinates)
        {
            bool isCellEmpty = (gameBoard[coordinates.row, coordinates.column] == EMPTY_CELL);

            if (!isCellEmpty)
            {
                Console.WriteLine("\n  This cell is already occupied. Please try again.");
            }

            return(isCellEmpty);
        }
コード例 #2
0
        static boardCoordinate ParseCoordinates(string rawCoordinates)
        {
            var coordinate = new boardCoordinate();

            const int COORD_X = 0; //First and third positions
            const int COORD_Y = 2; //of the input string respectively

            coordinate.row    = int.Parse(rawCoordinates[COORD_X].ToString());
            coordinate.column = int.Parse(rawCoordinates[COORD_Y].ToString());

            return(coordinate);
        }
コード例 #3
0
        //The gameplay method
        public static void Start()
        {
            Draw.InitialGameBoard(gameBoard);

            while (!Verify.IfGameOver(gameBoard, numberOfTurnsMade))
            {
                numberOfTurnsMade++;

                string rawCoordinates = "";
                bool   isRightFormat  = false; //Format of coordinate imput
                bool   isEmpty        = false; //If current cell is empty

                //Print prompt and receive coordinates of the turn
                while (!isEmpty)
                {
                    do
                    {
                        rawCoordinates = ReceiveCoordinates(currentSign);
                        isRightFormat  = Verify.CheckCoordinates(rawCoordinates);
                    }while (!isRightFormat);

                    boardCoordinate coordinates = ParseCoordinates(rawCoordinates);

                    isEmpty = Verify.IfCellEmpty(gameBoard, coordinates);
                    if (!isEmpty)
                    {
                        Console.WriteLine("\n  This cell is already occupied. Please try again.");
                    }
                    else
                    {
                        gameBoard[coordinates.row, coordinates.column] = currentSign.ToString();
                    }
                }

                Draw.CurrentGameBoard(gameBoard);
                ChangeCurrentSign();
            }
        }