public void Start() { this.inputhandler = new InputHandler(); this.gamehandler = new GameboardHandler(); this.consoleSizeWatcher.Start(); this.consoleSizeWatcher.OnSizeChanged += this.RenewInput; this.keyBoardWatcher.Start(); this.keyBoardWatcher.OnKeyPressed += this.UseKeyForInput; inputhandler.Accept(renderer); this.inputFinisherThread = new Thread(this.RunGame); this.inputFinisherThread.Start(); while (true) { if (this.QuitGame) { break; } } }
public void Visit(GameboardHandler handler) { if (handler.IsGameFinished) { for (int i = 0; i < gameboardheight; i++) { for (int j = 0; j < gameboardwidth; j++) { Console.SetCursorPosition(j * 4 + 6, i * 2 + 1); Field examinedField = handler.Gameboard.GetFieldAtPosition(new Position(j, i)); if (examinedField.HasMine) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Red; Console.Write(" X "); } } } } else { if (handler.IsCheatModeOn) { for (int i = 0; i < gameboardheight; i++) { for (int j = 0; j < gameboardwidth; j++) { Console.SetCursorPosition(j * 4 + 6, i * 2 + 1); Field examinedField = handler.Gameboard.GetFieldAtPosition(new Position(j, i)); if (examinedField.HasMine) { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.Write(" X "); } else { if (examinedField.Minenumber > 0) { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.Write(" " + examinedField.Minenumber + " "); } else { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.Write(" "); } } } } Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; } else { for (int i = 0; i < gameboardheight; i++) { for (int j = 0; j < gameboardwidth; j++) { Field examinedField = handler.Gameboard.GetFieldAtPosition(new Position(j, i)); Console.SetCursorPosition(j * 4 + 6, i * 2 + 1); if (examinedField.HasFlag) { Console.ForegroundColor = ConsoleColor.Red; Console.Write(" X "); Console.ForegroundColor = ConsoleColor.White; } else if (examinedField.ShowNumber) { if (examinedField.HasMine) { return; } Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.SetCursorPosition(j * 4 + 6, i * 2 + 1); if (examinedField.Minenumber > 0) { Console.Write(" " + examinedField.Minenumber + " "); } else { Console.Write(" "); } Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; } else { Console.Write(" "); } } } Console.ForegroundColor = ConsoleColor.White; this.DrawField(handler.Cursor.Position.Left, handler.Cursor.Position.Top); } } }