Пример #1
0
        public static bool IsPlayerInputValid(string move)
        {
            var isMoveStringLengthValid = IsMoveStringLengthValid(move);

            if (!isMoveStringLengthValid)
            {
                SysLogger.DisplayMessageToTheConsole("InvalidCoordinates");
                return(false);
            }

            var isInputDelimiterValid = IsInputDelimiterValid(move);
            var isInputDigitsValid    = false;

            if (isInputDelimiterValid)
            {
                isInputDigitsValid = IsInputDigitsValid(move);
            }

            var isInputValid = isInputDelimiterValid && isInputDigitsValid;

            if (!isInputValid)
            {
                SysLogger.DisplayMessageToTheConsole("InvalidCoordinates");
            }

            return(isInputValid);
        }
Пример #2
0
        public static bool IsPlayerGivingUp(string moveInput)
        {
            if (moveInput == "q" || moveInput == "'q'")
            {
                SysLogger.DisplayMessageToTheConsole("PlayerLostGame");
                return(true);
            }

            return(false);
        }
Пример #3
0
        public static bool IsCellFree(string moveInput)
        {
            var row    = int.Parse(moveInput.Split(Move.GetValidDelimiter())[0]);
            var column = int.Parse(moveInput.Split(Move.GetValidDelimiter())[1]);

            var isCellFree = GameField[row - 1, column - 1] == GetEmptyCellChar();

            if (!isCellFree)
            {
                SysLogger.DisplayMessageToTheConsole("CellOccupied");
            }

            return(isCellFree);
        }
Пример #4
0
        public static bool IsThereWinner()
        {
            var currentPlayerSymbol = Player.GetCurrentPlayerSymbol();

            var isThereWinner = FieldValidator.IsThereWinningColumn(currentPlayerSymbol) ||
                                FieldValidator.IsThereWinningRow(currentPlayerSymbol) ||
                                FieldValidator.IsThereWinningTopLeftBottomRightDiagonal(currentPlayerSymbol) ||
                                FieldValidator.IsThereWinningBottomLeftTopRightDiagonal(currentPlayerSymbol);

            if (isThereWinner)
            {
                DrawField();
                SysLogger.DisplayMessageToTheConsole("GameOver");
            }

            return(isThereWinner);
        }
Пример #5
0
        public static bool IsMoreMovesPossible()
        {
            for (var row = 0; row < Size; row++)
            {
                for (var column = 0; column < Size; column++)
                {
                    if (GameField[row, column] == GetEmptyCellChar())
                    {
                        return(true);
                    }
                }
            }

            SysLogger.DisplayMessageToTheConsole("NoMoreTurns");
            DrawField();

            return(false);
        }
Пример #6
0
        public static Field CreateField(int inputSize = 0)
        {
            var size = inputSize;

            if (size == 0)
            {
                SysLogger.DisplayMessageToTheConsole("EnterFieldSize");
                var userSizeInput = Console.ReadLine();

                if (!FieldValidator.IsFieldSizeValid(userSizeInput))
                {
                    return(null);
                }
                size = int.Parse(userSizeInput);
            }

            return(new Field(size));
        }
Пример #7
0
 public static string PromptForNextMove()
 {
     SysLogger.DisplayMessageToTheConsole("EnterNextMove");
     return(Console.ReadLine());
 }
Пример #8
0
 private Field(int value)
 {
     Size = value;
     PopulateField();
     SysLogger.DisplayMessageToTheConsole("GameStart");
 }