/// <summary> /// Method that start the main logic of the game. /// </summary> /// <param name="output">Output renderer</param> /// <param name="input">Iput provider</param> /// <param name="cmmandLogger">Command logger</param> public static void Start(IRenderer output, IInputProvider input, ILogger cmmandLogger) { output.ShowInfoMessage("Please ente your name: "); string playerName = input.GetPlayerName(); output.ShowInfoMessage("Please enter a dimension for the board the standard is 9x9"); int dimension = input.GetPlayFieldDimensions(); ICell playerCell = new Cell(new Position(dimension / 2, dimension / 2)); IPlayField playField = null; var player = new Player.Player(playerName, playerCell); try { var playFieldGenerator = new StandardPlayFieldGenerator(player.CurentCell.Position, dimension, dimension); playField = new PlayField.PlayField(playFieldGenerator, player.CurentCell.Position, dimension, dimension); } catch (ArgumentOutOfRangeException e) { output.ShowInfoMessage(e.Message); } ICommandFactory commandFactory = new SimpleCommandFactory(); IMementoCaretaker memory = new MementoCaretaker(new List <IMemento>()); IScoreLadder ladder = ScoreLadder.Instance; IGameEngine gameEngine = new StandardGameEngine(output, input, playField, commandFactory, cmmandLogger, player, memory, ladder); gameEngine.Initialize(RandomNumberGenerator.Instance); gameEngine.Start(); }
/// <summary> /// Constructor with 5 parameters /// </summary> /// <param name="playField">Parameter of type IPlayField </param> /// <param name="output">Parameter of type IRenderer</param> /// <param name="memory">Parameter of type IMementoCaretaker</param> /// <param name="ladder">Parameter of type IScoreLadder</param> /// <param name="player">Parameter of type IPlayer</param> public CommandContext(IPlayField playField, IRenderer output, IMementoCaretaker memory, IScoreLadder ladder, IPlayer player) { this.PlayField = playField; this.Output = output; this.Memory = memory; this.Ladder = ladder; this.Player = player; }
public Engine(byte rowsAmmount, byte colsAmmount) { field = new PlayField(rowsAmmount, colsAmmount); scoreBoard = new ScoreBoard(); player = new Player(); communicator = new ConsoleCommunicator(); parser = new CommandParser(); }
public GameController(IPlayField playField, IGameRule gameRule) { if (playField == null) throw new ArgumentNullException("playField"); if (gameRule == null) throw new ArgumentNullException("gameRule"); _playField = playField; _gameRule = gameRule; }
public void ShowPlayField(IPlayField playField) { for (int row = 0; row < playField.NumberOfRows; row++) { for (int col = 0; col < playField.NumberOfCols; col++) { ICell cell = playField.GetCell(new Position(row, col)); Console.Write(cell.ValueChar + " "); } Console.WriteLine(); } }
/// <summary> /// Method that checks if commandInput given by the user represents a balloon in the /// field which is poppable(different than zero) /// </summary> /// <param name="commandInput">String containing the command from user. /// If it is not a coordinate, the first letter is capital, the rest are lower case.</param> /// <param name="field">Parameter of type PlayField, representing the playfield of the game</param> /// <returns>Returns true if the balloon is poppable(different than zero and false if not)</returns> public bool CheckPoppableBalloon(string commandInput, IPlayField field) { int row = ParseCommandToRow(commandInput); int col = ParseCommandToCol(commandInput); if (field[row, col] == 0) { return false; } else { return true; } }
public void Render(IPlayField playField) { var output = new StringBuilder(); for (int row = 0; row < playField.Rows; row++) for (int column = 0; column < playField.Columns; column++) { output.Append(playField.GetCell(row, column).IsAlive ? "#" : " "); if (column == playField.Columns - 1) output.Append(Environment.NewLine); } Console.Write(output.ToString()); }
private void Awake() { _livesSystem = new LivesSystem(); _scoreSystem = new ScoreSystem(); _matchSystem = new MatchSystem(_livesSystem, _scoreSystem); _playField = GetComponent <IPlayField>(); _saveManager = GetComponent <ISaveManager>(); _inputSystem = GetComponent <IInputSystem>(); _roundUiManager = GetComponent <IRoundUiManager>(); _gameSceneManager = GetComponent <IGameSceneManager>(); _lightAndCameraSystem = GetComponent <ILightAndCameraSystem>(); _cardMeshes = GetComponent <CardReferences>().GetCardObjects(); StartCoroutine(InitializeRound()); }
/// <summary> /// Method used to parse command from string to Command Type /// </summary> /// <param name="commandInput">String containing the command from user. /// If it is not a coordinate, the first letter is capital, the rest are lower case.</param> /// <param name="field">Parameter of type PlayField, representing the playfield of the game</param> /// <returns>Returns the parsed command- a Command Type parameter.</returns> public Command ParseCommand(string commandInput, IPlayField field) { bool isValidCoordinate = CheckIfCommandIsCoordinate(commandInput, field); if (isValidCoordinate && CheckPoppableBalloon(commandInput, field)) { return Command.CoordinateForParsing; } else if (CheckIfValidCommand(commandInput)) { return (Command)Enum.Parse(typeof(Command), commandInput); } else { return Command.Invalid; } }
/// <summary> /// Prints the field and game instructions to the console. /// </summary> /// <param name="field">The field that will be printed</param> public void RenderGameField(IPlayField field) { Console.Clear(); Console.WriteLine("Welcome to “Balloons Pops” game. " + "Please try to pop the balloons. \nUse 'top' to view the top scoreboard,\n" + "'restart' to start a new game and 'exit' to quit the game. \n"); Console.Write(" "); for (byte column = 0; column < field.GetLength(1); column++) { Console.Write(column + " "); } Console.Write("\n "); for (byte column = 0; column < field.GetLength(1) * 2 + 1; column++) { Console.Write("-"); } Console.WriteLine(); for (byte row = 0; row < field.GetLength(0); row++) { Console.Write(row + " | "); for (byte col = 0; col < field.GetLength(1); col++) { if (field[row, col] == 0) { Console.Write(" "); continue; } Console.Write(field[row, col] + " "); } Console.Write("| "); Console.WriteLine(); } Console.Write(" "); for (byte column = 0; column < field.GetLength(1) * 2 + 1; column++) { Console.Write("-"); } Console.WriteLine(); }
/// <summary> /// Standard game engine constructor. /// </summary> /// <param name="renderer">Output renderer.</param> /// <param name="inputProvider">Input provider.</param> /// <param name="playField">Game play field.</param> /// <param name="commandFactory">Game command factory.</param> /// <param name="logger">Command execution logger.</param> /// <param name="player">Player</param> public StandardGameEngine( IRenderer renderer, IInputProvider inputProvider, IPlayField playField, ICommandFactory commandFactory, ILogger logger, IPlayer player, IMementoCaretaker memory, IScoreLadder ladder) { this.playField = playField; this.renderer = renderer; this.input = inputProvider; this.ladder = ladder; this.commandFactory = commandFactory; this.logger = logger; this.player = player; this.memory = memory; }
public void ClassInitialize() { playerPosition = new Position(3, 3); generator = new StandardPlayFieldGenerator(playerPosition, 9, 9); playField = new PlayField(generator, playerPosition, 9, 9); IInfoRenderer infoPanel = new InfoPanel(); IPlayFieldRenderer playFieldPanel = new PlayFieldPanel(); ILadderRenderer topScoresPanel = new TopScoresPanel(); output = new ConsoleRender(infoPanel, playFieldPanel, topScoresPanel); memory = new MementoCaretaker(new List<IMemento>()); ladder = ScoreLadder.Instance; player = new Player("test", new Cell(playerPosition)); context = new CommandContext(playField, output, memory, ladder, player); }
/// <summary> /// Method that checks if a given command represents a valid coordinate in the game field /// </summary> /// <param name="commandInput">String containing the command from user. /// If it is not a coordinate, the first letter is capital, the rest are lower case.</param> /// <param name="field">Parameter of type PlayField, representing the playfield of the game</param> /// <returns>Returns true if command is a valid coordinate and false, if it is not</returns> public bool CheckIfCommandIsCoordinate(string commandInput, IPlayField field) { string[] commandWords = commandInput.Split(new Char[]{' ', ',', '_', '.'}, StringSplitOptions.RemoveEmptyEntries); if (commandWords.Length == 2) { byte row = 0; byte col = 0; bool areCoordinates = byte.TryParse(commandWords[0], out row) && byte.TryParse(commandWords[1], out col); if (areCoordinates) { if (0 <= row && row < field.GetLength(0) && 0 <= col && col < field.GetLength(1)) { return true; } } } return false; }
public void ClassInitialize() { playerPosition = new Position(3, 3); generator = new StandardPlayFieldGenerator(playerPosition, 9, 9); playField = new PlayField(generator, playerPosition, 9, 9); IInfoRenderer infoPanel = new InfoPanel(); IPlayFieldRenderer playFieldPanel = new PlayFieldPanel(); ILadderRenderer topScoresPanel = new TopScoresPanel(); output = new ConsoleRender(infoPanel, playFieldPanel, topScoresPanel); memory = new MementoCaretaker(new List <IMemento>()); ladder = ScoreLadder.Instance; player = new Player("test", new Cell(playerPosition)); context = new CommandContext(playField, output, memory, ladder, player); }
public bool CheckIfCommandIsCoordinate(string commandInput, IPlayField field) { string[] commandWords = commandInput.Split(' '); if (commandWords.Length == 2) { byte row = 0; byte col = 0; bool areCoordinates = byte.TryParse(commandWords[0], out row) && byte.TryParse(commandWords[1], out col); if (areCoordinates) { if (0 <= row && row < field.GetLength(0) && 0 <= col && col < field.GetLength(1)) { return true; } else return false; } else { return false; } } return false; }
private void HandleCommand(Command commandInput, string commandInputString) { switch (commandInput) { case Command.Restart: this.currentAction = CurrentAction.Restarting; field = new PlayField(5, 10); player = new Player(); communicator.RenderGameField(field); break; case Command.Top: this.currentAction = CurrentAction.PrintingTopBoard; communicator.RenderWinnerBoard(scoreBoard); break; case Command.Exit: this.currentAction = CurrentAction.IsNotRunning; communicator.PrintUserMessage("Good Bye! "); System.Threading.Thread.Sleep(500); break; case Command.CoordinateForParsing: this.currentAction = CurrentAction.CheckingCoordinates; int userInputRow = parser.ParseCommandToRow(commandInputString); int userInputColumn = parser.ParseCommandToCol(commandInputString); field.MakeChangesToField(userInputRow, userInputColumn); player.UpdateMovesAmmount(); if (field.ClearedLevel()) //if field is empty { FinalizeGame(); this.currentAction = CurrentAction.FinishedGame; } communicator.RenderGameField(field); break; case Command.Invalid: this.currentAction = CurrentAction.IsWaitingForValidInput; if (parser.CheckIfCommandIsCoordinate(commandInputString, field) && !parser.CheckPoppableBalloon(commandInputString, field)) { communicator.PrintUserMessage("Illegal move: cannot pop missing ballon!\n"); } else { communicator.PrintUserMessage("Wrong input ! Try Again !\n"); } break; } }
private void FinalizeGame() { communicator.PrintUserMessage(string.Format("Gratz ! You completed the level in {0} moves.\n", player.Moves)); if (scoreBoard.AddSkillfulPlayerToBoard(player, communicator)) { scoreBoard.SortWinnerBoard(); communicator.RenderWinnerBoard(scoreBoard); System.Threading.Thread.Sleep(3000); } else { communicator.PrintUserMessage("I am sorry you are not skillful enough for TopFive chart!"); System.Threading.Thread.Sleep(3000); } field = new PlayField(5, 10); player = new Player(); }
public void ShowPlayField(IPlayField playField) { this.playFieldPanel.ShowPlayField(playField); }