Example #1
0
    //Randomly places a new dungeon room next to one that already exists
    private static void PlaceRandomRoom(Dungeon Dungeon)
    {
        //Get a random size for the new room
        Vector2 RoomSize = GetNewRoomSize(Dungeon.RoomSizes);

        //Create a shuffled copy of the list of rooms that already exist in the dungeon
        List <DungeonRoom> RoomsCopy = ListFunctions.Copy(Dungeon.Rooms);

        ListFunctions.Shuffle(RoomsCopy);

        //Search through the rooms, checking if we can place the new room adjacent to any of these existing rooms
        foreach (DungeonRoom OtherRoom in RoomsCopy)
        {
            //Make a list of the 4 placement directions we want to check for placing the new room
            List <Direction> Directions = new List <Direction>();
            for (int i = 0; i < 4; i++)
            {
                Directions.Add((Direction)i);
            }
            ListFunctions.Shuffle(Directions);

            //Use each direction to check if we can place the new room next to the current OtherRoom in that direction
            Direction Placement = Direction.North;
            bool      Found     = false;
            foreach (Direction Check in Directions)
            {
                //Store the direction and exit out once a valid placement location has been found
                if (CanPlaceRoom(Dungeon, RoomSize, OtherRoom, Check))
                {
                    Placement = Check;
                    Found     = true;
                    break;
                }
            }

            //Add the new room to the dungeon if a valid placement location was found
            if (Found)
            {
                Vector2     NewRoomPos = OtherRoom.GetAdjacentLocation((int)RoomSize.x, (int)RoomSize.y, Placement);
                DungeonRoom NewRoom    = new DungeonRoom((int)RoomSize.x, (int)RoomSize.y, NewRoomPos);
                NewRoom.Init();
                Dungeon.Rooms.Add(NewRoom);
                ConnectRooms(Dungeon, OtherRoom, NewRoom, Placement);
                return;

                return;
            }
        }
    }
Example #2
0
 public void AddRoom()
 {
     unitOfWork.RepoOtherRooms.Add(RoomCreate);
     try
     {
         if (unitOfWork.Save() > 0)
         {
             Messenger.Default.Send("Nieuwe kamer successvol toegevoegd");
             RoomCreate = new OtherRoom();
         }
         else
         {
             Messenger.Default.Send("Toevoeging gefaald ");
         }
     }
     catch (Exception err)
     {
         Messenger.Default.Send(err.Message);
     }
 }
Example #3
0
 public RoomCreateViewModel()
 {
     RoomCreate = new OtherRoom();
 }