Пример #1
0
        private void GenerateFinal()
        {
            // big room
            int roomY  = Data.GetLength(0) / 4;
            int roomY2 = 3 * Data.GetLength(0) / 4;
            int roomX  = Data.GetLength(1) / 4;
            int roomX2 = 3 * Data.GetLength(1) / 4;

            RoomPoints.Add(new List <int>(new int[] { roomY, roomX, roomY2, roomX2 }));
            for (int y = roomY; y < roomY2; ++y)
            {
                for (int x = roomX; x < roomX2; ++x)
                {
                    Data[y, x] = new RoomFloor(y, x, 0);
                }
            }
            for (int y = roomY - 1; y < roomY2 + 1; ++y)
            {
                for (int x = roomX - 1; x < roomX2 + 1; ++x)
                {
                    if (Data[y, x] == null)
                    {
                        Data[y, x] = new Wall(y, x);
                    }
                }
            }
            int entryY = roomY2;
            int entryX = (roomX + roomX2) / 2;

            Data[entryY, entryX] = new Stair(entryY, entryX, StairType.Up);
            Data[roomY, (roomX + roomX2) / 2].Inventory.AddItem(new Macguffin());
            Program.player.CoordX = entryX;
            Program.player.CoordY = entryY;
        }
Пример #2
0
        /// <summary> Populates a dungeon-like map. </summary>
        private void GenerateDungeon()
        {
            GenerateRooms();
            GenerateMaze();
            foreach (List <int> pointSet in RoomPoints)
            {
                MakeDoor(pointSet);
            }
            // Retract the maze starting at the dead ends
            for (int i = 0; i < 500; i++)
            {
                List <List <int> > mazeEnds = GetMazeEndPoints();
                foreach (List <int> endPoints in mazeEnds)
                {
                    Data[endPoints[0], endPoints[1]] = null;
                }
            }
            // Ensure that all regions are connected (i.e. only one region)
            List <List <int> > regionLocations = GetRegionLocations();

            while (regionLocations.Count > 1)
            {
                ConnectRegions(regionLocations);
                FloodFill(regionLocations[0][0], regionLocations[0][1]);
                regionLocations = GetRegionLocations();
            }
            // Place the stairs to get out of the dungeon
            int entryRoom = Engine.rand.Next(0, RoomPoints.Count);
            int exitRoom  = Engine.rand.Next(0, RoomPoints.Count);

            if (entryRoom == exitRoom && RoomPoints.Count > 1)
            {
                exitRoom = (exitRoom + 1) % RoomPoints.Count;
            }
            int entryY = Engine.rand.Next(RoomPoints[entryRoom][0], RoomPoints[entryRoom][2]);
            int entryX = Engine.rand.Next(RoomPoints[entryRoom][1], RoomPoints[entryRoom][3]);
            int exitY  = Engine.rand.Next(RoomPoints[exitRoom][0], RoomPoints[exitRoom][2]);
            int exitX  = Engine.rand.Next(RoomPoints[exitRoom][1], RoomPoints[exitRoom][3]);

            Data[entryY, entryX] = new Stair(entryY, entryX, StairType.Up);
            Data[exitY, exitX]   = new Stair(exitY, exitX, StairType.Down);
            foreach (List <int> points in RoomPoints)
            {
                for (int y = points[0] - 1; y < points[2] + 1; ++y)
                {
                    for (int x = points[1] - 1; x < points[3] + 1; ++x)
                    {
                        if (Data[y, x] == null)
                        {
                            Data[y, x] = new Wall(y, x);
                        }
                    }
                }
            }

            Program.player.CoordX = entryX;
            Program.player.CoordY = entryY;
            foreach (List <int> room in RoomPoints)
            {
                int cY = Engine.rand.Next(room[0], room[2]);
                int cX = Engine.rand.Next(room[1], room[3]);
                // randomly select index
                // get type of that index
                // make new object of that type with cast of that type
                Creature c = new Creature(Engine.MasterCreatures[0]);
                c.CoordY = cY;
                c.CoordX = cX;
                Creatures.Add(c);
            }
            foreach (List <int> room in RoomPoints)
            {
                if (Engine.rand.Next(0, 10) < 3)
                {
                    int index = Engine.rand.Next(0, Engine.MasterOrbs.Count);
                    int y     = Engine.rand.Next(room[0], room[2]);
                    int x     = Engine.rand.Next(room[1], room[3]);
                    Data[y, x].Inventory.AddItem(new Orb(Engine.MasterOrbs[index]));
                }
            }
        }