示例#1
0
        public Hero()
            : base(DrawTag.Hero, "Hero")
        {
            canOpenDoors = true;

            justMoved = false;

            inventory = new List<Item>();

            visibleRect = new Rect(0, 0, 0, 0);

            str = 30;
            def = 10;
            dex = 10;
            speed = 100;
            hp = 200;
            maxHp = hp;

            faction = Faction.Good;
        }
示例#2
0
 private static bool rectIsClear(Level level, Rect rect)
 {
     for (int x = rect.x1; x <= rect.x2; x++)
     {
         for (int y = rect.y1; y <= rect.y2; y++)
         {
             Tile tile = level.getTile(new Location(x, y));
             if (tile == null || !tile.blocksMovement)
                 return false;
         }
     }
     return true;
 }
示例#3
0
        public static void generateDungeon(Level level, int width, int height)
        {
            Rect dungeonRect = new Rect(0, 0, width, height);
            level.bounds = dungeonRect;

            carveRoom(level, dungeonRect, true, TileType.Dungeon_Wall);

            Location center = new Location(width / 2, height / 2);
            Rect innerRoom = createRect(center, Direction.West, Feature.Room);
            carveRoom(level, innerRoom, false, TileType.Dungeon_Floor);

            for (int i = 0; i < 100; i++)
            {
                Location doorLoc = findDoor(level, dungeonRect);

                //randomly choose a feature to add to the dungeon
                Feature[] features = {Feature.Corridor, Feature.Room};
                Feature feature = Util.chooseRandomElement(features);

                tryAddFeature(level, doorLoc, feature);
            }
            addEntranceAndExit(level, dungeonRect);
            addChests(level, dungeonRect);
            addMonsters(level, dungeonRect);
            initLighting(level, dungeonRect);
        }
示例#4
0
        private static Location findDoor(Level level, Rect dungeonRect)
        {
            Location doorLoc = new Location(0, 0);

            while (!isDoorCandidate(level, doorLoc))
            {
                doorLoc = new Location(
                    Util.random.Next(dungeonRect.x2),
                    Util.random.Next(dungeonRect.y2));
            }

            return doorLoc;
        }
示例#5
0
 private static void initLighting(Level level,  Rect bounds)
 {
     for (int x = bounds.x1; x <= bounds.x2; x++)
     {
         for (int y = bounds.y1; y <= bounds.y2; y++)
         {
             if (isDark(level, new Location(x, y)))
             {
                 level.setLit(new Location(x, y), Entity.LIT_FULL_DARK);
             }
         }
     }
 }
示例#6
0
 private static void carveRoom(Level level, Rect rect, bool blocks, TileType tileType)
 {
     for (int x = rect.x1; x <= rect.x2; x++)
     {
         for (int y = rect.y1; y <= rect.y2; y++)
         {
             Tile tile = new Tile(blocks, tileType);
             level.addTile(tile, new Location(x, y));
         }
     }
 }
示例#7
0
 private static void carveCorridor(Level level, Rect rect, bool blocks, TileType tileType)
 {
     rect.compressCorridor();
     carveRoom(level, rect, blocks, tileType);
 }
示例#8
0
        private static void addMonsters(Level level, Rect bounds)
        {
            List<Monster> monsters = MonsterFactory.getDungeonMonsters(1);

            for (int i = 0; i < monsters.Count; i++)
            {
                Location monsterLocation = new Location(0, 0);

                while (!isMonsterCandidate(level, monsterLocation))
                {
                    monsterLocation.x = Util.random.Next(bounds.x1, bounds.x2);
                    monsterLocation.y = Util.random.Next(bounds.y1, bounds.y2);
                }

                level.addActor(monsters[i], monsterLocation);
            }
        }
示例#9
0
        private static void addEntranceAndExit(Level level, Rect dungeon)
        {
            Location loc = new Location(0, 0);

            while (!isStairCandidate(level, loc))
            {
                loc.x = Util.random.Next(dungeon.x1, dungeon.x2);
                loc.y = Util.random.Next(dungeon.y1, dungeon.y2);
            }

            Staircase upcase = new Staircase(true);
            level.addWalkable(upcase, loc);
            level.upStairs = loc;

            loc = new Location(0, 0);

            while (!isStairCandidate(level, loc))
            {
                loc.x = Util.random.Next(dungeon.x1, dungeon.x2);
                loc.y = Util.random.Next(dungeon.y1, dungeon.y2);
            }

            Staircase downcase = new Staircase(false);
            level.addWalkable(downcase, loc);
            level.downStairs = loc;
        }
示例#10
0
        private static void addChests(Level level, Rect bounds)
        {
            const int numChests = 5;
            for (int i = 0; i < numChests; i++)
            {
                Location chestLoc = new Location(0, 0);

                while (!isChestCandidate(level, chestLoc))
                {
                    chestLoc.x = Util.random.Next(bounds.x1, bounds.x2);
                    chestLoc.y = Util.random.Next(bounds.y1, bounds.y2);
                }

                Chest chest = new Chest();
                level.addWalkable(chest, chestLoc);
            }
        }