Exemplo n.º 1
0
        public void TestSimpleMapGeneratorSeed()
        {
            IMapGenerator simpleMapGenerator = MapGeneratorFactory.CreateSimpleMapGenerator();
            int           w    = 5;
            int           h    = 10;
            int           seed = 87452;

            Direction[] allDirections = DirectionMethods.GetAllDirections();

            MapBlock[,] grid  = simpleMapGenerator.GenerateGrid(w, h, seed);
            MapBlock[,] grid2 = simpleMapGenerator.GenerateGrid(w, h, seed);

            Assert.IsNotNull(grid, "Grid 1 is null!");
            Assert.IsNotNull(grid2, "Grid 2 is null!");
            Assert.AreEqual(w, grid.GetLength(0), "Wrong width of map grid!");
            Assert.AreEqual(h, grid.GetLength(1), "Wrong height of map grid!");
            Assert.AreEqual(w, grid2.GetLength(0), "Wrong width of map grid 2!");
            Assert.AreEqual(h, grid2.GetLength(1), "Wrong height of map grid 2!");

            // all map block should be same
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    int entrances = 0;
                    foreach (Direction dir in allDirections)
                    {
                        Assert.AreEqual(grid[i, j].EntranceInDirection(dir).Exists(), grid2[i, j].EntranceInDirection(dir).Exists(), $"Map block at position [{i},{j}] has different entrance in direction {dir}.");
                        if (grid[i, j].EntranceInDirection(dir).Exists())
                        {
                            entrances++;
                        }
                    }

                    Assert.IsTrue(entrances > 0, $"Block at [{i},{j}] has no entrance!");
                }
            }
        }
Exemplo n.º 2
0
        public void TestOpenMapGenerator()
        {
            IMapGenerator openMapGenerator = MapGeneratorFactory.CreateOpenMapGenerator();
            int           w = 10;
            int           h = 15;

            Direction[] allDirections = DirectionMethods.GetAllDirections();

            MapBlock[,] grid = openMapGenerator.GenerateGrid(w, h, 0);
            Assert.IsNotNull(grid, "Null grid returned!");
            Assert.AreEqual(w, grid.GetLength(0), "Wrong width of map grid!");
            Assert.AreEqual(h, grid.GetLength(1), "Wrong height of map grid!");
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    foreach (Direction dir in allDirections)
                    {
                        Assert.IsTrue(grid[i, j].EntranceInDirection(dir).IsOpen(), $"Entrance in direction {dir} of block [{i},{j}] should be open!");
                    }
                }
            }

            Map map = openMapGenerator.GenerateMap(w, h, 0);

            Assert.IsNotNull(map, "Null map returned!");
            Assert.AreEqual(w, map.Width, "Wrong map width!");
            Assert.AreEqual(h, map.Height, "Wrong map height!");
            MapBlock[,] grid2 = map.Grid;
            Assert.AreEqual(grid.GetLength(0), grid.GetLength(0), "Widths of grids don't match!");
            Assert.AreEqual(grid.GetLength(1), grid.GetLength(1), "Widths of grids don't match!");
            Assert.IsNotNull(map.WinningBlock, "Winning block is null!");
            Assert.AreEqual((w - 1) / 2, map.WinningBlock.X, "Wrong X coordinate of winning block.");
            Assert.AreEqual((h - 1) / 2, map.WinningBlock.Y, "Wrong Y coordinate of winning block.");

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    foreach (Direction dir in allDirections)
                    {
                        Assert.IsTrue(grid2[i, j].EntranceInDirection(dir).IsOpen(), $"Entrance in direction {dir} of block [{i},{j}] should be open!");
                    }
                }
            }
        }