Esempio n. 1
0
    void InitGame()
    {
        boardScript = GetComponent <BoardManager>();
        rooms       = new List <Room>();  // for new game empty rooms
        int[][]     randLvls      = LevelGenerator.Instance.GenerateLevel(difficulty);
        List <Room> possibleRooms = new List <Room>();

        for (int i = 1; i <= numOfLevels; i++)
        {
            possibleRooms.Add(ReadJSON.loadRoomWithId(i));
        }

        List <Room> possibleBossRooms = new List <Room>();

        for (int i = 1; i <= numOfBossLevels; i++)
        {
            Room b = ReadJSON.loadBossRoomWithId(i);
            b.isBoss = true;
            possibleBossRooms.Add(b);
        }

        List <Room> possibleKeyRooms = new List <Room>();

        for (int i = 1; i <= numOfKeyLevels; i++)
        {
            possibleKeyRooms.Add(ReadJSON.loadKeyRoomWithId(i));
        }

        for (int x = 0; x < randLvls.Length; x++)
        {
            for (int y = 0; y < randLvls[x].Length; y++)
            {
                RoomType type = (RoomType)randLvls[x][y];
                Room     r    = null;
                switch (type)
                {
                case RoomType.Spawn:
                    List <Room> spawnList = new List <Room>();
                    spawnList.Add(ReadJSON.loadRoomWithId(0));
                    r = findFittingRoom(randLvls, spawnList, x, y);
                    break;

                case RoomType.Normal:
                    r = findFittingRoom(randLvls, possibleRooms, x, y);
                    break;

                case RoomType.Bonus:
                    r = findFittingRoom(randLvls, possibleRooms, x, y);                             //TODO throw not implemented exception ;)
                    break;

                case RoomType.Boss:
                    r = findFittingRoom(randLvls, possibleBossRooms, x, y);
                    break;

                case RoomType.Key:
                    r = findFittingRoom(randLvls, possibleKeyRooms, x, y);
                    break;

                case RoomType.Trap:
                    r = findFittingRoom(randLvls, possibleRooms, x, y);                             //TODO throw not implemented exception ;)
                    break;
                }
                if (r != null)
                {
                    r.x       = x;
                    r.y       = y;
                    r.cleared = false;
                    rooms.Add(r);
                }
                Debug.Log(rooms);
            }
        }
        if (player == null)
        {
            player = Instantiate(playerPrefab, new Vector3(7, 7, 0f), Quaternion.identity) as GameObject;
        }

        player.GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f);       //reset color of sprite renderer
        HealthScript hs = player.GetComponent <HealthScript>();

        hs.hp = playerLives;
        addScore(0);

        hasKey = false;

        LoadLevelWithCoords(7, 7, true);
        enabled = true;
    }