public void Render(IBattleshipGrid battleshipGrid) { _textWindow.Clear(); _gridWindow.Clear(); DrawGrid(battleshipGrid); _writer?.Flush(); }
private void DrawGrid(IBattleshipGrid grid) { var size = grid.Size; var shipCells = grid.Ships.SelectMany(t => t.Cells); var line = new Draw(_gridWindow); DrawHeaders(size); const int cellWidth = 4, cellHeight = 2; const int startingX = 3, startingY = 1; int x = startingX, y = startingY; for (int row = 1; row <= size; ++row) { for (int column = 1; column <= size; ++column) { var color = Colors.WhiteOnBlack; var cell = new GridCell(column, row); var shipHit = shipCells.Any(t => t.Equals(cell) && t.Hit); if (shipHit || grid.MissedShots.Contains(cell)) { color = Colors.BlackOnWhite; } line.Box(x, y, x + cellWidth, y + cellHeight, string.Empty, color, Colors.BlackOnWhite); if (shipHit) { var ship = grid.Ships.Single(t => t.Cells.Contains(cell)); var hitColor = ship.HasSink ? ConsoleColor.Gray : ConsoleColor.Red; _gridWindow.PrintAtColor(color.Foreground, x + 2, y + 1, "X", hitColor); } x += cellWidth + 1; } y += cellHeight + 1; x = startingX; } }
public void Setup() { _battleship = Freeze <IBattleshipGrid>(); _ui = Freeze <IGameUi>(); }
public Game(IBattleshipGrid battleshipGrid, IGameUi ui) { _battleshipGrid = battleshipGrid; _ui = ui; }