예제 #1
0
        public void Generate(Rooms[,] map)
        {
            for (int x = 0; x < map.GetLength(0); x++)
                for (int y = 0; y < map.GetLength(1); y++)
                {
                    int number = map[x, y].roomVersion;

                    if (number > 0)
                    {
                        rooms.Add(map[x, y]);
                        rooms[rooms.Count - 1].RoomCreate(number, new Rectangle(x * 16, y * 16, 16, 16));
                    }
                }
        }
예제 #2
0
        public Rooms[,] GenerateRooms()
        {
            startRoom = 1;
            endRoom = 1;
            itemRoom = 1;
            specialRoom = 4;
            differentRoom = 8;

            for (int i = 0; i < roomsOnFloor.GetLength(0); i++)
            {
                for (int j = 0; j < roomsOnFloor.GetLength(1); j++)
                {
                    roomsOnFloor[i, j] = new Rooms(0, empty);
                }
            }

            numOfRooms = random.Next(6, 8);
            tmpNumOfRooms = 0;

            //place rooms
            for (int i = 0; i < 3; i++)
            {
                positionOnFloor[0] = 13;
                positionOnFloor[1] = 13;
                while (true)
                {
                    direction = (Direction)random.Next(4);

                    if (direction == Direction.Up)
                    {
                        positionOnFloor[1] -= 1;
                    }
                    if (direction == Direction.Left)
                    {
                        positionOnFloor[0] -= 1;
                    }
                    if (direction == Direction.Down)
                    {
                        positionOnFloor[1] += 1;
                    }
                    if (direction == Direction.Right)
                    {
                        positionOnFloor[0] += 1;
                    }

                    if (roomsOnFloor[positionOnFloor[0], positionOnFloor[1]].roomVersion == 0)
                    {
                        /*int roomVersion = random.Next(2, 12);
                        if (roomVersion > 10)
                            roomVersion = 3;
                        else if (roomVersion > 5)
                            roomVersion = 2;*/
                        int roomVersion = 2;

                        roomsOnFloor[positionOnFloor[0], positionOnFloor[1]] = new Rooms(roomVersion, empty);
                        tmpNumOfRooms += 1;
                    }

                    if (tmpNumOfRooms > numOfRooms)
                    {
                        tmpNumOfRooms = 0;
                        numOfRooms = random.Next(4, 10);
                        break;
                    }
                }
            }
            roomsOnFloor[13, 13] = new Rooms(2,empty);

            //checking number of entrances for each room and where they are
            for (int x = 0; x < roomsOnFloor.GetLength(0); x++)
            {
                for (int y = 0; y < roomsOnFloor.GetLength(1); y++)
                {
                    if (roomsOnFloor[x, y].roomVersion != 0)
                    {
                        roomsOnFloor[x, y].roomVersionDoors = new int[4] { 0, 0, 0, 0 };

                        for (int i = 0; i < 4; i++)
                        {
                            positionOnFloor[0] = x;
                            positionOnFloor[1] = y;

                            direction = (Direction)i;

                            if (direction == Direction.Up)
                            {
                                positionOnFloor[1] -= 1;
                            }
                            if (direction == Direction.Left)
                            {
                                positionOnFloor[0] -= 1;
                            }
                            if (direction == Direction.Down)
                            {
                                positionOnFloor[1] += 1;
                            }
                            if (direction == Direction.Right)
                            {
                                positionOnFloor[0] += 1;
                            }

                            if (roomsOnFloor[positionOnFloor[0], positionOnFloor[1]].roomVersion != 0)
                            {
                                if (direction == Direction.Up)
                                {
                                    roomsOnFloor[x, y].roomVersionDoors[0] = 1;
                                }
                                if (direction == Direction.Left)
                                {
                                    roomsOnFloor[x, y].roomVersionDoors[1] = 1;
                                }
                                if (direction == Direction.Down)
                                {
                                    roomsOnFloor[x, y].roomVersionDoors[2] = 1;
                                }
                                if (direction == Direction.Right)
                                {
                                    roomsOnFloor[x, y].roomVersionDoors[3] = 1;
                                }
                            }
                        }
                    }
                }
            }

            //fixing different types of rooms example 
            while (endRoom > 0 || startRoom > 0 || itemRoom > 0 || specialRoom > 0)
            {
                for (int x = 0; x < roomsOnFloor.GetLength(0); x++)
                {
                    for (int y = 0; y < roomsOnFloor.GetLength(1); y++)
                    {
                        if (roomsOnFloor[x, y].roomVersion == 2)
                        {
                            int numberOfDoors = 0;
                            for (int i = 0; i < 4; i++)
                            {
                                numberOfDoors += roomsOnFloor[x, y].roomVersionDoors[i];
                            }
                            int chance = random.Next(8*3);

                            if (numberOfDoors == 1)
                            {
                                if (chance == 1 && endRoom > 0)
                                {
                                    roomsOnFloor[x, y].roomVersion = 5;
                                    endRoom -= 1;
                                    continue;
                                }
                            }
                            else if (numberOfDoors == 2)
                            {
                                if (chance == 1 && endRoom > 0)
                                {
                                    roomsOnFloor[x, y].roomVersion = 5;
                                    endRoom -= 1;
                                    continue;
                                }
                                else if (chance == 1 && startRoom > 0)
                                {
                                    roomsOnFloor[x, y].roomVersion = 1;
                                    startRoom -= 1;
                                    continue;
                                }
                                else if (chance == 1 && itemRoom > 0)
                                {
                                    roomsOnFloor[x, y].roomVersion = 4;
                                    itemRoom -= 1;
                                    continue;
                                }
                            }
                            if (chance == 1 && startRoom > 0)
                            {
                                roomsOnFloor[x, y].roomVersion = 1;
                                startRoom -= 1;
                            }
                            else if (chance == 1 && itemRoom > 0)
                            {
                                roomsOnFloor[x, y].roomVersion = 4;
                                itemRoom -= 1;
                            }
                            else if (chance == 1 && specialRoom > 0)
                            {
                                roomsOnFloor[x, y].roomVersion = 3;
                                specialRoom -= 1;
                            }
                        }
                    }
                }

                
            }
            return roomsOnFloor;
        }