/// <summary> /// Prints the playing field on each turn. /// </summary> /// <param name="playingField">Current playing field.</param> /// <param name="gamestatus">Status of the game, currently being played.</param> internal void PrintPlayingField(PlayingField playingField, GameStatus gamestatus) { MenuPrinter menuPrinter = new MenuPrinter(); menuPrinter.ConsoleSetUp(); menuPrinter.PrintBackground(); int rows = playingField.Field.GetLength(0); int columns = playingField.Field.GetLength(1); string formatString = new string(' ', (Console.WindowWidth - (columns + (columns * 2))) / 2); this.sb.AppendLine(); this.sb.Append(formatString); for (int i = 0; i < columns; i++) { this.sb.Append(string.Format("{0}", i).PadLeft(2, ' ') + " "); } this.sb.AppendLine(); this.PrintLine(columns); for (int i = 0; i < rows; i++) { this.sb.Append(new string(' ', ((Console.WindowWidth - (columns + (columns * 2))) / 2) - 4)); this.sb.Append(string.Format("{0}", i).PadLeft(2, ' ')); this.sb.Append(" | "); for (int j = 0; j < columns; j++) { Cell currentField = playingField.Field[i, j]; if (gamestatus == GameStatus.GameOn) { if (currentField.Status == CellStatus.Opened) { this.sb.Append(playingField.Field[i, j].Value); this.sb.Append(" "); } else if (currentField.Status == CellStatus.Flagged) { this.sb.Append(Flag); } else { this.sb.Append(CellClosed); } } else if (gamestatus == GameStatus.GameOver) { if (currentField.IsMine) { this.sb.Append(MineOpened); } else { this.sb.Append(playingField.Field[i, j].Value + " "); } } else { if (currentField.IsMine == true || currentField.Status == CellStatus.Flagged) { this.sb.Append(Flag); } else { this.sb.Append(playingField.Field[i, j].Value + " "); } } } this.sb.Append("|"); this.sb.AppendLine(); } this.PrintLine(columns); Console.WriteLine(this.sb.ToString()); this.sb.Clear(); }
/// <summary> /// Helper method that initializes game resources - prints the menu and prepares the playing field. /// </summary> private void PrepareGameResources() { MenuPrinter menuPrinter = new MenuPrinter(); this.SelectLevel(menuPrinter.GameLevelSelector()); this.GameBoard = new PlayingField(this.numberOfRows, this.numberOfCols, this.NumberOfMines); menuPrinter.ConsoleSetUp(); menuPrinter.PrintBackground(); }