static void Main(string[] args) { var shipFactory = new ShipFactory(); var board = new Board(10, 10, true); // pass one more parameter bool to display ships on the grid var boardGenerator = new RandomBoardGenerator(board); var game = new Game(board); var ships = new List <Ship>(); ships.Add(shipFactory.MakeShip(ShipType.Battleship)); ships.Add(shipFactory.MakeShip(ShipType.Destroyer)); ships.Add(shipFactory.MakeShip(ShipType.Destroyer)); boardGenerator.PlaceListOfShipsOnTheGrid(ships); string fieldName; while (!game.IsGameOver(ships)) { board.PrintGrid(board.Grid); Console.Write("Please enter the coordinate to shut the ship: "); fieldName = Console.ReadLine(); var status = game.ShutShip(fieldName, ships); Console.Clear(); Console.WriteLine($"You: {status} the ship"); } Console.Clear(); Console.WriteLine("Game over"); board.PrintGrid(board.Grid); Console.ReadKey(); }
public void GeneratorAvoidsPlacingMatchDuringGenerating() { // given var gameConfig = Substitute.For <IGameConfig>(); gameConfig.RowsCount.Returns(3); gameConfig.ColumnsCount.Returns(3); var pool = new BlockData[] { new BlockData(0), new BlockData(1), new BlockData(2) }; gameConfig.BlockDataPool.Returns(pool); var randomDevice = Substitute.For <IBlockDataProvider>(); randomDevice.GetBlockDataFromPool(Arg.Any <List <BlockData> >()).Returns(x => { // pick first option from pool var blockPool = (List <BlockData>)x[0]; return(blockPool[0]); }); var sut = new RandomBoardGenerator(randomDevice, gameConfig); // when: var generatedBoard = sut.CreateBoard(); // then: // 0 0 1 // 0 0 1 // 1 1 0 Assert.AreEqual(0, generatedBoard[0, 0].Type); Assert.AreEqual(0, generatedBoard[0, 1].Type); Assert.AreEqual(1, generatedBoard[0, 2].Type); Assert.AreEqual(0, generatedBoard[1, 0].Type); Assert.AreEqual(0, generatedBoard[1, 1].Type); Assert.AreEqual(1, generatedBoard[1, 2].Type); Assert.AreEqual(1, generatedBoard[2, 0].Type); Assert.AreEqual(1, generatedBoard[2, 1].Type); Assert.AreEqual(0, generatedBoard[2, 2].Type); }
public SolverPerformanceChecker() { randomBoardGenerator = new RandomBoardGenerator(); pathLengthCalculator = new PathLengthCalculator(); }