Ejemplo n.º 1
0
    public IEnumerator GenerateRandom(int floorNumber)
    {
        Stopwatch stopWatch = Stopwatch.StartNew();

        System.Random rnd = new System.Random();
        DungeonStruct dungeonStructure = new DungeonStruct(300, 150);

        yield return(null);

        dungeonStructure = SetDungeonSize(floorNumber);
        Map newMap = new Map(dungeonStructure, dungeonStructure.dungeon.Length, dungeonStructure.dungeon[0].Length, this);

        currentMap = newMap;
        mainCamera.transform.position = new Vector3(hero.transform.position.x, hero.transform.position.y, -10);
        mainCamera.GetComponent <SmoothCamera>().target = hero.gameObject.transform.GetChild(0);
        UpdateHeroHealthGUI();
        UpdateHeroGoldGUI();
        UpdateHeroKillsGUI();
        UpdateHeroItemSlots();
        PlayInMap();
        loadingScreen.GetComponent <LoadingScreen>().FadeOut();
        currentController = Controllers.player;
        stopWatch.Stop();
        debugLogManager.AddLog("World generated in: " + stopWatch.Elapsed.TotalMilliseconds.ToString() + "ms");
        yield return(null);
    }
Ejemplo n.º 2
0
 public LevelGenerator(int sizeX, int sizeY)
 {
     mapSizeX         = sizeX;
     mapSizeY         = sizeY;
     connectedRooms   = new List <Room>();
     rooms            = new List <Room>();
     rnd              = new System.Random();
     dungeonStructure = new DungeonStruct(sizeX, sizeY);
 }
	public void BindingData(DungeonStruct newData){
		if(this.dungeonData == null){
			this.dungeonData = newData;
			RegistAction();
			return;
		}
		UnRegistAction();
		this.dungeonData = newData;
		RegistAction();
	}
	//关联副本,是否通关
	public bool IsLinkedPassed(DungeonStruct linked){
		return linked.Passed;
	}
Ejemplo n.º 5
0
    //public EnemyIterator enemies;

    public Map(DungeonStruct dungeonStructure, int rowAmmount, int ColumnAmmount, TurnManager turnManager)
    {
        mapRowLimit        = rowAmmount;
        mapColumnLimit     = ColumnAmmount;
        this.tileMap       = new Tile[mapRowLimit][];
        this.charactersMap = new Character[mapRowLimit][];
        this.itemsMap      = new Item[mapRowLimit][];
        terrainCosts       = new int[mapRowLimit][];
        int rowCounter = 0;

        wallsColor = new Color(Random.Range(0.4f, 0.75f), Random.Range(0.4f, 0.75f), Random.Range(0.4f, 0.75f));
        floorColor = new Color(Random.Range(0.3f, 0.95f), Random.Range(0.3f, 0.95f), Random.Range(0.3f, 0.95f));

        foreach (int[] intRow in dungeonStructure.dungeon)
        {
            this.tileMap[rowCounter] = new Tile[mapColumnLimit];
            terrainCosts[rowCounter] = new int[mapColumnLimit];
            int columnCounter = 0;
            foreach (int integer in intRow)
            {
                this.tileMap[rowCounter][columnCounter] =
                    GameManager._instance.tileFactory.GetTile(integer, columnCounter, rowCounter, this).GetComponent <Tile>();
                if (integer < 10)
                {
                    terrainCosts[rowCounter][columnCounter] = 1;
                }
                else
                {
                    terrainCosts[rowCounter][columnCounter] = 99999;
                }
                columnCounter++;
            }
            rowCounter++;
        }
        rowCounter = 0;
        foreach (int[] intRow in dungeonStructure.characterMap)
        {
            charactersMap[rowCounter] = new Character[mapColumnLimit];
            int columnCounter = 0;
            foreach (int integer in intRow)
            {
                if (integer != 0) //zero is reserved for no characters
                {
                    charactersMap[rowCounter][columnCounter] =
                        GameManager._instance.tileFactory.GetCharacter(integer, columnCounter, rowCounter, this).GetComponent <Character>();
                    if (integer == 1)
                    {
                        turnManager.hero = charactersMap[rowCounter][columnCounter] as PlayerCharacter;
                        turnManager.hero.OnHealthChange     += turnManager.UpdateHeroHealthGUI;
                        turnManager.hero.OnHealthChangeHeal += turnManager.HeroHealEffectGUI;
                        turnManager.hero.OnHealthChangeLose += turnManager.HeroHitEffectGUI;
                        turnManager.hero.OnItemChange       += turnManager.UpdateHeroItemSlots;
                        turnManager.hero.OnIsDeathChange    += turnManager.UpdateHeroDeathGUI;
                    }
                    else
                    {
                        turnManager.enemyList.Add(charactersMap[rowCounter][columnCounter] as Enemy);
                    }
                }
                columnCounter++;
            }
            rowCounter++;
        }
        rowCounter = 0;
        foreach (int[] intRow in dungeonStructure.itemMap)
        {
            this.itemsMap[rowCounter] = new Item[mapColumnLimit];
            int columnCounter = 0;
            foreach (int integer in intRow)
            {
                if (integer != 0)//zero reserved for no items
                {
                    this.itemsMap[rowCounter][columnCounter] =
                        GameManager._instance.tileFactory.GetItem(integer, columnCounter, rowCounter, this).GetComponent <Item>();
                }
                columnCounter++;
            }
            rowCounter++;
        }
        enemyPathFindingA = new EnemyPathFindingAStar(ColumnAmmount, rowAmmount);;
    }
	void OnDestory(){
		this.dungeonData = null;
	}
	void SetDungeonData(DungeonStruct data){
		this.dungeonData = data;
	}
	public void ShowWithData(DungeonStruct data)
	{
		SetDungeonData(data);
		this.Show();
	}
	public void OpenDungeonTipUI(DungeonStruct data)
	{
		dungeonTipController.ShowWithData(data);
	}
	//先从本地加载当前副本拥有的副本,然后根据服务器数据更新章节,副本的解锁状态
	void LoadFromLocalData ()
	{
		possessDungeonDic.Clear ();
		possessDungeonDic.Add ((int)ChapterLevel.Normal, new Dictionary<int, DungeonStruct> ());
		possessDungeonDic.Add ((int)ChapterLevel.NightMare, new Dictionary<int, DungeonStruct> ());

		Dictionary<int , int> dungeonDic = baseData.GetDungeonIdDic ();
		foreach (KeyValuePair<int  , int> keyValue in dungeonDic) {
				DungeonStruct dungeonNormal = new DungeonStruct (keyValue.Value, ChapterLevel.Normal);
				DungeonStruct dungeonNightMare = new DungeonStruct (keyValue.Value, ChapterLevel.NightMare);
				possessDungeonDic [(int)ChapterLevel.Normal].Add (keyValue.Value, dungeonNormal);
				possessDungeonDic [(int)ChapterLevel.NightMare].Add (keyValue.Value, dungeonNightMare);
		}
	}
Ejemplo n.º 11
0
    public DungeonStruct CreateDungeon(int sizeX, int sizeY, int roomsAmnt)
    {
        mapSizeX         = sizeX;
        mapSizeY         = sizeY;
        rooms            = new List <Room>();
        rnd              = new System.Random();
        dungeonStructure = new DungeonStruct(sizeX, sizeY);

        CreateIfPossible(rnd.Next(4, 8), rnd.Next(4, 8), 0, rnd.Next(10, sizeX - 10), rnd.Next(10, sizeY - 10), false);
        rooms[0].isConnected = true;
        connectedRooms.Add(rooms[0]);
        int selectedRoom;

        while (rooms.Count != roomsAmnt)
        {
            selectedRoom = rnd.Next(rooms.Count);

            int dir = rnd.Next(4);

            Point nextPlace;
            nextPlace.X = rnd.Next(0, mapSizeX);
            nextPlace.Y = rnd.Next(0, mapSizeY);
            CreateIfPossible(rnd.Next(6, 12), rnd.Next(6, 12), dir, nextPlace.X, nextPlace.Y, false);
        }
        int id = 0;
        //every room connects to another room, which wasnt connected to any before

        /*
         * foreach (Room room in rooms)
         * {
         *  if (!room.isConnected)
         *  {
         *      int rand = rnd.Next(connectedRooms.Count);
         *      Room rndroom = rooms[rand];
         *      while (rndroom == room)
         *      {
         *          rand = rnd.Next(rooms.Count);
         *          rndroom = rooms[rand];
         *      }
         *      connectedRooms.Add(room);
         *      ConnectTwoRooms(room, rndroom);
         *      room.AddConnection(rand);
         *      rndroom.AddConnection(id);
         *      room.isConnected = true;
         *      rndroom.isConnected = true;
         *  }
         *  id++;
         * }
         *
         * //adding random room connections
         * int randomConnections = rnd.Next(2, 8);
         * for (int i = 0; i < randomConnections; i++)
         * {
         *  int room1 = rnd.Next(connectedRooms.Count);
         *  int room2 = rnd.Next(connectedRooms.Count);
         *  if (room1 == room2)
         *  {
         *      room2 = rnd.Next(connectedRooms.Count);
         *  }
         *  ConnectTwoRooms(connectedRooms[room1], connectedRooms[room2]);
         * }
         */

        AStarCorridors aStarCorridors = new AStarCorridors(sizeX, sizeY, dungeonStructure.dungeon, rooms);

        foreach (Room room in rooms)
        {
            if (!room.isConnected)
            {
                int  rand    = rnd.Next(connectedRooms.Count);
                Room rndroom = rooms[rand];
                while (rndroom == room)
                {
                    rand    = rnd.Next(rooms.Count);
                    rndroom = rooms[rand];
                }
                connectedRooms.Add(room);
                List <Node> path = aStarCorridors.ConnectTwoRoomsNoCollisions(dungeonStructure.dungeon, rooms, room, rndroom);
                if (!(path is null))
                {
                    foreach (Node node in path)
                    {
                        if (dungeonStructure.dungeon[node.position.Y][node.position.X] > 9)
                        {
                            dungeonStructure.dungeon[node.position.Y][node.position.X] = 0;
                        }
                    }
                    room.AddConnection(rand);
                    rndroom.AddConnection(id);
                    room.isConnected    = true;
                    rndroom.isConnected = true;
                }
                else
                {
                    Debug.Log("Path was null");
                }
            }
            id++;
        }