Esempio n. 1
0
        //public static Random rnd = new Random(1337);

        private static List <LayoutRoom> generateLayout(MapParams parameter)
        {
            LayoutRoom         r         = new LayoutRoom(new[] { new Point(0, 0), new Point(parameter.width, 0), new Point(parameter.width, parameter.height), new Point(0, parameter.height) });
            List <LayoutRoom>  rooms     = new List <LayoutRoom>();
            Queue <LayoutRoom> toCompute = new Queue <LayoutRoom>();

            toCompute.Enqueue(r);

            LayoutRoom current;
            int        spl;
            bool       splitH = false;

            while (toCompute.Count != 0)
            {
                current = toCompute.Dequeue();
                Tuple <LayoutRoom, LayoutRoom> ret;
                if (current.AvailableForSplitH(MIN_ROOM_SIZE, MAX_ROOM_SIZE) && current.AvailableForSplitV(MIN_ROOM_SIZE, MAX_ROOM_SIZE))
                {
                    spl = RandomGen.GetRandom(MIN_ROOM_SIZE, (splitH ? current.Bounds.Height : current.Bounds.Width) - MIN_ROOM_SIZE);

                    ret = splitH ? current.SplitHorizontal(spl) : current.SplitVertical(spl);
                }
                else if (current.AvailableForSplitV(MIN_ROOM_SIZE, MAX_ROOM_SIZE))
                {
                    spl = RandomGen.GetRandom(MIN_ROOM_SIZE, current.Bounds.Width - MIN_ROOM_SIZE);
                    ret = current.SplitVertical(spl);
                }
                else
                {
                    spl = RandomGen.GetRandom(MIN_ROOM_SIZE, current.Bounds.Height - MIN_ROOM_SIZE);
                    ret = current.SplitHorizontal(spl);
                }

                splitH = !splitH;

                if (ret.Item1.AvailableForSplit(MIN_ROOM_SIZE, MAX_ROOM_SIZE))
                {
                    toCompute.Enqueue(ret.Item1);
                }
                else
                {
                    rooms.Add(ret.Item1);
                }

                if (ret.Item2.AvailableForSplit(MIN_ROOM_SIZE, MAX_ROOM_SIZE))
                {
                    toCompute.Enqueue(ret.Item2);
                }
                else
                {
                    rooms.Add(ret.Item2);
                }
            }

            return(rooms);
        }
Esempio n. 2
0
        public static List <Tuple <Corridor, Corridor, Room> > GenerateLayout(MapParams parameter)
        {
            List <LayoutRoom> rooms = generateLayout(parameter);

            List <Tuple <Corridor, Corridor, Room> > map = rooms.Select(x => x.ToGameplayObjects()).ToList();



            return(map);
        }
Esempio n. 3
0
        public static Bitmap Preview(List <AbstractRoom> rooms, MapParams parameter)
        {
            Color[,] pxl = new Color[parameter.width, parameter.height];

            for (int w = 0; w < parameter.width; w++)
            {
                for (int h = 0; h < parameter.height; h++)
                {
                    pxl[w, h] = Color.Black;
                }
            }

            foreach (AbstractRoom room in rooms)
            {
                for (int w = room.Start.X; w < room.Start.X + room.data.GetLength(0); w++)
                {
                    for (int h = room.Start.Y; h < room.Start.Y + room.data.GetLength(1); h++)
                    {
                        pxl[w, h] = room.data[w - room.Start.X, h - room.Start.Y];
                    }
                }
            }


            Bitmap ret = new Bitmap(parameter.width, parameter.height);


            for (int w = 0; w < parameter.width; w++)
            {
                for (int h = 0; h < parameter.height; h++)
                {
                    ret.SetPixel(w, h, pxl[w, h]);
                }
            }

            return(ret);
        }