Beispiel #1
0
 def setUp(self):
     self.dungeonMap = Dungeon("basic_dungeon.txt")
Beispiel #2
0
 def setUp(self):
     self.crackhag_orc = orc.Orc("Crackhag", 120, True, 120, 1.5)
     self.bron_hero = hero.Hero("Bron", 120, "DragonSlayer", True, 120)
     self.map = Dungeon("dungeon.txt")
Beispiel #3
0
 def setUp(self):
     self.filepath = "basic_dungeon.txt"
     self.dun = Dungeon(self.filepath)
Beispiel #4
0
    Item("some weird nonalcoholic root beer-lookin' alien drink", 8, True),
    Item("half a horse leg", 1, False),
    Item("top quality alien oxygen", 0, False)
]

dandy_dialogue = [
    'You think you can defeat me? The dandiest in the west?',
    "I'm never gonna give you up, kid", "*alien screeching*",
    "You're done, kid",
    "Man, you've gone a long way. Too bad I'm gonna murder you tonight",
    "Y'know they're comin' for ya, right? The council?"
]

if __name__ == '__main__':
    send_text(opening)
    dungeon = Dungeon()
    player = Player('Player', 24, 11)
    directions = ['North', 'Yeast', 'South', 'West']

    while True:
        break
        current_room = dungeon.check_room(dungeon.player_position)
        surrounding = dungeon.check_for_surrounding(dungeon.player_position)

        if current_room == True:
            break

        # Battle!
        if type(current_room) is Enemy:
            current_enemy = current_room
            in_battle = True
Beispiel #5
0
import svgwrite

from dungeon import Dungeon

# Setup Parameters
paper_dimensions = {"A4p":( 595,  842),
                    "A4l":( 842,  595),
                    "A3p":( 842, 1191),
                    "A3l":(1191,  842)}
width, height = paper_dimensions["A3l"]
square = 14.2
background_color = svgwrite.rgb(9, 46, 61, '%')
corridor_color = svgwrite.rgb(100, 100, 100, '%')

# Make Dungeons
dungeon = Dungeon(width=int(width/square), height=int(height/square))
dungeon.build_dungeon(max_iterations=400)

# Setup Drawing
print("Setting up drawing")
dwg = svgwrite.Drawing('output/dungeon_test.svg',
                    size=(width, height),
                    viewBox=(0,0,width, height),
                    profile='tiny')

# Draw Background
background = dwg.rect((0, 0), (width, height))
background.fill(color=background_color)
dwg.add(background)

# Draw Origin
Beispiel #6
0
    def setUp(self):
        self.spell = Spell(name="Fireball",
                           damage=5,
                           mana_cost=20,
                           cast_range=1)
        self.weapon = Weapon(name="The Axe of Destiny", damage=10)
        self.hero = Hero(name="Bron",
                         title="Dragonslayer",
                         health=100,
                         mana=100,
                         mana_regeneration_rate=2)
        self.map = [['S', '.', '#', '#', '.', '.', '.', '.', '.', 'T'],
                    ['#', 'T', '#', '#', '.', '.', '#', '#', '#', '.'],
                    ['#', '.', '#', '#', '#', 'E', '#', '#', '#', 'E'],
                    ['#', '.', 'E', '.', '.', '.', '#', '#', '#', '.'],
                    ['#', '#', '#', 'T', '#', 'T', '#', '#', '#', 'G']]

        self.enemies = {
            "2,5": {
                "damage": 10,
                "health": 40,
                "mana": 20,
                "weapon": None,
                "spell": self.spell.to_json()
            },
            "2,9": {
                "damage": 10,
                "health": 40,
                "mana": 20,
                "weapon": self.weapon.to_json(),
                "spell": None
            },
            "3,2": {
                "damage": 10,
                "health": 40,
                "mana": 20,
                "weapon": None,
                "spell": None
            }
        }

        self.enemy1 = Enemy.from_json(self.enemies['2,5'])
        self.enemy2 = Enemy.from_json(self.enemies['2,9'])
        self.enemy3 = Enemy.from_json(self.enemies['3,2'])

        self.treasures = {
            "1,1": {
                "class": "Potion",
                "type": "mana",
                "amount": 50
            },
            "0,9": {
                "class": "Potion",
                "type": "health",
                "amount": 50
            },
            "4,3": {
                "class": "Weapon",
                "name": "The Axe of Destiny",
                "damage": 10
            },
            "4,5": {
                'class': "Spell",
                'name': 'Fireball',
                'damage': 5,
                'mana_cost': 20,
                'cast_range': 1
            }
        }

        self.tr1 = self.treasures['0,9']
        self.tr2 = self.treasures['1,1']
        self.tr3 = Weapon.from_json(self.treasures['4,3'])
        self.tr4 = Spell.from_json(self.treasures['4,5'])

        self.json_data = {
            "map": [
                "S.##.....T", "#T##..###.", "#.###E###E", "#.E...###.",
                "###T#T###G"
            ],
            "enemies":
            self.enemies,
            "treasures":
            self.treasures
        }

        self.dungeon = Dungeon(self.json_data)
Beispiel #7
0
# python3 game.py
#
# Written by: Simon Parsons
# Last Modified: 25/08/20

from world import World
from link import Link
from dungeon import Dungeon
import utils
import time

# How we set the game up. Create a world, then connect player and
# display to it.
gameWorld = World()
player = Link(gameWorld)
display = Dungeon(gameWorld)

# Now run...
while not (gameWorld.isEnded()):
    gameWorld.updateLink(player.makeMove())
    gameWorld.updateWumpus()  #if commented it’s static world
    # Uncomment this for a printout of world state
    # utils.printGameState(gameWorld)
    display.update()
    time.sleep(1)

if gameWorld.status == utils.State.WON:
    print("You won!")
else:
    print("You lost!")
Beispiel #8
0
from dungeon import Dungeon
from hero import Hero
from ork import Ork
from weapon import Weapon

d = Dungeon('dungeon.txt')
hero = Hero('Manson', 120, 'Captain')
orc = Ork('FishHead', 100, 1.01)
orc.weapon = Weapon('Axe', 12, 0.2)
hero.weapon = Weapon('Gun', 20, 0.1)
print(hero.known_as() + " IS HERE")
print(d.move("FishHead", 'right'))
d.spawn('Manson', hero)
d.spawn('FishHead', orc)
d.move('Manson', 'right')
d.move('Manson', 'down')
d.move('Manson', 'down')
d.move('Manson', 'down')
d.move('Manson', 'right')
d.move('Manson', 'right')
d.move('Manson', 'right')
d.move('Manson', 'right')
d.move('Manson', 'up')
d.move('Manson', 'up')
d.move('Manson', 'up')
d.move('Manson', 'right')
d.move('FishHead', 'up')
d.move('FishHead', 'up')
d.move('FishHead', 'up')
d.move('FishHead', 'up')
d.move('FishHead', 'left')
Beispiel #9
0
 def __init__(self):
     super(GameStateDummy, self).__init__()
     self.dungeon = Dungeon(self)
     self.player = new_player(self)
     self.player.description.name = "Mr. Test Hero"
     reset_globals(self.player)
Beispiel #10
0
    def playing(self):
        def resize_image(event):
            new_width = event.width
            new_height = event.height

            image = copy_of_image.resize((new_width, new_height))
            photo = ImageTk.PhotoImage(image)

            label.config(image=photo)
            label.image = photo  # avoid garbage collection

        def what_is_your_name():
            self.__player_name = askstring(HD_DOOM, 'Identify Yourself!')
            if self.__player_name is None:
                showinfo(
                    'THE Dungeon OF Doom',
                    "Don't be shy. Name is required to the start the game !!!")
            else:
                self.game_active()

        def how_to():
            messagebox.showinfo("THE Dungeon OF Doom", HOWTOPLAY)

        # ----------------------------------------------------
        # ------------- Introduction Page --------------------
        # ----------------------------------------------------
        copy_of_image = Image.open("wizard.jpg")
        photo = ImageTk.PhotoImage(copy_of_image)

        label = Label(frame, image=photo)
        label.place(x=0, y=0, relwidth=1, relheight=1)
        label.bind('<Configure>', resize_image)

        center_frame = Frame(frame,
                             relief='raised',
                             borderwidth=8,
                             bg=BGB,
                             width=80)
        center_frame.place(relx=.5, rely=.5, anchor=CENTER)

        # ---------------- introduction -----------------
        Label(center_frame, text=INTRO, width=60, bg=BGB, fg=FGY).pack()

        # ------------- "Let's the game begin..." buttons --------------------
        bottom_frame = Frame(tk)
        bottom_frame.pack(side=BOTTOM)
        start_button = Button(center_frame,
                              text="CLICK TO START",
                              bg=BGW,
                              font=FONT,
                              command=what_is_your_name)

        start_button.pack(side=BOTTOM)

        # ----------------------------------------------------------------------------
        # ------------ After get a play name, start the game -------------------------
        # ----------------------------------------------------------------------------
        if self.__player_name != '':

            center_frame.pack_forget()
            copy_of_image = Image.open("Maze.jpg")
            photo = ImageTk.PhotoImage(copy_of_image)

            label = Label(frame, image=photo)
            label.place(x=0, y=0, relwidth=1, relheight=1)
            label.bind('<Configure>', resize_image)

            center_frame = Frame(frame,
                                 relief='raised',
                                 borderwidth=5,
                                 bg=BGB,
                                 width=80)
            center_frame.place(relx=.5, rely=.5, anchor=CENTER)

            howto_button = Button(frame,
                                  text="How to play...",
                                  bg=BGW,
                                  font=FONT,
                                  command=how_to)
            howto_button.pack(side=BOTTOM)

            # -----------------------------------------------------------
            # ----------------- Difficulty Level ------------------------
            # -----------------------------------------------------------

            Label(center_frame,
                  text=self.__player_name,
                  bg=BGB,
                  fg=FGY,
                  font=FONT).pack()
            Label(center_frame,
                  text="You are about to enter THE DUNGEON OF DOOM.",
                  bg=BGB,
                  fg=FGY,
                  font=FONT).pack()
            Label(center_frame,
                  text="Select a difficulty from 1 (Easy) to 5 (Hard)",
                  bg=BGB,
                  fg=FGY,
                  font=FONT).pack()
            Label(center_frame, bg=BGB).pack()

            # ------------ Get player input on the difficult Level  ------------------
            player_level = Entry(center_frame)
            player_level.pack()

            Label(center_frame, bg=BGB).pack()  # create space in between

            def get_level():
                self.__difficult_level = player_level.get()
                tk.after(20, self.game_active())

            btn_start = Button(center_frame,
                               text="GO",
                               bg=BGW,
                               fg=FGB,
                               font=FONT_B,
                               command=get_level)
            btn_start.pack()

            # -------------------------------------------------
            # ---------------- Start Playing ------------------
            # -------------------------------------------------
            if 0 < int(self.__difficult_level) < 6:

                # ---------- Clean every things in the frame --------
                center_frame.pack_forget()

                # -------- Change the background -------
                copy_of_image = Image.open("Pillars.jpg")
                photo = ImageTk.PhotoImage(copy_of_image)

                label = Label(frame, image=photo)
                label.place(x=0, y=0, relwidth=1, relheight=1)
                label.bind('<Configure>', resize_image)

                # -------- put it in the center of the frame --------
                center_frame = Frame(frame,
                                     relief='raised',
                                     borderwidth=5,
                                     bg=BGB,
                                     width=80)
                center_frame.place(relx=.5, rely=.5, anchor=CENTER)

                # ------------------ Difficult Level Maze -------------------
                game_board = Dungeon(5, 5, 0, 0)
                if int(self.__difficult_level) == 1:
                    game_board = Dungeon(5, 5, 0, 0)
                elif int(self.__difficult_level) == 2:
                    game_board = Dungeon(6, 6, 0, 0)
                elif int(self.__difficult_level) == 3:
                    game_board = Dungeon(7, 7, 0, 0)
                elif int(self.__difficult_level) == 4:
                    game_board = Dungeon(8, 8, 0, 0)
                elif int(self.__difficult_level) == 5:
                    game_board = Dungeon(10, 10, 0, 0)
                else:
                    game_board = Dungeon(5, 5, 0, 0)

                game_board.make_dungeon()
                game_board.place_dungeon_items()
                # -------- To Do -----------
                # while game_board.traverse() is not True:
                #     game_board.make_dungeon()
                #     game_board.place_dungeon_items()

                Label(center_frame,
                      text=game_board,
                      bg=BGB,
                      fg=FGY,
                      font=("Courier New", 18)).pack()

                # ------------------- Show the Items in the Dungeon --------------------
                bottom_frame1 = Frame(tk)
                bottom_frame1.pack(side=TOP)

                # ---------------------- if not MAC computer, uncomment this -----------------------
                # Button(bottom_frame, text="Pillar A", fg=FGG).pack(side=LEFT)
                # Button(bottom_frame, text="Pillar E", fg=FGG).pack(side=LEFT)
                # Button(bottom_frame, text="Pillar I", fg=FGG).pack(side=LEFT)
                # Button(bottom_frame, text="Pillar P", fg=FGG).pack(side=LEFT)

                Button(bottom_frame1,
                       text="Use HEALING Potion",
                       highlightbackground='#3E4149').pack(side=LEFT)
                Button(bottom_frame1,
                       text="Use VISION Potion",
                       highlightbackground='#3E4149').pack(side=LEFT)
                Button(bottom_frame1,
                       text="Map Key",
                       highlightbackground='#3E4149').pack(side=LEFT)
                Button(bottom_frame1, text="       ", bd=0).pack(side=LEFT)

                bottom_frame2 = Frame(tk)
                bottom_frame2.pack(side=TOP)
                Button(bottom_frame2,
                       text="Move Up",
                       highlightbackground='#3E4149').pack(side=LEFT)
                Button(bottom_frame2,
                       text="Move Down",
                       highlightbackground='#3E4149').pack(side=LEFT)
                Button(bottom_frame2,
                       text="Move Left",
                       highlightbackground='#3E4149').pack(side=LEFT)
                Button(bottom_frame2,
                       text="Move Right",
                       highlightbackground='#3E4149').pack(side=LEFT)

                # ------------------ Place "How to Play" button -------------------
                Button(bottom_frame2,
                       text="How to play",
                       highlightbackground='#3E4149',
                       command=how_to).pack(side=LEFT)

                def exit_game():
                    tk.quit()

                Button(bottom_frame2,
                       text="Exit The Game",
                       highlightbackground='#3E4149',
                       command=exit_game).pack(side=LEFT)
Beispiel #11
0
 def __init__(self, player_name=""):
     super(GameState, self).__init__(player_name)
     self.dungeon = Dungeon(self)
     self._init_player_position()
Beispiel #12
0
def main():
    print('Starting the dungeon.')
    settings.dungeon = Dungeon()
    settings.dungeon.run()
Beispiel #13
0
def generate_dungeon_(layouts_,
                      layout_mods,
                      tilesets,
                      rw,
                      rh,
                      stage=None,
                      constraints=None):
    if stage == None:
        stage = 0

    if constraints == None:
        constraints = {
            "total_rooms": 8,
            "max_walk_connections": 4,
            "start_max_walk": 3,
            "end_max_walk": 1
        }

    stages = {
        "Farmhouse": 0,
        "Bubbas Basement": 1,
        "The Cave": 2,
        "Trailer Park": 3
    }

    rstages = {j: k for k, j in stages.items()}

    stage_name = rstages[stage]

    shortcuts = {
        "Farmhouse": "farm",
        "Bubbas Basement": "bubbas",
        "The Cave": "cave",
        "Trailer Park": "park"
    }

    short = shortcuts[stage_name]

    l0 = [
        "Sandra's Farmhouse Room 1", "Sandra's Farmhouse Room 2",
        "Sandra's Farmhouse Room 3", "Sandra's Farmhouse Room 4",
        "Sandra's Farmhouse Room 5", "Sandra's Farmhouse Room 6",
        "Sandra's Farmhouse Room 7", "Sandra's Farmhouse Room 8",
        "Sandra's Farmhouse Room 9", "Sandra's Farmhouse Room 10",
        "Sandra's Farmhouse Room 11", "Test Farmhouse Room 1",
        "Test Farmhouse Room 2", "Test Farmhouse Room 3"
    ]

    l1 = []
    l1 = l0

    l2 = []
    l2 = l0

    l3 = []
    l3 = l0

    layouts_belonging = l0, l1, l2, l3

    layouts_old = layouts_
    layouts = {k: layouts_[k] for k in layouts_belonging[stage]}

    lm_halls_ = {
        "west": "hallway_left",
        "east": "hallway_right",
        "north": "hallway_up",
        "south": "hallway_down"
    }

    lm_halls = {}
    for k, i in lm_halls_.items():
        new_entry = None
        for kj, ij in layout_mods.items():
            if (i in kj) and (short in kj):
                new_entry = kj
                break
        lm_halls[k] = new_entry

    # this right here is just a token placeholder
    # intended for
    # actual visual changes can be made in tiled
    # there still needs to be logic applied to all
    # of these wherever the rooms are actually "setup"
    # i.e. loot rooms w/ chest should place a chest
    # that actually keeps track of a chest() object
    # and shop rooms should load a shopkeeper unit
    # and place him in the middle
    # and rest rooms should load the bed

    # this is just for additional visual variation
    lm_mid_farm = {
        "shop room": [
            "shop1_farm", "shop2_farm", "shop3_farm", "shop4_farm",
            "shop5_farm", "shop6_farm"
        ],
        "loot room": [
            "loot1_farm", "loot2_farm", "loot3_farm", "loot4_farm",
            "loot5_farm", "loot6_farm", "loot7_farm"
        ],
        "rest room":
        ["rest2_farm", "rest3_farm", "rest4_farm", "rest5_farm", "rest6_farm"]
    }

    lm_mid_trans = {
        0: lm_mid_farm,
        1: lm_mid_farm,
        2: lm_mid_farm,
        3: lm_mid_farm
    }

    lm_mid = lm_mid_trans[stage]

    # note: all enemy rooms should have a chest
    # i.e. be loot rooms
    # at least, probably?
    # make it like this; if it IS a loot room, then
    # theres a 90% chance it also has enemies

    # the following are potential room types:

    room_types = [
        "starting room", "loot room", "rest room", "shop room", "boss room"
    ]

    starting_room = None

    # create rooms & path

    con = conx, cony = 7, 7
    sx, sy = 3, 6

    gen_rooms = constraints["total_rooms"]

    dung_list = [[None for y in range(cony)] for x in range(conx)]

    x, y = sx, sy

    start_room = make_a_room(layouts, tilesets)
    start_room.grid_pos = x, y
    # start_room.room_id = 0

    pp = [start_room]
    dung_list[x][y] = start_room
    ar = []

    rn = 0
    while rn <= gen_rooms - 1:
        # shuffle list of potential rooms
        shuffle(pp)
        # and grab one
        cr = pp.pop(0)

        cr.layout_mods = layout_mods

        # set room id
        cr.room_id = rn
        # increment room number variable
        rn = rn + 1

        # decide room type (shop, loot, rest)
        rt_sub = room_types[1:4]
        # 80% loot/enemy, 10 % shops, 10% rest
        pdist = [0.8, 0.1, 0.1]
        rt_choice = weighed_choice([i for i in range(len(rt_sub))], p=pdist)
        rt = rt_sub[rt_choice]
        cr.room_type = rt

        # if it's a loot room, then it has a 90% chance of have enemies
        if rt == "loot room" and random() >= 0.1:
            cr.has_enemies = True
        else:
            cr.has_enemies = False

        # danger rating
        if cr.has_enemies == True:
            cr.danger_rating = choice((1, 2, 3))
        else:
            cr.danger_rating = 0

        # decide layout mod
        lm = choice(lm_mid[rt])
        cr.layout_mod = lm
        cr.layout_mod_path = layout_mods[lm]

        # add room to actual rooms in dungeon
        ar.append(cr)

        # now branch out and find new potential rooms
        ds = get_directions(cr, dung_list, con)
        if "starting_directions" in constraints and len(ar) == 1:
            dorients = constraints["starting_directions"]
            new_ds = []
            for d_ in ds:
                if d_[1] in dorients:
                    new_ds.append(d_)
            ds = new_ds
            go_n = len(ds)
        else:
            shuffle(ds)
            nds = len(ds)
            if nds == 0:
                go_n = 0
            elif nds == 1:
                go_n = 1
            else:
                go_n = randint(1, nds)
            already_connected = cr.get_n_connections()
            if len(ar) == 1:
                go_n = min(go_n,
                           constraints["start_max_walk"] - already_connected)
            elif len(ar) == gen_rooms:
                go_n = min(go_n,
                           constraints["end_max_walk"] - already_connected)
            else:
                go_n = min(
                    go_n,
                    constraints["max_walk_connections"] - already_connected)
        for i in range(go_n):

            ads = ds.pop(0)
            nr = make_a_room(layouts, tilesets)
            nr.grid_pos = ads[0]
            orient = ads[1]
            sindx = sindy = None
            if orient in ("north", "south"):
                room_placement_range = 2, 26
                sindx = randint(*room_placement_range)
            elif orient in ("east", "west"):
                room_placement_range = 3, 7
                sindy = randint(*room_placement_range)
            if orient == "north":
                cr.north = nr
                tc = lm_halls["north"]
                cr.connectors["north"] = (tc, layout_mods[tc], sindx)
                nr.south = cr
                nr.connectors["south"] = (tc, layout_mods[tc], sindx)
            elif orient == "south":
                cr.south = nr
                tc = lm_halls["south"]
                cr.connectors["south"] = (tc, layout_mods[tc], sindx)
                nr.north = cr
                nr.connectors["north"] = (tc, layout_mods[tc], sindx)
            elif orient == "east":
                cr.east = nr
                tc = lm_halls["east"]
                cr.connectors["east"] = (tc, layout_mods[tc], sindy)
                nr.west = cr
                nr.connectors["west"] = (tc, layout_mods[tc], sindy)
            elif orient == "west":
                cr.west = nr
                tc = lm_halls["west"]
                cr.connectors["west"] = (tc, layout_mods[tc], sindy)
                nr.east = cr
                nr.connectors["east"] = (tc, layout_mods[tc], sindy)
            dung_list[ads[0][0]][ads[0][1]] = nr

            pp.append(nr)

        if len(pp) == 0:
            for r in ar:
                ds = get_directions(r, dung_list, con)
                shuffle(ds)
                if len(ds) == 0:
                    continue

                while len(ds) > 0:
                    ads = ds.pop(0)
                    nr = make_a_room(layouts, tilesets)
                    nr.grid_pos = ads[0]
                    orient = ads[1]
                    sindx = sindy = None
                    if orient in ("north", "south"):
                        room_placement_range = 2, 26
                        sindx = randint(*room_placement_range)
                    elif orient in ("east", "west"):
                        room_placement_range = 3, 7
                        sindy = randint(*room_placement_range)
                    if orient == "north":
                        r.north = nr
                        tc = lm_halls["north"]
                        r.connectors["north"] = (tc, layout_mods[tc], sindx)
                        nr.south = r
                        nr.connectors["south"] = (tc, layout_mods[tc], sindx)
                    elif orient == "south":
                        r.south = nr
                        tc = lm_halls["south"]
                        r.connectors["south"] = (tc, layout_mods[tc], sindx)
                        nr.north = r
                        nr.connectors["north"] = (tc, layout_mods[tc], sindx)
                    elif orient == "east":
                        r.east = nr
                        tc = lm_halls["east"]
                        r.connectors["east"] = (tc, layout_mods[tc], sindy)
                        nr.west = r
                        nr.connectors["west"] = (tc, layout_mods[tc], sindy)
                    elif orient == "west":
                        r.west = nr
                        tc = lm_halls["west"]
                        r.connectors["west"] = (tc, layout_mods[tc], sindy)
                        nr.east = r
                        r.connectors["east"] = (tc, layout_mods[tc], sindy)
                    dung_list[ads[0][0]][ads[0][1]] = nr

                    pp.append(nr)

                break

    # remove "connections" to unused rooms
    for r in ar:
        if r.north not in ar:
            r.north = None
            if "north" in r.connectors.keys():
                del r.connectors["north"]
        if r.south not in ar:
            r.south = None
            if "south" in r.connectors.keys():
                del r.connectors["south"]
        if r.east not in ar:
            r.east = None
            if "east" in r.connectors.keys():
                del r.connectors["east"]
        if r.west not in ar:
            r.west = None
            if "west" in r.connectors.keys():
                del r.connectors["west"]

    dung = Dungeon()

    # set the dungeons rooms to the actual rooms
    dung.rooms = ar

    # set starting room
    dung.in_room = 0
    dung.rooms[0].room_type = "starting room"
    dung.rooms[0].has_enemies = False
    dung.rooms[0].unexplored = False
    dung.rooms[0].remove_layout_mod()
    dung.rooms[0].add_layout_mod("empty room", layout_mods["empty_room1_farm"])

    # set boss room
    # i.e. the room furthest away from starting room
    # using euclidian distance
    # and checking only the ones that have just one
    # connection
    # i.e. boss room = furthest room away in raw distance, which is also an end room
    end_rooms = []
    for r in ar:
        l = r.north, r.south, r.west, r.east
        n_conns = 4 - sum(1 for i in l if i == None)
        if n_conns == 1:
            end_rooms.append(r)

    legal_rooms = []
    ind = 0
    for r in ar:
        l = r.north, r.south, r.west, r.east
        n_conns = 4 - sum(1 for i in l if i == None)
        if ind == 0:
            if n_conns <= constraints["start_max_walk"]:
                legal_rooms.append(r)
        elif ind == gen_rooms - 1:
            if n_conns <= constraints["end_max_walk"]:
                legal_rooms.append(r)
        elif n_conns <= constraints["max_walk_connections"]:
            legal_rooms.append(r)
        ind += 1

    if len(legal_rooms) != gen_rooms:
        screwed_up = True
    else:
        screwed_up = False

    gdist = 0
    froom = dung.rooms[0]

    rhw, rhh = 32 / 2, 14 / 2
    gfr = dung.rooms[0]
    p1x, p1y = gfr.grid_pos
    p1 = p1x + rhw, p1y + rhh

    if len(end_rooms) == 0:
        p_boss_rooms = ar
    else:
        p_boss_rooms = end_rooms

    for er in p_boss_rooms:
        p2x, p2y = er.grid_pos
        p2 = p2x + rhw, p2y + rhh
        d = get_distance(p1, p2)
        if d > gdist:
            gdist = d
            froom = er

    froom.room_type = "boss room"
    froom.layout_name = "Farmhouse Boss Room"
    froom.layout_path = layouts_old["Farmhouse Boss Room"]
    froom.has_boss = True
    froom.has_enemies = False
    froom.danger_rating = 3
    froom.remove_layout_mod()

    dung.stage = stage
    dung.stage_name = stage_name

    dung.rw, dung.rh = rw, rh

    return dung, screwed_up
Beispiel #14
0
def rat_in_none_dungeon() -> Rat:
    """Returns a Rat object in a Dungeon that doesn't have anything more than a main room"""
    room_1 = Room('main room')
    d = Dungeon(room_1)
    rat = Rat(d, room_1)
    return rat
Beispiel #15
0
def main():
    parser = argparse.ArgumentParser(description="P0 Adventure")
    parser.add_argument(
        "--savefile",
        dest="savefile",
        default="game.json",
        help="The save file. default: 'game.json'",
    )
    parser.add_argument(
        "--new-game",
        dest="new_game",
        default=False,
        action="store_true",
        help="Create a new save file.",
    )
    parser.add_argument(
        "-b",
        dest="bonus_tasks",
        default=False,
        action="store_true",
        help="enable bonus tasks",
    )
    parser.add_argument(
        "--print-bonus",
        dest="print_bonus",
        default=False,
        action="store_true",
        help="print bonus task list and exit",
    )
    args = parser.parse_args()

    if args.print_bonus:
        print_bonus_tasks()
        return

    # your code starts here
    save = args.savefile
    if args.new_game:
        user = Player()
        user.createNewCharacter()
        gamedata = GameData(player=user, savefile=save, bonus_tasks=args.bonus_tasks)
        if args.bonus_tasks:
            totengraeber = Gravedigger()
            gamedata.gravedigger = totengraeber
            truhe = Chest()
            gamedata.chest = truhe

    else:
        gamedata = load_gamedata(save)
        user = gamedata.player
        if args.bonus_tasks:
            totengraeber = gamedata.gravedigger
            truhe = gamedata.chest

    schmied = Shopkeeper(name="blacksmith", inventory=blacksmith_items)
    druide = Shopkeeper(name="druid", inventory=druid_items)
    prog0 = Village(
        player=user, bonus_tasks=args.bonus_tasks, blacksmith=schmied, druid=druide
    )

    if args.bonus_tasks:
        prog0.gravedigger = totengraeber
        prog0.chest = truhe

    while True:
        user_choice = village(prog0)

        if user_choice == 5:
            dung0 = Dungeon(player=user, bonus_tasks=args.bonus_tasks)
            if args.bonus_tasks:
                dung0.gravedigger = totengraeber
            dungeon(dung0)
        elif user_choice == 6:
            save_gamedata(gamedata, save),
            print("Game saved to {}".format(save))
        elif user_choice == 0:
            quit(gamedata, save)
            break
        else:
            raise KeyError(
                "main.py Something went wrong with the user choosing what to do!"
            )

    sys.exit(0)