示例#1
0
        public void Menu()
        {
            while (true)
            {
                var board = new Board();
                Introductions();

                _boardSize   = ConsoleReadHelper.GetBoardSize("Type board size (3-10)");            //NIE MOZE BYC PUSTY
                _fieldsToWin = ConsoleReadHelper.GetBoardSize($"How many symbols next each other do you need to win ?" +
                                                              $"[Min 3 Max {_boardSize}] type:  "); // DODAJ SPRAWDZENIE CZY JEST GIT

                switch (ConsoleReadHelper.GetCommnadType("Type command: "))
                {
                case CommandTypes.GameForTwo:
                    Console.Clear();
                    _gameWithAI = false;
                    GameLoop();
                    break;

                case CommandTypes.GameWithComputer:
                    Console.Clear();
                    _gameWithAI = true;
                    GameLoop();
                    break;

                case CommandTypes.Exit:
                    Environment.Exit(0);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
示例#2
0
        public void Turn()
        {
            var    board = new Board(_boardSize);
            var    currentInfoAboutFields = board.GetCurrentInfoAboutFields();
            string step;

            if (_gameWithAI && _currentPlayer == "o")
            {
                var computer = new AI();
                step = computer.Move(_boardSize, _fieldsToWin);
            }
            else
            {
                step = ConsoleReadHelper.GetSymbolField(_currentPlayer, "Type next step: ");
            }


            var index = currentInfoAboutFields.FirstOrDefault(x => x.SymbolField == step);

            _tab[index.IndexOne, index.IndexTwo] = _currentPlayer; //mark symbol on board

            index.FieldIsEmpty = false;
            index.Mark         = _currentPlayer;


            var ifWinner = CheckSomeoneWin();
            var ifDraw   = CheckIsItDraw();

            if (ifWinner)
            {
                Console.Clear();
                board.DisplayBoard(_tab);//display board
                Console.WriteLine($"\n\n\t\tWinner is player: {_currentPlayer.ToUpper()}".ToUpper() +
                                  $"\n\n\n\n -----type one key on keyboard, to get back to main menu------");
                Console.ReadKey();
                _gameFinished = true;
                return;
            }

            if (ifDraw)
            {
                board.DisplayBoard(_tab);//display board
                Console.WriteLine($"THERE IS NO WINNER... IT'S DRAW " +
                                  $"\n\n\n\n -----tap any key on keyboard, to get back to main menu------");
                Console.ReadKey();
                _gameFinished = true;
                return;
            }

            if (_currentPlayer == "x")
            {
                _currentPlayer = "o";
            }
            else
            {
                _currentPlayer = "x";
            }
        }