Пример #1
0
        /// <summary>
        /// manage each new task based on the current game state
        /// </summary>
        private void ManageGameStateTasks()
        {
            switch (_gameView.CurrentViewState)
            {
            case ConsoleView.ViewState.Active:
                _gameView.DisplayGameArea();

                switch (_gameboard.CurrentRoundState)
                {
                case Gameboard.GameboardState.NewRound:
                    _roundNumber++;
                    _gameboard.CurrentRoundState = _gameView.DisplayWhosOnFirst();
                    break;

                case Gameboard.GameboardState.PlayerXTurn:
                    ManagePlayerTurn(PlayerPiece.X);
                    break;

                case Gameboard.GameboardState.PlayerOTurn:
                    ManagePlayerTurn(PlayerPiece.O);
                    break;

                case Gameboard.GameboardState.PlayerXWin:
                    _playerXNumberOfWins++;
                    Scoreboard score = new Scoreboard()
                    {
                        gameTime     = DateTime.Now,
                        playerNames  = new string[] { "Player X", "Player O" },
                        playerScores = new int[] { _playerXNumberOfWins, _playerONumberOfWins }
                    };
                    _scoreboard.Add(score);
                    JsonServices.WriteJsonFile(_scoreboard, "scores.json");
                    _playingRound = false;
                    break;

                case Gameboard.GameboardState.PlayerOWin:
                    _playerONumberOfWins++;
                    score = new Scoreboard()
                    {
                        gameTime     = DateTime.Now,
                        playerNames  = new string[] { "Player X", "Player O" },
                        playerScores = new int[] { _playerXNumberOfWins, _playerONumberOfWins }
                    };
                    _scoreboard.Add(score);
                    JsonServices.WriteJsonFile(_scoreboard, "scores.json");
                    _playingRound = false;
                    break;

                case Gameboard.GameboardState.CatsGame:
                    _numberOfCatsGames++;
                    _playingRound = false;
                    break;

                default:
                    break;
                }
                break;

            case ConsoleView.ViewState.PlayerTimedOut:
                _gameView.DisplayTimedOutScreen();
                _playingRound = false;
                break;

            case ConsoleView.ViewState.PlayerUsedMaxAttempts:
                _gameView.DisplayMaxAttemptsReachedScreen();
                _playingRound = false;
                _playingGame  = false;
                break;

            default:
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// Get a player's position choice within the correct range of the array
        /// Note: The ConsoleView is allowed access to the GameboardPosition struct.
        /// </summary>
        /// <returns>GameboardPosition</returns>
        public int GetPlayerPositionChoice()
        {
            Console.CursorVisible  = false;
            Console.OutputEncoding = System.Text.Encoding.Unicode;
            ConsoleKeyInfo keyInfo;
            int            player_column = 0;

            do
            {
                Console.SetCursorPosition(_gameboard._board[0, player_column].Row, _gameboard._board[0, player_column].Column + DROP_PEICE_OFFSET);
                Console.Write(PLAYER_ICONS[(int)_gameboard.CurrentRoundState]);
                keyInfo = Console.ReadKey();
                //Console.SetCursorPosition(Console.CursorLeft -3, Console.CursorTop);
                Console.SetCursorPosition(_gameboard._board[0, player_column].Row, _gameboard._board[0, player_column].Column + DROP_PEICE_OFFSET);
                Console.Write("  ");
                switch (keyInfo.Key)
                {
                case ConsoleKey.LeftArrow:
                    if (player_column > 0)
                    {
                        player_column--;
                    }
                    break;

                case ConsoleKey.RightArrow:
                    if (player_column < _gameboard.MaxNumOfRowsColumns - 1)
                    {
                        player_column++;
                    }
                    break;

                case ConsoleKey.F1:
                    JsonServices.WriteJsonFile(_gameboard);     //debug
                    DisplayGameSavedScreen();
                    return(-1);

                case ConsoleKey.F2:
                    Gameboard _tempboard = JsonServices.ReadJsonFile() as Gameboard;
                    _gameboard._board = _tempboard._board;     //debug
                    DisplayGameLoadedScreen();
                    return(-1);

                case ConsoleKey.F3:
                    break;

                case ConsoleKey.F4:
                    break;

                case ConsoleKey.Escape:
                    return(-2);

                default:
                    break;
                }
            } while (keyInfo.Key != ConsoleKey.Enter);

            /*
             * //
             * // Initialize gameboardPosition with -1 values
             * //
             * GameboardPosition gameboardPosition = new GameboardPosition(-1, -1);
             *
             * //
             * // Get row number from player.
             * //
             * gameboardPosition.Row = PlayerCoordinateChoice("Row");
             *
             * //
             * // Get column number.
             * //
             * if (CurrentViewState != ViewState.PlayerUsedMaxAttempts)
             * {
             *  gameboardPosition.Column = PlayerCoordinateChoice("Column");
             * }*/

            return(player_column);
        }