Beispiel #1
0
    public Dungeon generateDungeon(Random rand, int seed)
    {
        //LATER_PATCH: pick dungeon type

        //scegli layout
        DungeonLayout layout = DungeonDispatcher.getDungeonLayoutById((rand.Next() % Constants.LAYOUTS_COUNT) + 1);

        //scegli stanze
        List <DungeonRoom> rooms = new List <DungeonRoom>();

        foreach (PseudoRoom room in layout.rooms)
        {
            DungeonRoom pickedRoom = DungeonDispatcher.getDungeonRoomByType(room.sizeX, room.sizeY, rand.Next(), rand);
            layout.grid.paste(pickedRoom.grid, room.position);
            rooms.Add(pickedRoom);
        }

        //crea percorsi
        PathLinkingStrategy pathLinker = new ClosestPathLinker();         //LATER_PATCH: decide which srtategy to use

        pathLinker.linkPaths(layout, rand);
        layout.grid.normalize();

        //inserisci tesori
        List <Treasure> treasures = new List <Treasure>();

        foreach (DungeonRoom room in rooms)
        {
            foreach (Treasure treasure in room.treasures)
            {
                treasures.Add(TreasureInitializer.initializeTreasure(treasure, rand));
            }
        }

        List <Coordinates> culDeSacs = layout.grid.getCulDeSacs();

        foreach (Coordinates culDeSac in culDeSacs)
        {
        }
        int antiChances = Constants.TREASURE_SPAWN_PERIOD;

        foreach (Coordinates point in culDeSacs)
        {
            if (rand.Next() % antiChances == 0)
            {
                layout.grid.put(point, Constants.TREASURE_MARKER);
                treasures.Add(TreasureInitializer.initializeTreasure(new Treasure(point), rand));
                antiChances = Constants.TREASURE_SPAWN_PERIOD + (treasures.Count * Constants.TREASURE_SPAWN_INCREMENTAL);
            }
            else
            {
                antiChances -= Constants.TREASURE_SPAWN_INCREMENTAL;
            }
        }

        //LATER_PATCH: add traps

        return(new Dungeon(layout.grid, rooms, treasures, seed /*LATER_PATCH: , traps*/));
    }
Beispiel #2
0
    /// <summary>
    /// check if all rooms are declared correctly.
    /// does NOT check both rotations for rooms where sizeX == sizeY
    /// </summary>
    public static void runValidation()
    {
        Random r = new Random();

        //validate 3x3
        for (int id = 0; id < Constants.ROOM_3x3_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(3, 3, id, r), id + 1, 3, 3);
        }
        //validate 3x5, 5x3
        for (int id = 0; id < Constants.ROOM_3x5_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(3, 5, id, r), id + 1, 3, 5);
            singleValidation(DungeonDispatcher.getDungeonRoomByType(5, 3, id, r), id + 1, 5, 3);
        }
        //validate 3x7, 7x3
        for (int id = 0; id < Constants.ROOM_3x7_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(3, 7, id, r), id + 1, 3, 7);
            singleValidation(DungeonDispatcher.getDungeonRoomByType(7, 3, id, r), id + 1, 7, 3);
        }
        //validate 3x9, 9x3
        for (int id = 0; id < Constants.ROOM_3x9_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(3, 9, id, r), id + 1, 3, 9);
            singleValidation(DungeonDispatcher.getDungeonRoomByType(9, 3, id, r), id + 1, 9, 3);
        }
        //validate 5x5
        for (int id = 0; id < Constants.ROOM_5x5_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(5, 5, id, r), id + 1, 5, 5);
        }
        //validate 5x7, 7x5
        for (int id = 0; id < Constants.ROOM_5x7_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(5, 7, id, r), id + 1, 5, 7);
            singleValidation(DungeonDispatcher.getDungeonRoomByType(7, 5, id, r), id + 1, 7, 5);
        }
        //validate 5x9, 9x5
        for (int id = 0; id < Constants.ROOM_5x9_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(5, 9, id, r), id + 1, 5, 9);
            singleValidation(DungeonDispatcher.getDungeonRoomByType(9, 5, id, r), id + 1, 9, 5);
        }
        //validate 5x11, 11x5
        for (int id = 0; id < Constants.ROOM_5x11_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(5, 11, id, r), id + 1, 5, 11);
            singleValidation(DungeonDispatcher.getDungeonRoomByType(11, 5, id, r), id + 1, 11, 5);
        }
        //validate 7x7
        for (int id = 0; id < Constants.ROOM_7x7_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(7, 7, id, r), id + 1, 7, 7);
        }
        //validate 7x9, 9x7
        for (int id = 0; id < Constants.ROOM_7x9_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(7, 9, id, r), id + 1, 7, 9);
            singleValidation(DungeonDispatcher.getDungeonRoomByType(9, 7, id, r), id + 1, 9, 7);
        }
        //validate 7x11, 11x7
        for (int id = 0; id < Constants.ROOM_7x11_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(7, 11, id, r), id + 1, 7, 11);
            singleValidation(DungeonDispatcher.getDungeonRoomByType(11, 7, id, r), id + 1, 11, 7);
        }
        //validate 9x9
        for (int id = 0; id < Constants.ROOM_9x9_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(9, 9, id, r), id + 1, 9, 9);
        }
        //validate 9x11, 11x9
        for (int id = 0; id < Constants.ROOM_9x11_COUNT; id++)
        {
            singleValidation(DungeonDispatcher.getDungeonRoomByType(9, 11, id, r), id + 1, 9, 11);
            singleValidation(DungeonDispatcher.getDungeonRoomByType(11, 9, id, r), id + 1, 11, 9);
        }
    }