Esempio n. 1
0
 public static Thing Random()
 {
     return(new Thing
     {
         Kind = GenGod.GenOne(0, 2) == 0 ? ThingKind.Weapon : ThingKind.Armor,
         Bonus = GenGod.GenOne(0, 10),
         Identified = true
     });
 }
Esempio n. 2
0
        public Level(int width, int height, int nRooms, int minSize, int maxSize)
        {
            Width  = width;
            Height = height;
            _tiles = new List <Tile>(Generate(() => new Tile {
                Kind = TileKind.Wall
            }).Take(width * height));

            _rooms = Generate(() => GenGod.Point(0, 0, Width, Height))
                     .Where(p => this[p].Kind == TileKind.Wall)
                     .Where(p =>
            {
                var growth = PossibleGrowth(p);
                return(growth.X > 0 && growth.Y > 0);
            })
                     .Select(p =>
            {
                Point growth = PossibleGrowth(p);
                var half     = new Point {
                    X = growth.X / 2, Y = growth.Y / 2
                };
                var room = new Room
                {
                    TopLeft = p + half,
                    Size    = growth
                };
                var clampedX     = room.BottomRight.X >= Width ? Width - 1 : room.BottomRight.X;
                var clampedY     = room.BottomRight.Y >= Height ? Height - 1 : room.BottomRight.Y;
                room.BottomRight = new Point {
                    X = clampedX, Y = clampedY
                };
                CarveRoom(room);
                return(room);
            })
                     .Take(nRooms)
                     .ToList();

            var connections = (from a in _rooms
                               from b in _rooms
                               where a != b && a.IsWestOf(b)
                               select new { a, b }).ToList();

            foreach (var c in connections)
            {
                foreach (var p in EastOf(c.a.TopLeft).TakeWhile(p => p.X <= c.b.TopLeft.X))
                {
                    this[p].Kind = TileKind.Floor;
                }
                foreach (var p in NorthOf(new Point {
                    X = c.b.TopLeft.X, Y = c.a.TopLeft.Y
                }).TakeWhile(p => p.Y >= c.b.TopLeft.Y))
                {
                    this[p].Kind = TileKind.Floor;
                }
                foreach (var p in SouthOf(new Point {
                    X = c.b.TopLeft.X, Y = c.a.TopLeft.Y
                }).TakeWhile(p => p.Y <= c.b.TopLeft.Y))
                {
                    this[p].Kind = TileKind.Floor;
                }
            }
        }
Esempio n. 3
0
        public Point GetWalkablePoint()
        {
            var room = _rooms[GenGod.GenOne(0, _rooms.Count)];

            return(GenGod.Point(room.TopLeft.X, room.TopLeft.Y, room.BottomRight.X, room.BottomRight.Y));
        }