public OutputWindow(IServiceProvider serviceProvider) : base(serviceProvider) { Output = serviceProvider.Get <IOutputManager>(); Output.Logs.CollectionChanged += OnLogsChanged; var cmd = serviceProvider.Get <ICommandProvider>(); ClearCommand = cmd.Create(() => { Output.Clear(); }); }
public void Start() { try { _log.Info("BTG - Initialization Started."); _outputManager.ShowFlashScreen(); _outputManager.ShowHeader(); _gameConfig.Player.Name = _inputManager.GetUserName(); _gameConfig.Player.IsComputer = false; _gameConfig.Computer.Name = "ZORRO"; _gameConfig.Computer.IsComputer = true; _outputManager.ShowStats(_gameConfig); _gameConfig.IsPlayerTurn = _randomManager.WhoseFirst(); _log.Info("BTG - Initialization Completed."); } catch (Exception e) { _log.Error($"BTG - Initialization Error {e}."); } do { SetBoard(); do { try { _log.Info("BTG - Game Flow Started!"); _outputManager.ShowWhoseTurn(_gameConfig.IsPlayerTurn ? _gameConfig.Player : _gameConfig.Computer); _outputManager.DrawHistory(_gameConfig.IsPlayerTurn ? _gameConfig.Computer : _gameConfig.Player); _fireShotResponse = Shot(_gameConfig.IsPlayerTurn ? _gameConfig.Computer : _gameConfig.Player, _gameConfig.IsPlayerTurn ? _gameConfig.Player : _gameConfig.Computer, out _shotPoint); _outputManager.Clear(); _outputManager.ShowHeader(); _outputManager.ShowStats(_gameConfig); _outputManager.ShowWhoseTurn(_gameConfig.IsPlayerTurn ? _gameConfig.Player : _gameConfig.Computer); _outputManager.DrawHistory(_gameConfig.IsPlayerTurn ? _gameConfig.Computer : _gameConfig.Player); _outputManager.ShowShotResult(_fireShotResponse, _shotPoint, _gameConfig.IsPlayerTurn ? _gameConfig.Player : _gameConfig.Computer); if (_fireShotResponse.ShotStatus != ShotStatus.Victory) { _outputManager.WriteLine("Press any key to continue to switch to " + (_gameConfig.IsPlayerTurn ? _gameConfig.Computer.Name : _gameConfig.Player.Name), ConsoleColor.Cyan); _gameConfig.IsPlayerTurn = !_gameConfig.IsPlayerTurn; _inputManager.Read(); _outputManager.Clear(); _outputManager.ShowHeader(); _outputManager.ShowStats(_gameConfig); } } catch (Exception e) { _log.Error($"BTG - Game flow error: {e}"); } } while (_fireShotResponse.ShotStatus != ShotStatus.Victory); } while (!_inputManager.CheckQuit()); _log.Info("BTG - Exit Game."); }