예제 #1
0
        public void GenerateMap()
        {
            TileGenerator tileGenerator = new TileGenerator(WaterPrefab, GrassPrefab, DesertPrefab, MountainPrefab, ForestPrefab);

            Transform[,] tileTransforms = tileGenerator.GenerateTiles();
            tiles = new Tile[tileTransforms.GetLength(0), tileTransforms.GetLength(1)];

            // destroy/create container object
            Transform mapHolder = RestoreMapholder();

            // create the tiles
            for (int x = 0; x < Constants.MapSettings.MapSize.X; x++)
            {
                for (int y = 0; y < Constants.MapSettings.MapSize.Y; y++)
                {
                    Vector3   tilePosition = TileUtil.CoordToPosition(x, y);
                    Transform newTile      = Instantiate(tileTransforms[x, y], tilePosition, Quaternion.Euler(Vector3.right * 90)) as Transform;
                    newTile.localScale = Vector3.one * Constants.MapSettings.TileSize;
                    newTile.Rotate(Vector3.back * GenerateDegree());
                    newTile.parent = mapHolder;
                    newTile.name   = "X:" + x + " Y:" + y + " " + newTile.tag;

                    // store created tile for later access
                    tiles[x, y] = newTile.GetComponent <Tile>();

                    // set properties of tile
                    tiles[x, y].Type     = GetType(tileTransforms[x, y]);
                    tiles[x, y].Position = new Coord(x, y);
                }
            }
        }
예제 #2
0
 private void ExecuteTest(MapSettings[] settings, int[][] tilesExpected)
 {
     for (int index = 0; index < settings.Length; index++)
     {
         Constants.MapSettings = settings[index];
         TileGenerator generator = new TileGenerator(waterPrefab, grassPrefab, desertPrefab, mountainPrefab, forestPrefab);
         Transform[,] tiles = generator.GenerateTiles();
         Validate(tiles, tilesExpected[index]);
     }
 }
예제 #3
0
        public void GenerateRandomMap()
        {
            Constants.MapSettings = CreateSettings(10, 10, 1, 1, 0, 0, 0);
            TileGenerator generator = new TileGenerator(waterPrefab, grassPrefab, desertPrefab, mountainPrefab, forestPrefab);

            Transform[,] tiles = generator.GenerateTiles();

            // if shuffeling doesn't work, the first 50 tiles would be water
            bool isGrass = false;
            int  halfMap = 5;

            for (int x = 0; x < halfMap; x++)
            {
                for (int y = 0; y < halfMap; y++)
                {
                    isGrass |= tiles[x, y].tag.Equals("GrassTile");
                }
            }

            Assert.IsTrue(isGrass);
        }