/// <summary> /// Initialize the multi-round game. /// </summary> public void InitializeGame() { // // Initialize game variables // _playingGame = true; _playingRound = true; _roundNumber = 0; _playerONumberOfWins = 0; _playerXNumberOfWins = 0; _numberOfCatsGames = 0; if (File.Exists("Data\\scores.json")) { _scoreboard = JsonServices.ReadJsonFile("scores.json") as List <Scoreboard>; } }
public GameController() { InitializeGame(); _gameView.DisplayWelcomeScreen(); while (!_sendBack) { _usersChoice = _gameView.DisplayMainMenuScreen(); switch (_usersChoice) { case 0: //Play if (_playingGame) { _gameboard.InitializeGameboard(); _gameView.InitializeView(); _playingRound = true; } _roundNumber++; _gameboard.CurrentRoundState = _gameView.DisplayWhosOnFirst(); PlayGame(); break; case 1: //Rules _gameView.DisplayGameRules(); _sendBack = false; break; case 2: //Gamestats _gameView.DisplayCurrentGameStatus(_roundNumber, _playerXNumberOfWins, _playerONumberOfWins, _numberOfCatsGames); _sendBack = false; break; case 3: //Historic Scores if (File.Exists("Data\\scores.json")) { _scoreboard = JsonServices.ReadJsonFile("scores.json") as List <Scoreboard>; _gameView.DisplayPreviousGameStats(_scoreboard); } else { _gameView.DisplayNoGameStats(); } _sendBack = false; break; case 4: //Save _gameView.DisplaySaveGameScreen(); _sendBack = false; break; case 5: //Close _gameView.DisplayClosingScreen(); _sendBack = true; break; default: break; } } }
/// <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); }