public Maze(int mazeId) { id = mazeId; MazeConfig = ConfigData.GetMazeConfig(mazeId); items = new List <MazeItem>(); foreach (int mazeItemId in MazeBook.GetMazeItemIds(mazeId)) { items.Add(new MazeItem(mazeItemId, MazeConfig.Level)); } }
public Maze(int mazeId) { id = mazeId; MazeConfig = ConfigData.GetMazeConfig(mazeId); items = new List<MazeItem>(); foreach (int mazeItemId in MazeBook.GetMazeItemIds(mazeId)) { items.Add(new MazeItem(mazeItemId, MazeConfig.Level)); } }
private void Populate() { var mazeConfig = new MazeConfig { ConnectLeft = false, StraightPassageways = false, ConnectCenter = true }; var maze = MazeBuilder.Generate(map.Width, map.Height, mazeConfig); foreach (var cell in map.Cells) { switch (maze.Map[cell.X, cell.Y]) { case MazeBuilder.CellType.Wall: cell.CellType = CellType.Wall; break; case MazeBuilder.CellType.Door: cell.CellType = CellType.Door; // cell.Item = new Item("Door", "D", ConsoleColor.Magenta); break; case MazeBuilder.CellType.StairsUp: cell.CellType = CellType.StairsAscending; break; case MazeBuilder.CellType.StairsDown: cell.CellType = CellType.StairsDescending; break; case MazeBuilder.CellType.Open: cell.CellType = CellType.Open; break; } } var distributionOfMonsters = new Distribution <Monster> { { 2, MonsterFactory.Goblin }, { 1, MonsterFactory.Troll }, }; var distributionOfItems = new Distribution <Item> { { 20, ItemFactory.Coin }, { 20, ItemFactory.Coins }, { 10, () => new HealthPotion(R.Dice(4) * 20) }, { 05, () => new TeleportPotion(map) }, { 02, ItemFactory.Dagger }, { 01, ItemFactory.Sword }, }; var cells = map.Cells.Where(c => !c.Obstructing); Queue <Item> items = null; foreach (var cell in cells) { if (items == null || items.Count <= 0) { items = distributionOfItems.RandomQueue(); } if (R.Chance(.02) && cell.Monster == null) { cell.Monster = distributionOfMonsters.PickRandom(); } if (R.Chance(.02) && cell.Item == null) { cell.Item = /*distributionOfItems.PickRandom();*/ items.Dequeue(); } } }
public void InstantiateLevel(int levelIndex, ILevel level, MazeConfig config) { RemoveChildren(); ResetLevelData(); float height = config.TileHeight; float width = config.TileWidth; float verticalDirection = config.VerticalDirection; for (int row = 0; row < config.NumRows; row++) { for (int col = 0; col < config.NumColumns; col++) { TileType tileType = (TileType)level.Data[row, col]; GameObject newTile = null; Vector3 newPosition = new Vector3((float)col * width, (float)row * height * verticalDirection, 0f); switch (tileType) { case TileType.PathWithDot: newTile = Instantiate(pillTile, newPosition, Quaternion.identity) as GameObject; Pills++; break; case TileType.PathWithoutDot: newTile = Instantiate(BackgroundTile, newPosition, Quaternion.identity) as GameObject; break; case TileType.BlueWall: newTile = Instantiate(obstacleTiles[obstacleTilesRandom.Next(0, obstacleTiles.Length)], newPosition, Quaternion.identity) as GameObject; break; case TileType.GrayWall: newTile = Instantiate(outerWallTiles[outerWallRandom.Next(0, outerWallTiles.Length - 1)], newPosition, Quaternion.identity) as GameObject; break; case TileType.PlayerStart: newTile = Instantiate(BackgroundTile, newPosition, Quaternion.identity) as GameObject; newTile.transform.SetParent(boardTransform, false); newTile = player; newTile.transform.SetParent(null); playerStartingPosition = newPosition; newTile.transform.position = playerStartingPosition; break; case TileType.PathWithIcon: newTile = Instantiate(prizePrefab, newPosition, Quaternion.identity) as GameObject; Prizes++; break; case TileType.EnemyStart: newTile = Instantiate(BackgroundTile, newPosition, Quaternion.identity) as GameObject; newTile.transform.SetParent(boardTransform, false); newTile = enemy; newTile.transform.SetParent(null); enemyStartingPosition = newPosition; newTile.transform.position = enemyStartingPosition; break; default: System.Diagnostics.Debug.Assert(false, "Invalid tile type"); break; } if (newTile != null) { newTile.transform.SetParent(boardTransform, false); } } } config.Data = level.Data; GameState.Instance.InitLevel(levelIndex, Pills, Prizes, config); BroadcastMessage("LevelReset"); }