예제 #1
0
        protected override void Initialize()
        {
            // Sample texture, 1x1 pixel for testing.
            simpleTexture = new Texture2D(GraphicsDevice, 1, 1);
            simpleTexture.SetData(new[] { Color.White });

            // Initializes the accelerometer.
            initializeAccelerometer();

            // Databases
            tileDatabase = new TileDatabase();
            roomDatabase = new RoomDatabase();

            // Handlers
            songHandler      = new SongHandler();
            inventoryHandler = new InventoryHandler();
            eventHandler     = new EventHandler();
            locationHandler  = new LocationHandler();

            // Objects
            mapDefinition   = new Map();
            sadakoReference = new Sadako();
            playerReference = new Player();

            // M! game profiler for FPS and other related stuff
#if DEBUG
            Components.Add(new GameProfiler(this, Content));
#endif

            base.Initialize();
        }
예제 #2
0
 private void Start()
 {
     //TODO: This shouldn't be neccesary once I've got the cartridge loader scene up and running
     //Will check that all data exists before even entering the game scene
     //Load all Data, Make sure none are missing
     if (!WorldDatabase.LoadWorldData())
     {
         Debug.LogWarning("World Data is Missing!");
     }
     else if (!LevelDatabase.LoadLevelData())
     {
         Debug.LogWarning("Level Data is Missing!");
     }
     else if (!RoomDatabase.LoadRoomData())
     {
         Debug.LogWarning("Room Data is Missing!");
     }
     else if (!InteractableDatabase.LoadInteractableData())
     {
         Debug.LogWarning("Interaction Data is Missing!");
     }
     else if (!ObstacleDatabase.LoadObstacleData())
     {
         Debug.LogWarning("Obstacle Data is Missing!");
     }
     else if (!ItemDatabase.LoadItemData())
     {
         Debug.LogWarning("Item Data is Missing!");
     }
     else
     {
         WorldManagerInst.EnterWorld();
         UIController.Instance.EnableUI();
     }
 }
예제 #3
0
    public static Map GenerateHubMap(MapData data)
    {
        Debug.Log("Rooms Size: " + data.roomSizeX + ", " + data.roomSizeY);

        RoomData roomData = RoomDatabase.GetWorldHub(data.type);

        data.roomSizeX = roomData.mWidth;
        data.roomSizeY = roomData.mHeight;

        Debug.Log("Rooms Size: " + data.roomSizeX + ", " + data.roomSizeY);
        Map map = new Map(data);



        map.SetTileMap(roomData.tiles);
        Debug.Log("Rooms Size: " + map.getMapSize().x + ", " + map.getMapSize().y);

        //AddBounds(map);

        foreach (EntityData eData in roomData.entityData)
        {
            if (eData == null)
            {
                continue;
            }
            map.AddEntity(eData);
        }
        //Post process the map based on probabilistic tiles and such
        PostProcessing(map, data);

        return(map);
    }
예제 #4
0
        public override List <RoomData> Search(string query, Session session, int Limit)
        {
            List <RoomData> rooms = new List <RoomData>();

            switch (base.QueryId)
            {
            case "my":
            {
                foreach (var room in RoomDatabase.UserRooms(session.Player.Id))
                {
                    if (rooms.Count >= Limit)
                    {
                        break;
                    }

                    if (!room.Name.ToLower().Contains(query))
                    {
                        continue;
                    }

                    rooms.Add(room);
                }
                break;
            }
            }
            return(rooms);
        }
예제 #5
0
 private void Awake()
 {
     instance = this;
     CollisionManager.InitializeCollisionManager();
     ItemDatabase.InitializeDatabase();
     AbilityDatabase.InitializeDatabase();
     EnemyDatabase.LoadDatabase();
     MapDatabase.InitializeDatabase();
     RoomDatabase.InitializeDatabase();
 }
예제 #6
0
    public static Map GenerateBossMap(MapData data)
    {
        RoomData roomData = RoomDatabase.GetBossRoom(data.type);

        data.roomSizeX = roomData.mWidth;
        data.roomSizeY = roomData.mHeight;
        Map map = new Map(data);

        map.SetTileMap(roomData.tiles);
        Debug.Log("Rooms Size: " + map.getMapSize().x + ", " + map.getMapSize().y);

        AddBounds(map);

        bool hasDoor = false;

        for (int x = 0; x < map.getMapSize().x; x++)
        {
            for (int y = 0; y < map.getMapSize().y; y++)
            {
                if (map.GetTile(x, y) == TileType.Door)
                {
                    hasDoor      = true;
                    map.exitTile = new Vector2i(x, y);
                }
            }
        }

        if (!hasDoor)
        {
            //map.startTile = GetStartTile(map, 0, 0);
            Vector2i door = AddDoorTile(map, 0, 0);
            map.exitTile = door;
            //Debug.Log("Door tile " + door);

            map.SetTile(door.x, door.y, TileType.Door);
        }

        foreach (EntityData eData in roomData.entityData)
        {
            if (eData == null)
            {
                continue;
            }
            map.AddEntity(eData);
        }


        map.bossTile = new Vector2i(8, 2);

        //This needs a +1 to hit all the bosses
        map.AddEntity(new BossData(map.bossTile.x, map.bossTile.y, GetBossForWorld(map.worldType)));
        //Post process the map based on probabilistic tiles and such
        PostProcessing(map, data);
        return(map);
    }
예제 #7
0
 public virtual void Initialize(Game1 gameReference, Player playerReference, Sadako sadakoReference, InventoryHandler inventoryHandler, LocationHandler locationHandler, EventHandler eventHandler, RoomDatabase roomDatabase, TileDatabase tileDatabase)
 {
     this.gameReference    = gameReference;
     this.playerReference  = playerReference;
     this.sadakoReference  = sadakoReference;
     this.inventoryHandler = inventoryHandler;
     this.locationHandler  = locationHandler;
     this.eventHandler     = eventHandler;
     this.tileDatabase     = tileDatabase;
     this.roomDatabase     = roomDatabase;
 }
예제 #8
0
 public virtual void Initialize(Game1 gameReference, Player playerReference, Sadako sadakoReference, InventoryHandler inventoryHandler, LocationHandler locationHandler, EventHandler eventHandler, RoomDatabase roomDatabase, TileDatabase tileDatabase)
 {
     this.gameReference = gameReference;
     this.playerReference = playerReference;
     this.sadakoReference = sadakoReference;
     this.inventoryHandler = inventoryHandler;
     this.locationHandler = locationHandler;
     this.eventHandler = eventHandler;
     this.tileDatabase = tileDatabase;
     this.roomDatabase = roomDatabase;
 }
예제 #9
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public void Initialize(RoomDatabase rdb)
        {
            initTypeAndRotation();
            initRoomDesign(rdb);

            initShadowHandlers();
            initWallHitTests();
            initDoors();
            initEntities();
            initItems();
            base.Initialize();
        }
예제 #10
0
 /// <summary>
 /// This method initializes the room's design by randomly selecting
 /// from a list of valid room designs (e.g. a list of all TRIADs facing UP)
 /// </summary>
 /// <param name="rdb">The database that contains all room designs</param>
 private void initRoomDesign(RoomDatabase rdb)
 {
     int[,] roomDesign = rdb.getRoomDesign(roomType, rotation);
     if (roomDesign != null)
     {
         setRoomDesign(roomDesign);
     }
     else
     {
         throw new Exception("Null Room Design Exception! No room design for type: " + Room.getRoomTypeString(roomType) + " and rotation: " + Room.getRoomRotationString(rotation));
     }
 }
예제 #11
0
        public void Handle(Session session, ClientPacket message)
        {
            List <RoomData> rooms = new List <RoomData>();

            RoomDatabase.UserRooms(session.Player.Id).ForEach(roomData =>
            {
                //todo: check if room is promoted
                rooms.Add(roomData);
            });

            session.Send(new PromoteOwnRoomsListComposer(rooms));
        }
예제 #12
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Debug.Log("Instance already exists, destroying object");
         Destroy(this);
     }
 }
예제 #13
0
        public void Handle(Session session, ClientPacket message)
        {
            List <RoomData> rooms = new List <RoomData>();

            RoomDatabase.UserRooms(session.Player.Id).ForEach(roomData =>
            {
                if (roomData.Group == null)
                {
                    rooms.Add(roomData);
                }
            });

            session.Send(new GroupBuyRoomsComposer(rooms.ToList()));
        }
예제 #14
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("SpawnPoint"))
     {
         if (other.GetComponent <RoomSpawner>() != null)
         {
             if (other.GetComponent <RoomSpawner>().Spawned == false && Spawned == false)
             {
                 RoomDatabase = FindObjectOfType <RoomDatabase>();
                 Instantiate(RoomDatabase.CloserRooms[Direction - 1], transform.position, Quaternion.identity);
                 Destroy(other.gameObject);
                 Destroy(this.gameObject);
             }
             Spawned = true;
         }
     }
 }
예제 #15
0
        /// <summary>
        /// This initializes a new map given a rectangle which has
        /// the starting X and Y locations of the player and the
        /// width and size of the map (not the room).
        /// </summary>
        /// <param name="init"></param>
        public void Initialize(Game game, Player playerReference, ContentManager Content, Rectangle init, Texture2D tileTexture, List <Texture2D> mapDebuggingTextures, RoomDatabase roomDatabaseReference, TileDatabase tileDatabaseReference)
        {
            gameReference              = game;
            this.shadowTexture         = Content.Load <Texture2D>("shadow");
            this.playerReference       = playerReference;
            mapDefinition              = init;
            debugTextures              = mapDebuggingTextures;
            this.roomDatabaseReference = roomDatabaseReference;
            // Generate rooms
            int width  = init.Width;
            int height = init.Height;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Room r = new Room(gameReference, x, y, shadowTexture, tileDatabaseReference, playerReference, tileTexture);
                    listOfRooms.Add(r);

#if !KRUSKAL
                    r.Initialize();
#else
                    kruskalRooms.Add(r);

                    // In Kruskal's, each room has a set of their own.
                    List <Room> list = new List <Room>();
                    list.Add(r);
                    sets.Add(list);
#endif
                }
            }

            // Generate maze
            int destination_x = random.Next(width);
            int destination_y = random.Next(height);
            endLocation.X = destination_x;
            endLocation.Y = destination_y;
#if KRUSKAL
            generateMaze();
#else
            generateMaze(destination_x, destination_y, null);
#endif
        }
    /// <summary>
    /// Entry point for populating screen with information from JSON
    /// Based on Current Information Set as dictated by dropdown.
    /// </summary>
    private void PopulateFromJson()
    {
        for (int i = 0; i < InfoContent.childCount; i++)
        {
            Destroy(InfoContent.GetChild(i).gameObject);
        }

        if (_currentInformationSet == InformationSet.WorldInformation)
        {
            _rootObject = WorldDatabase.GetWorldData() ?? Activator.CreateInstance(typeof(WorldData));
        }
        else if (_currentInformationSet == InformationSet.LevelInformation)
        {
            _rootObject = LevelDatabase.GetLevelArrayData() ?? Activator.CreateInstance(typeof(LevelArray));
        }
        else if (_currentInformationSet == InformationSet.RoomInformation)
        {
            _rootObject = RoomDatabase.GetRoomArayData() ?? Activator.CreateInstance(typeof(RoomArray));
        }
        else if (_currentInformationSet == InformationSet.InteractableInformation)
        {
            _rootObject = InteractableDatabase.GetInteractableArray() ?? Activator.CreateInstance(typeof(InteractableArray));
        }
        else if (_currentInformationSet == InformationSet.ObstacleInformation)
        {
            _rootObject = ObstacleDatabase.GetObstacleArray() ?? Activator.CreateInstance(typeof(ObstacleArray));
        }
        else if (_currentInformationSet == InformationSet.ItemInformation)
        {
            _rootObject = ItemDatabase.GetItemArray() ?? Activator.CreateInstance(typeof(ItemArray));
        }
        else if (_currentInformationSet == InformationSet.MessageInformation)
        {
            _rootObject = MessageDatabase.GetMessageData() ?? Activator.CreateInstance(typeof(MessageData));
        }

        PopulateViewGroup(_rootObject, InfoContent);
        MessageUI.text = _currentInformationSet.ToString() + " loaded.";
    }
예제 #17
0
 public RoomManager(RoomDatabase roomDatabase)
 {
     _roomDatabase = roomDatabase;
 }
예제 #18
0
    void SpawnNextRoom(Vector3 roomPos)
    {
        roomDatabase   = GameObject.FindGameObjectWithTag("RoomDatabase").GetComponent <RoomDatabase> ();
        gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController> ();
        //Cast Rays at the centerpoint of the surrounding rooms
        //set local bools to these values

        RaycastHit hit;


        if (Physics.Raycast(roomPos + new Vector3(0, 1, mRoomOffset), Vector3.down, out hit))
        {
            print("Checking Northern Room!");
            if (hit.collider.tag == "Ground")
            {
                print("Hit Northern Room!");
                nDoor        = hit.collider.gameObject.GetComponent <RoomInfo>().SouthDoor;
                disableNDoor = true;
                if (!nDoor)
                {
                    //There is a room, but there is no way in
                    nBlocked = true;
                }
                else
                {
                    hit.collider.gameObject.GetComponent <RoomInfo>().SouthExit.SpawnerActive = false;
                }
            }
        }
        else
        {
            print("No Northern Room Found!");
        }

        if (Physics.Raycast(roomPos - new Vector3(0, -1, mRoomOffset), Vector3.down, out hit))
        {
            print("Checking Southern Room!");
            if (hit.collider.tag == "Ground")
            {
                print("Hit Southern Room!");
                sDoor        = hit.collider.gameObject.GetComponent <RoomInfo>().NorthDoor;
                disableSDoor = true;
                if (!sDoor)
                {
                    //There is a room, but there is no way in
                    sBlocked = true;
                }
                else
                {
                    hit.collider.gameObject.GetComponent <RoomInfo>().NorthExit.SpawnerActive = false;
                }
            }
        }
        else
        {
            print("No Southern Room Found!");
        }

        if (Physics.Raycast(roomPos + new Vector3(mRoomOffset, 1, 0), Vector3.down, out hit))
        {
            print("Checking Eastern Room!");
            if (hit.collider.tag == "Ground")
            {
                print("Hit Eastern Room!");
                eDoor        = hit.collider.gameObject.GetComponent <RoomInfo>().WestDoor;
                disableEDoor = true;
                if (!eDoor)
                {
                    //There is a room, but there is no way in
                    eBlocked = true;
                }
                else
                {
                    hit.collider.gameObject.GetComponent <RoomInfo>().WestExit.SpawnerActive = false;
                }
            }
        }
        else
        {
            print("No Eastern Room Found!");
        }

        if (Physics.Raycast(roomPos - new Vector3(mRoomOffset, -1, 0), Vector3.down, out hit))
        {
            print("Checking Western Room!");
            if (hit.collider.tag == "Ground")
            {
                print("Hit Western Room!");
                wDoor        = hit.collider.gameObject.GetComponent <RoomInfo>().EastDoor;
                disableWDoor = true;
                if (!wDoor)
                {
                    //There is a room, but there is no way in
                    wBlocked = true;
                }
                else
                {
                    hit.collider.gameObject.GetComponent <RoomInfo>().EastExit.SpawnerActive = false;
                }
            }
        }
        else
        {
            print("No Western Room Found!");
        }

        List <RoomInfo> PotentialSpawns = new List <RoomInfo>();

        //Check if the end room can be spawned
        if (gameController.RoomsSpawned >= gameController.RoomsNeeded && !gameController.EndRoomSpawned)
        {
            //if so, ensure that it meets the requirements for spawning
            //if it does, spawn the room

            PotentialSpawns = NarrowRooms(roomDatabase.EndRooms);

            //if it does not, spawn another room as normal.
        }
        if (PotentialSpawns.Count == 0)
        {
            //search through room list and narrowdown to rooms that match the criteria
            PotentialSpawns = NarrowRooms(roomDatabase.Rooms);
        }
        else
        {
            gameController.EndRoomSpawned = true;
        }
        int RandomRoom = Random.Range(0, PotentialSpawns.Count);
        //spawn room
        GameObject SpawnedRoom = Instantiate(PotentialSpawns [RandomRoom].gameObject, roomPos, transform.rotation) as GameObject;

        gameController.RoomsSpawned++;
        SpawnedRoom.GetComponent <RoomInfo> ().SetExits();

        //disable exit spawners as to not create rooms over exiting ones
        if (disableNDoor)
        {
            SpawnedRoom.GetComponent <RoomInfo> ().NorthExit.SpawnerActive = false;
        }
        if (disableSDoor)
        {
            SpawnedRoom.GetComponent <RoomInfo> ().SouthExit.SpawnerActive = false;
        }
        if (disableEDoor)
        {
            SpawnedRoom.GetComponent <RoomInfo> ().EastExit.SpawnerActive = false;
        }
        if (disableWDoor)
        {
            SpawnedRoom.GetComponent <RoomInfo> ().WestExit.SpawnerActive = false;
        }



        //Rescan the grid
        gameController.ScanPath();
    }
예제 #19
0
    public static Map GenerateMap(MapData data)
    {
        Map map = new Map(data);

        RoomData[,] rooms = new RoomData[data.sizeX, data.sizeY];

        Vector2i startRoom;
        Vector2i endRoom;
        int      randomX = Random.Range(0, map.sizeX);

        int[] depths = new int[map.sizeX];


        if (data.baseDepth < data.sizeY)
        {
            for (int i = 0; i < depths.Length; i++)
            {
                depths[i] = data.baseDepth + (Random.Range(-data.depthVariance, data.depthVariance));
            }
            Debug.Log("Random X: " + randomX);
            startRoom = new Vector2i(randomX, depths[randomX]);
        }
        else
        {
            for (int i = 0; i < depths.Length; i++)
            {
                depths[i] = data.sizeY;
            }

            startRoom = new Vector2i(randomX, map.sizeY - 1);
        }

        RoomData[,] roomPath = RoomMap(map.sizeX, map.sizeY, startRoom, out endRoom);

        if (data.hasMiniboss)
        {
            Debug.Log("Has miniboss");
            roomPath[endRoom.x, endRoom.y].roomType = RoomType.MinibossRoom;
        }
        SurfaceLayer temp;

        for (int x = 0; x < map.sizeX; x++)
        {
            for (int y = 0; y < map.sizeY; y++)
            {
                if (y < depths[x])
                {
                    temp = SurfaceLayer.Inner;
                }
                else if (y > depths[x])
                {
                    temp = SurfaceLayer.Above;
                }
                else
                {
                    temp = SurfaceLayer.Surface;
                }



                if (roomPath[x, y] != null)
                {
                    if (roomPath[x, y].roomType == RoomType.MinibossRoom)
                    {
                        rooms[x, y] = RoomDatabase.GetRoom(RoomType.MinibossRoom);
                    }
                    else
                    {
                        rooms[x, y] = RoomDatabase.GetRoom(roomPath[x, y].roomType, temp);
                    }
                }
                else
                {
                    rooms[x, y] = RoomDatabase.GetRoom(RoomType.SideRoom, temp);
                }

                foreach (EntityData eData in rooms[x, y].entityData)
                {
                    if (eData == null)
                    {
                        continue;
                    }
                    map.AddEntity(eData);
                }
            }
        }

        map.SetTileMap(RoomsToMap(rooms, data.sizeX, data.sizeY));

        //TODO Turn room array into map



        AddBounds(map);

        Debug.Log("Start room: " + startRoom.x + ", " + startRoom.y);
        Vector2i door = AddDoorTile(map, endRoom.x, endRoom.y);

        map.SetTile(door.x, door.y, TileType.Door);
        map.exitTile = door;
        //Debug.Log("Door tile " + door);
        map.startTile = GetStartTile(map, startRoom.x, startRoom.y);


        if (data.mapType != MapType.Ship && data.mapType != MapType.BossMap)
        {
            //PopulateMap(map);

            //PopulateBoss(map);
            AddChests(map);
            //AddFauna(map);
            //AddFallingRock(map);

            //PopulateBoss(map);
        }


        //Post process the map based on probabilistic tiles and such
        PostProcessing(map, data);


        return(map);
    }
예제 #20
0
    public static Map GenerateShipMap(MapData data)
    {
        Debug.Log("Rooms Size: " + data.roomSizeX + ", " + data.roomSizeY);

        RoomData roomData = RoomDatabase.GetRoom(RoomType.Ship);

        data.roomSizeX = roomData.mWidth;
        data.roomSizeY = roomData.mHeight;

        Debug.Log("Rooms Size: " + data.roomSizeX + ", " + data.roomSizeY);
        Map map = new Map(data);



        map.SetTileMap(roomData.tiles);
        Debug.Log("Rooms Size: " + map.getMapSize().x + ", " + map.getMapSize().y);

        AddBounds(map);

        /*
         * map.AddEntity(new NPCData(1, 1, NPCType.ArmsDealer));
         * map.AddEntity(new NPCData(14, 1, NPCType.GeneralTrader));
         * map.AddEntity(new NPCData(8, 4, NPCType.Gadgeteer));
         * map.AddEntity(new NPCData(20, 1, NPCType.PotionSeller));
         * map.AddEntity(new NPCData(22, 4, NPCType.Clothier));
         * map.AddEntity(new NPCData(10, 13, NPCType.EggsDealer));
         */
        //map.AddEntity(new BossData(10, 13, BossType.VoidBoss));


        if (WorldManager.instance.NumCompletedWorlds() == 0)
        {
            map.AddEntity(new ItemObjectData(6, 1, ObjectType.Item, "Biosample"));
            map.AddEntity(new ItemObjectData(7, 1, ObjectType.Item, "Slime Egg"));
        }

        if (WorldManager.instance.NumCompletedWorlds() == 0)
        {
            //map.AddEntity(new ItemObjectData(6, 1, ObjectType.Item, "Snowzooka"));
        }
        //map.AddEntity(new MinibossData(15, 10, map.Data.minibossType));
        //map.AddEntity(new EnemyData(15, 10, EnemyType.Sporby));

        if (WorldManager.instance.NumCompletedWorlds() == 0)
        {
            /*
             * map.AddEntity(new ItemObjectData(8, 1, ObjectType.Item, "ForceFieldGadget"));
             * map.AddEntity(new ItemObjectData(9, 1, ObjectType.Item, "NovaGadget"));
             * map.AddEntity(new ItemObjectData(10, 1, ObjectType.Item, "HookShot"));
             * map.AddEntity(new ItemObjectData(10, 1, ObjectType.Item, "HookShot"));
             * map.AddEntity(new ItemObjectData(11, 1, ObjectType.Item, "PortalGadget"));
             * map.AddEntity(new ItemObjectData(12, 1, ObjectType.Item, "Teleporter"));
             * map.AddEntity(new ItemObjectData(13, 1, ObjectType.Item, "CaptureGadget"));
             */
        }

        foreach (EntityData eData in roomData.entityData)
        {
            if (eData == null)
            {
                continue;
            }
            map.AddEntity(eData);
        }
        //Post process the map based on probabilistic tiles and such
        PostProcessing(map, data);

        return(map);
    }
예제 #21
0
 public override void Initialize(Game1 gameReference, Player playerReference, Sadako sadakoReference, InventoryHandler inventoryHandler, LocationHandler locationHandler, EventHandler eventHandler, RoomDatabase roomDatabase, TileDatabase tileDatabase)
 {
     base.Initialize(gameReference, playerReference, sadakoReference, inventoryHandler, locationHandler, eventHandler, roomDatabase, tileDatabase);
 }
예제 #22
0
 public override void Initialize(Game1 gameReference, Player playerReference, Sadako sadakoReference, InventoryHandler inventoryHandler, LocationHandler locationHandler, EventHandler eventHandler, RoomDatabase roomDatabase, TileDatabase tileDatabase)
 {
     base.Initialize(gameReference, playerReference, sadakoReference, inventoryHandler, locationHandler, eventHandler, roomDatabase, tileDatabase);
 }
예제 #23
0
 void Start()
 {
     RoomDatabase = FindObjectOfType <RoomDatabase>();
     Invoke("Spawn", 0.1f);
 }
예제 #24
0
    private void GenerateMap(int roomCount)
    {
        _rooms = new Room[roomCount];
        for (int i = 0; i < roomCount; i++)
        {
            _rooms[i] = new Room();
        }

        //Create network
        Queue <int> roomsToBeConneted = new Queue <int>();

        for (int i = 1; i < _rooms.Length; i++)
        {
            roomsToBeConneted.Enqueue(i);
        }

        Stack <int> connectedRooms = new Stack <int>();

        List <int> roomsToConnect = new List <int>()
        {
            0
        };

        _roomPositions = new List <Vector2>();
        _roomPositions.Add(Vector2.zero);
        _rooms[0].Entrance = true;

        while (roomsToBeConneted.Count > 0)
        {
            //Get room from list of rooms to be connected
            int nextRoomIndex = Random.Range(0, roomsToConnect.Count);
            int roomIndex     = roomsToConnect[nextRoomIndex];
            roomsToConnect.RemoveAt(nextRoomIndex);
            Room currentRoom = _rooms[roomIndex];

            //Create Connections - I want a max of 3 (including "entrance")
            int connections = Random.Range(1, 3);
            for (int i = 0; i < connections; i++)
            {
                bool connected = false;
                if (roomsToBeConneted.Count > 0)
                {
                    //Get a branching direction
                    List <int> possibleDirections = GetPossibleDirections(currentRoom.Position);
                    int        direction          = currentRoom.GetConnectionDirection(possibleDirections);

                    if (direction >= 0)
                    {
                        connected = true;

                        int connectingRoom = roomsToBeConneted.Dequeue();
                        currentRoom.AddConnectingRoom(direction, connectingRoom);
                        _rooms[connectingRoom].AddConnectingRoom((direction + 2) % 4, roomIndex);

                        //Set position of newly connected room
                        Vector2 position = currentRoom.Position + VectorFromDirection(direction);
                        _rooms[connectingRoom].Position = position;
                        _roomPositions.Add(position);

                        //Add connected room to queue for connection
                        roomsToConnect.Add(connectingRoom);
                    }

                    if (!connected)
                    {
                        //Backtrack to find another branch route
                        roomsToConnect.Add(connectedRooms.Pop());
                    }
                }
            }
        }

        //Get Endpoints
        Stack <int> endCaps = new Stack <int>();

        for (int i = 1; i < _rooms.Length; i++)
        {
            if (_rooms[i].Connections <= 1)
            {
                endCaps.Push(i);
            }
        }

        //TODO: If user wants random content, put in endcaps

        //Last end cap is the exit point
        _exitPoint = endCaps.Pop();
        _rooms[_exitPoint].StaticData = RoomDatabase.GetFillerRoom();
        _rooms[_exitPoint].Exit       = true;

        //Fill start point
        _rooms[0].StaticData = RoomDatabase.GetFillerRoom();

        //Fill in data
        List <string> roomDataIndicies = StaticData.RoomIds.ToList();
        List <int>    roomIndecies     = new List <int>();

        for (int i = 1; i < roomCount; i++)
        {
            if (i != _exitPoint)
            {
                roomIndecies.Add(i);
            }
        }

        while (roomIndecies.Count > 0)
        {
            int i         = Random.Range(0, roomIndecies.Count);
            int roomIndex = roomIndecies[i];
            roomIndecies.Remove(roomIndex);

            string roomId = null;
            if (roomDataIndicies.Count > 0)
            {
                int index = Random.Range(0, roomDataIndicies.Count);
                roomId = roomDataIndicies[index];
                roomDataIndicies.Remove(roomId);
            }

            RoomData data = roomId == null?RoomDatabase.GetFillerRoom() : RoomDatabase.GetRoomData(roomId);

            _rooms[roomIndex].Setup(data);
        }
    }
예제 #25
0
 public RoomsController(RoomDatabase db)
 {
     this.db = db;
 }
예제 #26
0
 public ListRoomsHandler(IServiceProvider services)
 {
     _roomDatabase = services.GetService <RoomDatabase>();
 }
예제 #27
0
 public void Start()
 {
     _rooms = FindObjectOfType <RoomDatabase>();
 }