public void NotBuildField_WhenThereAreTooManyShips() { shipsCount = new Dictionary <ShipType, int> { { ShipType.Submarine, 1 }, { ShipType.Destroyer, 2 } }; rules = new GameRules(fieldSize, shipsCount); builder = new GameFieldBuilder(rules); var cells = new[] { new CellPosition(0, 0), new CellPosition(7, 2), new CellPosition(9, 7), new CellPosition(6, 4), new CellPosition(6, 5), new CellPosition(2, 1), new CellPosition(2, 2) }; foreach (var cell in cells) { builder.TryAddShipCell(cell); } foreach (var shipType in Enum.GetValues(typeof(ShipType)).Cast <ShipType>()) { shipsCount[shipType] = 0; } builder.Build().Should().BeNull(); }
public void BuildField_WhenDataCorrect() { shipsCount = new Dictionary <ShipType, int> { { ShipType.Submarine, 3 }, { ShipType.Destroyer, 2 } }; rules = new GameRules(fieldSize, shipsCount); builder = new GameFieldBuilder(rules); var cells = new[] { new CellPosition(0, 0), new CellPosition(7, 2), new CellPosition(9, 7), new CellPosition(6, 4), new CellPosition(6, 5), new CellPosition(2, 1), new CellPosition(2, 2) }; foreach (var cell in cells) { builder.TryAddShipCell(cell); } builder.Build().Should().NotBeNull(); }
private static IGameField FromLines(GameRules rules, string[] lines) { var builder = new GameFieldBuilder(rules); for (var row = 0; row < rules.FieldSize.Height; row++) { for (var column = 0; column < rules.FieldSize.Width; column++) { if (lines[row][column] == 'X') { builder.TryAddShipCell(new CellPosition(row, column)); } } } return(builder.Build()); }
public void BuildCorrectField() { shipsCount = new Dictionary <ShipType, int> { { ShipType.Submarine, 3 }, { ShipType.Destroyer, 2 } }; rules = new GameRules(fieldSize, shipsCount); builder = new GameFieldBuilder(rules); var cells = new[] { new CellPosition(0, 0), new CellPosition(7, 2), new CellPosition(9, 7), new CellPosition(6, 4), new CellPosition(6, 5), new CellPosition(2, 1), new CellPosition(2, 2) }; foreach (var cell in cells) { builder.TryAddShipCell(cell); } foreach (var shipType in Enum.GetValues(typeof(ShipType)).Cast <ShipType>()) { shipsCount[shipType] = 0; } var field = builder.Build(); foreach (var cell in field.EnumeratePositions()) { cells.Contains(cell).Should().Be(field[cell] is IShipCell); } }