public void Play(BattleshipGame battleshipGame) { var position = new (char x, int y)?(); var lastMessage = string.Empty; while (!battleshipGame.IsComplete) { _console.Clear(); _gameDrawer.Draw(battleshipGame, position); _console.WriteLine(); _console.WriteAtPositionWithForegroundColor(0, _console.CursorTop + 1, lastMessage, ConsoleColor.Yellow); position = _positionReader.ReadPosition(); var fireResult = battleshipGame.Fire(position.Value); lastMessage = _fireResultMessages[fireResult]; } _console.Clear(); _gameDrawer.Draw(battleshipGame); _console.WriteLine(); _console.WriteLine("Game Completed!"); var statistics = battleshipGame.CurrentStatistics; _console.WriteLine($"Hits: {statistics.Hits}"); _console.WriteLine($"Misses: {statistics.Misses}"); _console.WriteLine($"Accuracy: {statistics.Accuracy:P}"); _console.WriteLine(); }
public static void FireAllCells(this BattleshipGame battleship) { foreach (var cell in battleship.Cells) { battleship.Fire(cell); } }