Ejemplo n.º 1
0
    def test_get_set(self):
        d = dungeon.Dungeon()
        d.resize(3, 4)

        d[(2, 3)] = dungeon.Cell.Floor(x=0, y=0)

        self.assertTrue(d[(2, 3)].isFloor())
Ejemplo n.º 2
0
 def test_move_left(self):
     self.dungeon_map = dungeon.Dungeon("dev_map.txt")
     self.dungeon_map.spawn("Heroic Human", self.human)
     self.assertTrue(self.dungeon_map.move("Heroic Human", "left"))
     self.assertEqual(
         "H.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S",
         self.dungeon_map.print_map())
Ejemplo n.º 3
0
def main():
    me = player.Player('Bori', 10, WEAPONS[DAGGER], SKILLS['DOUBLE_TROUBLE'])
    enemies = [give_monster('wolf') for i in range(3)]

    # Comment/Uncomment game/world depending on which one you want to try
    # world is the dungeon system, game is the combat system, they are not
    # joined together yet, untill then this what you can do
    world = dungeon.Dungeon(me, ROOMS)
    world.cmdloop()
Ejemplo n.º 4
0
def main():
    sys.path.append(os.getcwd())
    set_console_size()
    me = Player('Bori', 10, WEAPONS[BOW])
    enemies = [give_monster('wolf') for i in range(3)]

    # Comment/Uncomment game/world depending on which one you want to try
    # world is the dungeon system, game is the combat system, they are not
    # joined together yet, untill then this what you can do
    world = dungeon.Dungeon(me, ROOMS)
    world.cmdloop()
Ejemplo n.º 5
0
    def test_mapIndex(self):
        d = dungeon.Dungeon()
        d.resize(3, 4)
        self.assertEqual(d.mapIndex(0, 0), 0)
        self.assertEqual(d.mapIndex(1, 0), 1)
        self.assertEqual(d.mapIndex(2, 0), 2)
        self.assertEqual(d.mapIndex(3, 0), -1)

        self.assertEqual(d.mapIndex(0, 1), 3)
        self.assertEqual(d.mapIndex(1, 1), 4)
        self.assertEqual(d.mapIndex(2, 3), 11)
Ejemplo n.º 6
0
    def test_loadFromMemory_saveToMemory(self):
        # load from string
        raw = '5x3\n#####\n #..#\n#####'
        d = dungeon.Dungeon()
        self.assertTrue(d.loadFromMemory(raw))
        for c in d.cells:
            self.assertTrue(d.has(*c.pos))

        # save to string
        out = d.saveToMemory()
        self.assertEqual(raw, out)
Ejemplo n.º 7
0
    def test_has(self):
        d = dungeon.Dungeon()
        d.resize(3, 4)
        self.assertTrue(d.has(0, 0))
        self.assertTrue(d.has(2, 0))
        self.assertTrue(d.has(2, 3))
        self.assertTrue(d.has(0, 3))

        self.assertFalse(d.has(-1, 0))
        self.assertFalse(d.has(0, -1))
        self.assertFalse(d.has(3, 0))
        self.assertFalse(d.has(0, 4))
Ejemplo n.º 8
0
def tower_handler(self, event):
    """event handler of tower"""
    if self.tower.character_continue != None and self.tower.character_continue.is_visible == True:
        self.tower.character_continue.character_view_handler(
            self, event, self.tower.dungeon_alive_characters)
        return

    #moves the cursor up
    if event.type == KEYDOWN and event.key == K_UP:
        self.cursor_se.play()
        self.tower.menu -= 1
        if self.tower.menu < 0:
            self.tower.menu = MENU_MAX
    #moves the cursor down
    elif event.type == KEYDOWN and event.key == K_DOWN:
        self.cursor_se.play()
        self.tower.menu += 1
        if self.tower.menu > MENU_MAX:
            self.tower.menu = 0
    #select the item
    if event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_z
                                  or event.key == K_RETURN):
        if self.tower.menu == Tower.GO:
            if len(self.party.member) == 0: return
            self.game_state = DUNGEON
            for character in self.party.member:
                character.coordinate = [9, 19, 1]
                #character.coordinate = [6,10,4]
            self.dungeon = dungeon.Dungeon(character.coordinate[2])
            self.tower = None
        elif self.tower.menu == Tower.CONTINUE:
            if len(self.tower.dungeon_alive_characters) == 0: return

            self.tower.character_continue = character_view.Character_view(
                Rect(80, 60, 480, 360),
                character_view.Character_view.CONTINUE_DUNGEON)
            self.tower.character_continue.is_visible = True

        elif self.tower.menu == Tower.BACK:
            self.game_state = CITY
            self.tower.menu = Tower.GO
            self.tower = None
            self.city = city.City()
            self.city.menu = 6
        self.select_se.play()

    if event.type == KEYDOWN and (event.key == K_x):
        self.game_state = CITY
        self.tower.menu = Tower.GO
        self.tower = None
        self.city = city.City()
        self.city.menu = 6
        self.cancel_se.play()
Ejemplo n.º 9
0
 def __init__(self, down_stairs=None):
     self.dungeon = dungeon.Dungeon()
     self.tiles = self.dungeon.tiles
     self.valid_tiles = [
         tile for room in self.dungeon._rooms for tile in room.points
     ]
     self.empty_tiles = [
         tile for tile in self.valid_tiles if self.is_empty(tile)
     ]
     self.stair_limit = 4
     if down_stairs is None:
         self.up_stairs = self.stair_gen("up")
     self.down_stairs = self.stair_gen("down")
Ejemplo n.º 10
0
def main():
    sys.path.append(os.getcwd())
    set_console_size()
    yername = input('What is your name?> ')
    classtype = ""
    while not (classtype in ['1', '2', '3', 'cheat']):
        classtype = input(
            "Pick Your Class:\n1) Daggerman\n2) Armorlady\n3) Richtwitch\n#> ")
    me = Player(yername, 10, WEAPONS[FIST])

    world = dungeon.Dungeon(me, ROOMS)
    world.setClass(classtype)
    world.cmdloop()
Ejemplo n.º 11
0
def main(stdscr):
    stdscr.clear()
    curses.curs_set(False)

    #init colour pairs
    for fg in range(8):
        for bg in range(8):
            curses.init_pair(1 + 8 * fg + bg, fg, bg)

    f = open("debug.log", "w")
    f.close()

    EM = entities.EntityManager()
    EM.create_entity({
        "controlled": True,
        "p_pos": (3, 7),
        "physical": True,
        "r_char": "@",
        "r_pos": (3, 7),
        "r_prio": 900,
        "camera": True,
        "health": 30,
        "attack_dmg": 6,
        "blood": 1000,
        "r_colour": curses.COLOR_BLACK,
        "ap": 3,
        "max_ap": 3,
        "dijkstra_target": True
    })

    d_size = (100, 100)

    MS = main_screen.MainScreen(d_size[0], d_size[1], EM)

    SM = systems.SystemsManager(EM, stdscr, MS)

    dungeon.Dungeon(d_size, EM)

    stdscr.nodelay(True)

    #EM.load("derp")

    SM.event("refresh", {})

    quit = 0
    while not quit:
        quit = SM.update_all()

    EM.save("derp")

    stdscr.refresh()
Ejemplo n.º 12
0
    def test_resize(self):
        d = dungeon.Dungeon()

        # resize fills with void
        d.resize(5, 10)
        self.assertEqual(d.size, (5, 10))
        self.assertEqual(len(d.cells), 5 * 10)
        for c in d.cells:
            self.assertTrue(c.isVoid())

        # resize resets all cells
        for c in d.cells:
            c = dungeon.Cell.Floor(x=0, y=0)
        d.resize(7, 12)
        self.assertEqual(d.size, (7, 12))
        self.assertEqual(len(d.cells), 7 * 12)
        for c in d.cells:
            self.assertTrue(c.isVoid())
Ejemplo n.º 13
0
    def test_getNeighbor(self):
        # load test dungeon
        raw = '''3x3
# #
 .#
#.#'''
        d = dungeon.Dungeon()
        self.assertTrue(d.loadFromMemory(raw))

        center = d[(1, 1)]
        north = center.getNeighbor(d, (0, -1))
        south = center.getNeighbor(d, (0, 1))
        east = center.getNeighbor(d, (1, 0))
        west = center.getNeighbor(d, (-1, 0))

        self.assertTrue(north.isVoid())
        self.assertTrue(south.isFloor())
        self.assertTrue(east.isWall())
        self.assertTrue(west.isVoid())
Ejemplo n.º 14
0
def main():
    curses.initscr()
    try:
        win = curses.newwin(0, 0)

        # get player name and race
        chargen = pc.CharacterCreation()
        chargen.askForName(win, 0, 0)
        name = win.getstr()  #.decode(encoding='utf-8')
        chargen.askForRace(win, 0, 1)
        race = win.getstr()

        #clear the screen
        win.clear()
        win.refresh()

        # instantiate classes
        d = dungeon.Dungeon()
        pcinfo = pc.PlayerCharacter(name, race)

        # prints character info
        win.addstr(2, 0, 'IS THIS THINE TRUE SELF?')
        pcinfo.drawTo(win, 5, 4)
        win.addstr(13, 9, 'Y or N')
        win.refresh()

        # waits for a keypress
        win.getch()

        # clear the screen
        win.clear()
        win.refresh()

        #draw dungeon map and close on keystroke
        d.drawTo(win, 0, 0)
        win.getch()
    except:
        curses.endwin()
    finally:
        pass
    # return terminal to normal
    curses.endwin()
Ejemplo n.º 15
0
    def test_loadFromFile_saveToFile(self):
        raw = '5x3\n#####\n #..#\n#####'
        d = dungeon.Dungeon()

        with tempfile.NamedTemporaryFile('w+') as tmp:
            # write file
            tmp.write(raw)
            tmp.flush()

            # load demo dungeon
            self.assertTrue(d.loadFromFile(tmp.name))
            for c in d.cells:
                self.assertTrue(d.has(*c.pos))

        with tempfile.NamedTemporaryFile('w+') as tmp:
            # save demo dungeon
            d.saveToFile(tmp.name)
            tmp.flush()

            # read file
            content = tmp.read()
            self.assertEqual(content, raw)
Ejemplo n.º 16
0
def process(game, action):
    # Create game, the hero, and dungeon to start the game.  Then
    # set the controller to the town.
    if action is None:
        print("creating character!!!")
        game = game_play.Game(str(uuid.uuid4()))
        game.character = characters.Character(characters.warrior)
        game.dungeon = dungeon.Dungeon()
        game.current_controller = 'game_play.start_game'
        db.save_game(game.game_id, game)

        contents = "The city of Thordon was once a great city, with unimaginable wealth and riches. So much so that " \
                   "to protect their piles of gold they cut deep into the mountain a labyrinth. This maze of " \
                   "corridors and rooms were heavily guarded and laden with traps discouraging the best of thieves. " \
                   "All was well until the dragon came. She came screeching from the sky, her fire laid waste to the " \
                   "town and death was everywhere. She made the labyrinth her home, and as the years went by, " \
                   "wild and evil things moved in. Only a small shell of a town now remains, waiting... hoping… " \
                   "for a hero to free Thordon from its curse and return it to its glory. "

        return screen.paint_one_pane(
            title_image=images.intro_scroll,
            contents=contents,
            contents_image=None,
            commands=
            "Please provide your gamer-tag (for display on the leaderboard):",
            sound=None,
            delay=0,
            interaction_type='enter_press',
            animation=None,
            game_id=game.game_id)

    else:
        # Record the name of the character and move forward.
        game.gamer_tag = action
        db.save_game(game.game_id, game)
        game.current_controller = 'game_play.set_game_mode'
        return set_game_mode.process(game, None)
Ejemplo n.º 17
0
    def character_view_handler(self, game_self, event, character):
        if event.type == KEYDOWN and event.key == K_x:
            self.menu = 0
            self.page = 0
            self.is_visible = False

        if event.type == KEYDOWN and event.key == K_UP:  #moves the cursor up
            self.menu -= 1
            if self.menu < 0:
                self.menu = 0
        elif event.type == KEYDOWN and event.key == K_DOWN:
            if len(character) > self.menu + self.page * 10 + 1:
                self.menu += 1
                if self.menu > self.MENU_MAX:
                    self.menu = self.MENU_MAX
        elif event.type == KEYDOWN and event.key == K_RIGHT:
            if len(character) > (self.page + 1) * 10:
                self.page += 1
                self.menu = 0
        elif event.type == KEYDOWN and event.key == K_LEFT:
            if self.page > 0:
                self.page -= 1
                self.menu = 0

        elif event.type == KEYDOWN and (event.key == K_SPACE or event.key
                                        == K_z or event.key == K_RETURN):
            if len(character) == 0: return
            if self.instruction == self.DELETE:
                game_self.castle.delete_confirm.is_visible = True
            elif self.instruction == self.RENAME:
                character_name_message = u"名前を入力してください(8文字制限)"
                message_title = u"名前入力"
                fieldnames = [u"名前"]
                fieldvalues = []

                fieldvalues = easygui.multenterbox(character_name_message,
                                                   message_title, fieldnames)

                if (fieldvalues != None):
                    #if length is > 8 or empty string, then re-enter
                    if len(fieldvalues[0]) > 8 or len(fieldvalues[0]) == 0:
                        return
                    #if it includes spaces, then also re-enter
                    if fieldvalues[0][0] == " ":
                        return
                if fieldvalues == None: return

                character[game_self.castle.character_rename.menu +
                          game_self.castle.character_rename.page *
                          10].name = u"" + fieldvalues[0]

            elif self.instruction == self.ADD:
                if len(game_self.party.member) < 6:
                    if (game_self.party.alignment >= 0 and
                            game_self.characters[game_self.bar.party_add.menu +
                                                 game_self.bar.party_add.page *
                                                 10].alignment > 0
                        ) or (
                            game_self.party.alignment <= 0 and
                            game_self.characters[game_self.bar.party_add.menu +
                                                 game_self.bar.party_add.page *
                                                 10].alignment < 0
                        ) or game_self.characters[
                            game_self.bar.party_add.menu +
                            game_self.bar.party_add.page * 10].alignment == 0:
                        game_self.party.member.append(
                            game_self.characters[game_self.bar.party_add.menu +
                                                 game_self.bar.party_add.page *
                                                 10])
                        game_self.party.alignment += game_self.characters[
                            game_self.bar.party_add.menu +
                            game_self.bar.party_add.page * 10].alignment
                        print game_self.party.alignment
                        del game_self.characters[game_self.bar.party_add.menu +
                                                 game_self.bar.party_add.page *
                                                 10]
                        if (game_self.bar.party_add.menu +
                                game_self.bar.party_add.page * 10) + 1 > len(
                                    character):
                            game_self.bar.party_add.menu -= 1
                            #if that page has no more, go back to previous page and set cursor to bottom
                            if game_self.bar.party_add.menu < 0:
                                game_self.bar.party_add.menu = 9
                                game_self.bar.party_add.page -= 1
            elif self.instruction == self.REMOVE:
                if len(game_self.party.member) > 0:
                    game_self.characters.append(game_self.party.member[
                        game_self.bar.party_remove.menu +
                        game_self.bar.party_remove.page * 10])
                    game_self.party.alignment -= game_self.party.member[
                        game_self.bar.party_remove.menu +
                        game_self.bar.party_remove.page * 10].alignment
                    del game_self.party.member[
                        game_self.bar.party_remove.menu +
                        game_self.bar.party_remove.page * 10]
                    if (game_self.bar.party_remove.menu +
                            game_self.bar.party_remove.page * 10) + 1 > len(
                                character):
                        game_self.bar.party_remove.menu -= 1
            elif self.instruction == self.CHECK:
                game_self.bar.status_view.is_visible = True
                game_self.bar.status_view.menu = self.menu

            elif self.instruction == self.CONTINUE_DUNGEON:
                #store current party in bar
                for chara in game_self.party.member:
                    game_self.characters.append(chara)

                game_self.party.member = []
                game_self.party.alignment = 0

                game_self.party.member.append(
                    game_self.tower.dungeon_alive_characters[self.menu +
                                                             self.page * 10])

                game_self.party.alignment += game_self.party.member[
                    0].alignment

                i = 0
                for chara in game_self.dungeon_characters:
                    if chara == game_self.party.member[0]:
                        del game_self.dungeon_characters[i]
                    i += 1

                #initialize dungeon
                game_self.game_state = DUNGEON
                game_self.dungeon = dungeon.Dungeon(
                    game_self.party.member[0].coordinate[2])
                game_self.tower = None
Ejemplo n.º 18
0
 def setUp(self):
     self.summoners_rift = dungeon.Dungeon("Sample_rift.txt")
Ejemplo n.º 19
0
def main():
    me = player.Player('Bori', 10, WEAPONS[DAGGER], SKILLS['DOUBLE_TROUBLE'])
    enemies = [give_monster('wolf') for i in range(3)]
    world = dungeon.Dungeon(me, ROOMS)
    world.cmdloop()
Ejemplo n.º 20
0
    hud = draw.Sprite2D(32, 32)
    hud.moveTo(640, 480)
    hud.centerTo(1.0, 1.0)
    hud.texture = heart

    weapon = draw.Sprite2D(196, 196)
    weapon.moveTo(420, 510)
    weapon.centerTo(0.5, 1.0)
    weapon.clip(0.0, 0.0, 0.25, 1.0)
    weapon.texture = sword

    weapon.animator = draw.FrameAnimator(weapon, 4, 8)

    # demo terrain
    d = dungeon.Dungeon()
    d.loadFromFile('demo.txt')
    renderer.loadDungeon(d)

    vb = dungeon.VertexBuilder()
    #vb.no_walls()
    vb.loadFromDungeon(d)

    next_fps_update = 0

    sprite1 = draw.Sprite3D()
    sprite1.moveTo(4.5, 0.0, 4.5)
    sprite1.centerTo(0.5, 0.0, 0.5)
    sprite1.texture = goblin
    sprite1.animator = draw.FrameAnimator(sprite1, 4, 8)
    sprite1.animator.start(loop=True)
Ejemplo n.º 21
0
def game_menu(window_width, window_height, framerate, surface):
    game_state = 'game'

    player_action = False

    surface.fill((0, 0, 0))

    clock = pygame.time.Clock()

    num_turns = 0
    '''
    # gui elements, console, etc
    gui = pygame_gui.UIManager((window_width, window_height), 'fonts/theme.json')

    console_rect = pygame.Rect(0, 0, window_width//2, window_height//4)
    console_text_rect = console_rect.copy()
    console_text_rect.width = console_text_rect.width - 30
    console_text_rect.height = console_text_rect.height - 60

    console_ui_window = pygame_gui.elements.UIWindow(rect=console_rect,
    manager=gui, window_display_title='Log', object_id='console_window',
    resizable=False, visible=True)
    console_ui_window.blendmode = 1
    console_ui_window.enable_close_button = False
    console_ui_window.rebuild()

    console_text = 'Can you find Big Mike?<br>Type ? for help.'
    console_text_box = pygame_gui.elements.UITextBox(
        html_text=console_text, relative_rect=console_text_rect, manager=gui,
        wrap_to_height=False, layer_starting_height=1, container=console_ui_window,
        parent_element=None, object_id='console_text_box', visible=1)
    console_text_box.blendmode = 1

    '''

    #console.out('Welcome to Hominidae!')
    #console.out('The legendary Big Mike awaits you!')
    #console.out('Press ? for help!')

    # dungeon stuff
    new_dungeon = dungeon.Dungeon()

    #tile_surface = pygame.Surface((window_width, window_height))

    console_surface = pygame.Surface((window_width // 2, window_height // 5))
    console = message.Message(console_surface, 5, assets.body_font)

    player_info_surface = pygame.Surface(
        (window_width // 5, window_height // 2))
    player_info = new_dungeon.player.get_info()
    player_info_text = message.TextList(player_info_surface, player_info,
                                        assets.body_font)

    player_health_bar = message.Bar('Health', new_dungeon.player.current_hp,
                                    new_dungeon.player.max_hp)

    player_inv_surface = pygame.Surface(
        (window_width // 5, window_height // 2))
    player_inv_text = message.TextList(player_inv_surface,
                                       new_dungeon.player.inv,
                                       assets.tiny_font)

    game_surface = pygame.Surface(
        (window_width - window_width // 5, window_height - window_height // 5))
    game_surface.fill(assets.game_background)

    map_surface = pygame.Surface((window_width // 3, window_height // 5))
    blip_player = False
    blip_player = new_dungeon.render_minimap(map_surface, blip_player)

    #blits
    player_info_text.out()
    player_health_bar.update(new_dungeon.player.current_hp, 16, 0,
                             player_info_surface)

    new_dungeon.render_proper(game_surface)
    surface.blit(game_surface, (0, 0))
    surface.blit(map_surface,
                 (window_width // 2, window_height - window_height // 5))
    surface.blit(player_info_surface, (window_width - window_width // 5, 16))
    surface.blit(player_inv_surface,
                 (window_width - window_width // 5, window_height // 2))
    surface.blit(console_surface, (0, window_height - window_height // 5))
    # menu render
    #console_text_box.set_active_effect('typing_appear')
    '''
    gui.update(0.0001)
    gui.draw_ui(surface)
    '''
    pygame.display.update()

    #'''
    # accurate FPS
    frame_time = []
    start_time = time.time()

    running = True
    while running:
        player_action = False

        # #print('FPS: ' + str(round(clock.get_fps(), 0)) + ', running: ' + str(running) + ', state: ' + str(game_state))
        #dT = clock.tick(framerate)/1000.0 # fps
        dT = clock.tick() / 1000.0  # TESTING MAX FRAMERATE

        # #print('dT : ' + str(dT))

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                game_state = 'main menu'
                return (running, game_state)

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_1:
                    new_dungeon.player.current_hp += 100

                if event.key == pygame.K_KP2:
                    player_action = new_dungeon.player.move(
                        new_dungeon, 1, 1, console)
                if event.key == pygame.K_KP4:
                    player_action = new_dungeon.player.move(
                        new_dungeon, -1, 1, console)
                if event.key == pygame.K_KP6:
                    player_action = new_dungeon.player.move(
                        new_dungeon, 1, -1, console)
                if event.key == pygame.K_KP8:
                    player_action = new_dungeon.player.move(
                        new_dungeon, -1, -1, console)
                if event.key == pygame.K_KP1:
                    player_action = new_dungeon.player.move(
                        new_dungeon, 0, 1, console)
                if event.key == pygame.K_KP3:
                    player_action = new_dungeon.player.move(
                        new_dungeon, 1, 0, console)
                if event.key == pygame.K_KP7:
                    player_action = new_dungeon.player.move(
                        new_dungeon, -1, 0, console)
                if event.key == pygame.K_KP9:
                    player_action = new_dungeon.player.move(
                        new_dungeon, 0, -1, console)

                if event.key == pygame.K_PERIOD or event.key == pygame.K_KP5:
                    console.out('waited')
                    player_action = True

                if event.key == pygame.K_c:  # toggle door
                    player_action = new_dungeon.toggle_door(console)

                if event.key == pygame.K_COMMA and pygame.key.get_mods(
                ) & pygame.KMOD_SHIFT:
                    player_action = new_dungeon.use_stairs('up', console)

                if event.key == pygame.K_PERIOD and pygame.key.get_mods(
                ) & pygame.KMOD_SHIFT:
                    player_action = new_dungeon.use_stairs('down', console)

                if event.key == pygame.K_g or event.key == pygame.K_COMMA:  # pick up item
                    player_action = new_dungeon.player.pickup(
                        new_dungeon, console)

                if event.key == pygame.K_d:  # drop item
                    player_action = new_dungeon.player.drop(
                        new_dungeon, console)

                if event.key == pygame.K_w:  # wield item
                    player_action = new_dungeon.player.wield(
                        new_dungeon, console)

                if event.key == pygame.K_s:  # sheathe item
                    player_action = new_dungeon.player.sheathe(
                        new_dungeon, console)

                if event.key == pygame.K_f:  # fling item
                    target = target_menu(
                        new_dungeon, player_inv_text, player_inv_surface,
                        player_info_surface, player_info_text, game_surface,
                        blip_player, map_surface, window_width, window_height,
                        console, console_surface, surface)
                    if target != None:
                        player_action = new_dungeon.player.fling(
                            new_dungeon, target, console)
                    else:
                        player_action = False
                if event.key == pygame.K_UP:  # select an item above the currently selected item
                    new_dungeon.player.select('up', player_inv_text,
                                              player_inv_surface, surface,
                                              window_width, window_height)

                if event.key == pygame.K_DOWN:  # select an item below the currently selected item
                    new_dungeon.player.select('down', player_inv_text,
                                              player_inv_surface, surface,
                                              window_width, window_height)

            if event.type == pygame.USEREVENT:  # gui events
                pass

            # menu render
            '''
            gui.process_events(event)
            '''

        if player_action:
            new_dungeon.player.process_conditions(new_dungeon, console)

            num_turns += 1
            '''MONSTER TURN'''
            for creature in new_dungeon.current_level.creature_list:
                creature.run_ai(new_dungeon, new_dungeon.find_fov(), console)
                creature.process_conditions(new_dungeon, console)
            '''
            console_text_box.kill()
            console_text = (new_dungeon.player.name + ' ' + player_action + '<br>' + console_text)
            console_text_box = pygame_gui.elements.UITextBox(
                html_text=console_text, relative_rect=console_text_rect, manager=gui,
                wrap_to_height=False, layer_starting_height=1, container=console_ui_window,
                parent_element=None, object_id='console_text_box', visible=1)
            console_text_box.blendmode = 1

            #'''

            # inv list
            player_info = new_dungeon.player.get_info()
            player_info_text = message.TextList(player_info_surface,
                                                player_info, assets.body_font)
            player_info_text.out()
            player_health_bar.update(new_dungeon.player.current_hp, 16, 0,
                                     player_info_surface)

            player_inv_text.out()

            game_surface.fill(assets.game_background)
            new_dungeon.render_proper(game_surface)
            blip_player = new_dungeon.render_minimap(map_surface, blip_player)
            surface.blit(game_surface, (0, 0))
            surface.blit(
                map_surface,
                (window_width // 2, window_height - window_height // 5))
            surface.blit(player_info_surface,
                         (window_width - window_width // 5, 16))
            surface.blit(
                player_inv_surface,
                (window_width - window_width // 5, window_height // 2))
            surface.blit(console_surface,
                         (0, window_height - window_height // 5))
            pygame.display.update()
            #'''
        #'''
        '''
        surface.blit(game_surface, (0, 0))# (16, 16))
        gui.update(dT)
        gui.draw_ui(surface)    
        pygame.display.update()
        #'''
        # new render strategy
        # 1. render tile surface ONCE
        # 2. if player does something
        #   3. move tile surface offset from player
        #   4. update entity renders offset from player
        #   5. update FOV
        # 6. always render GUI or only update during player idk yet

        end_time = time.time()
        time_taken = end_time - start_time
        start_time = end_time
        frame_time.append(time_taken)
        frame_time = frame_time[-20:]
        if sum(frame_time) != 0:
            fps = len(frame_time) / sum(frame_time)
            print(fps)
Ejemplo n.º 22
0
def tests():
    dungeon = d.Dungeon(DEFAULT_DIFFICULTY)
    dungeon.test()
Ejemplo n.º 23
0
 def test_init(self):
     d = dungeon.Dungeon()
     self.assertEqual(d.size, (0, 0))
     self.assertEqual(d.cells, list())
Ejemplo n.º 24
0
    def test_build(self):
        # load test dungeon
        raw = '''3x3
# #
 .#
#.#'''
        d = dungeon.Dungeon()
        self.assertTrue(d.loadFromMemory(raw))

        # monkeypatch for easier unittesting
        vb = dungeon.VertexBuilder()
        vb.floor = lambda x, y, z, w, h: ((x, y, z), ('F', w, h),
                                          (None, None, None, None))
        vb.northWall = lambda x, y, z, w, h: ((x, y, z), ('N', w, h),
                                              (None, None, None, None))
        vb.southWall = lambda x, y, z, w, h: ((x, y, z), ('S', w, h),
                                              (None, None, None, None))
        vb.westWall = lambda x, y, z, w, h: ((x, y, z), ('W', w, h),
                                             (None, None, None, None))
        vb.eastWall = lambda x, y, z, w, h: ((x, y, z), ('E', w, h),
                                             (None, None, None, None))

        # build dungeon
        self.assertTrue(vb.loadFromDungeon(d))
        for a, b, c in vb.data:  # only show in case of an error
            print(a, "\t", b, "\t", c)
        self.assertEqual(len(vb.data), 20)
        black = (0.0, 0.0, 0.0)
        # (1, 0) is void with walls in N/W/E
        self.assertEqual(vb.data[0], ((1, 0, 0), ('N', 3.0, 2.0),
                                      (None, None, None, None)))
        self.assertEqual(vb.data[1], ((1, 0, 0), ('W', 3.0, 2.0),
                                      (None, None, None, None)))
        self.assertEqual(vb.data[2], ((1, 0, 0), ('E', 3.0, 2.0),
                                      (None, None, None, None)))
        # and deep walls all around (colored black towards the pit)
        self.assertEqual(vb.data[3], ((1, 0, -1), ('N', 3.0, 2.0),
                                      (None, None, black, black)))
        self.assertEqual(vb.data[4], ((1, 0, -1), ('S', 3.0, 2.0),
                                      (None, None, black, black)))
        self.assertEqual(vb.data[5], ((1, 0, -1), ('W', 3.0, 2.0),
                                      (None, None, black, black)))
        self.assertEqual(vb.data[6], ((1, 0, -1), ('E', 3.0, 2.0),
                                      (None, None, black, black)))
        # (0, 1) is void with wall in N/W/S
        self.assertEqual(vb.data[7], ((0, 1, 0), ('N', 3.0, 2.0),
                                      (None, None, None, None)))
        self.assertEqual(vb.data[8], ((0, 1, 0), ('S', 3.0, 2.0),
                                      (None, None, None, None)))
        self.assertEqual(vb.data[9], ((0, 1, 0), ('W', 3.0, 2.0),
                                      (None, None, None, None)))
        # and deep walls all around (colored black towards the pit)
        self.assertEqual(vb.data[10], ((0, 1, -1), ('N', 3.0, 2.0),
                                       (None, None, black, black)))
        self.assertEqual(vb.data[11], ((0, 1, -1), ('S', 3.0, 2.0),
                                       (None, None, black, black)))
        self.assertEqual(vb.data[12], ((0, 1, -1), ('W', 3.0, 2.0),
                                       (None, None, black, black)))
        self.assertEqual(vb.data[13], ((0, 1, -1), ('E', 3.0, 2.0),
                                       (None, None, black, black)))
        # (1, 1) is floor with wall in E
        self.assertEqual(vb.data[14], ((1, 1, 0), ('F', 3.0, 2.0),
                                       (None, None, None, None)))
        self.assertEqual(vb.data[15], ((1, 1, 0), ('E', 3.0, 2.0),
                                       (None, None, None, None)))
        # (1, 2) is floor with walls in S/W/E
        self.assertEqual(vb.data[16], ((1, 2, 0), ('F', 3.0, 2.0),
                                       (None, None, None, None)))
        self.assertEqual(vb.data[17], ((1, 2, 0), ('S', 3.0, 2.0),
                                       (None, None, None, None)))
        self.assertEqual(vb.data[18], ((1, 2, 0), ('W', 3.0, 2.0),
                                       (None, None, None, None)))
        self.assertEqual(vb.data[19], ((1, 2, 0), ('E', 3.0, 2.0),
                                       (None, None, None, None)))
Ejemplo n.º 25
0
 def run(self, gamedata, *args):
     dun = dungeon.Dungeon(gamedata)
     dun_gd = dun.run()
     return LIST, dun_gd
Ejemplo n.º 26
0
def play():
    dungeon = d.Dungeon(DEFAULT_DIFFICULTY)
    admin = p.Player()
Ejemplo n.º 27
0
    def menu_handler(self, event, game_self):

        if self.item_window != None and self.item_window.is_visible == True:
            self.item_window.system_notify_window_handler(
                event, game_self, game_self.party.member)
            return
        elif self.magic_window != None and self.magic_window.is_visible == True:
            self.magic_window.system_notify_window_handler(
                event, game_self, game_self.party.member)
            return
        elif self.status_window != None and self.status_window.is_visible == True:
            self.status_window.system_notify_window_handler(
                event, game_self, game_self.party.member)
            return
        elif self.change_window != None and self.change_window.is_visible == True:
            self.change_window.system_notify_window_handler(
                event, game_self, self.temp_party1)
            return

        #moves the cursor up
        if event.type == KEYDOWN and event.key == K_UP:
            game_self.cursor_se.play()
            self.menu -= 1
            if self.menu < 0:
                self.menu = self.MENU_MAX

        #moves the cursor up
        if event.type == KEYDOWN and event.key == K_DOWN:
            game_self.cursor_se.play()
            self.menu += 1
            if self.menu > self.MENU_MAX:
                self.menu = 0

        if event.type == KEYDOWN and (event.key == K_z or event.key == K_SPACE
                                      or event.key == K_RETURN):
            game_self.select_se.play()
            if self.menu == self.ITEM:
                if len(game_self.party.member) > 0:
                    self.item_window = system_notify.System_notify_window(
                        Rect(200, 120, 340, 240),
                        system_notify.System_notify_window.USE_ITEM)
                    self.item_window.is_visible = True
            if self.menu == self.MAGIC:
                if len(game_self.party.member) > 0:
                    self.magic_window = system_notify.System_notify_window(
                        Rect(200, 120, 340, 240),
                        system_notify.System_notify_window.USE_MAGIC)
                    self.magic_window.is_visible = True
            if self.menu == self.STATUS:
                if len(game_self.party.member) > 0:
                    self.status_window = system_notify.System_notify_window(
                        Rect(200, 120, 340, 240),
                        system_notify.System_notify_window.VIEW_STATUS)
                    self.status_window.is_visible = True
            if self.menu == self.CHANGE:
                if len(game_self.party.member) > 0:
                    for character in game_self.party.member:
                        self.temp_party1.append(character)
                    self.change_window = system_notify.System_notify_window(
                        Rect(200, 120, 340, 240),
                        system_notify.System_notify_window.CHANGE_PARTY)
                    self.change_window.is_visible = True
            if self.menu == self.SETTINGS:

                character_name_message = u"パーティ名を入力してください"
                message_title = u"パーティ名入力"
                fieldnames = [u"パーティ名"]
                fieldvalues = []

                fieldvalues = easygui.multenterbox(character_name_message,
                                                   message_title, fieldnames)

                if (fieldvalues != None):
                    #if empty string, then re-enter
                    if len(fieldvalues[0]) == 0:
                        return
                    #if it includes spaces at front, then also re-enter
                    if fieldvalues[0][0] == " ":
                        return
                if fieldvalues == None: return
                game_self.party.party_name = u"" + fieldvalues[0]

            if self.menu == self.BACK:
                self.menu = self.ITEM
                if game_self.party.member == []:
                    game_self.game_state = CITY
                    game_self.city = city.City()
                    game_self.menu = None
                    return
                if game_self.party.member[0].coordinate != [-1, -1, -1]:
                    game_self.game_state = DUNGEON
                    game_self.menu = None
                    game_self.dungeon = dungeon.Dungeon(
                        game_self.party.member[0].coordinate[2])
                    game_self.dungeon.vertical_wall = game_self.vertical_wall_temp
                    game_self.dungeon.horizontal_wall = game_self.horizontal_wall_temp
                    game_self.dungeon.ground = game_self.ground_temp
                    game_self.dungeon.space = game_self.space_temp
                    game_self.dungeon.object = game_self.object_temp

                    #dungeon load????
                else:
                    game_self.game_state = CITY
                    game_self.city = city.City()
                    game_self.menu = None

        if event.type == KEYDOWN and (event.key == K_x):
            game_self.cancel_se.play()
            self.menu = self.ITEM
            if game_self.party.member == []:
                game_self.game_state = CITY
                game_self.city = city.City()
                game_self.menu = None
                return
            if game_self.party.member[0].coordinate != [-1, -1, -1]:
                game_self.game_state = DUNGEON
                game_self.menu = None
                game_self.dungeon = dungeon.Dungeon(
                    game_self.party.member[0].coordinate[2])

                game_self.dungeon.vertical_wall = game_self.vertical_wall_temp
                game_self.dungeon.horizontal_wall = game_self.horizontal_wall_temp
                game_self.dungeon.ground = game_self.ground_temp
                game_self.dungeon.space = game_self.space_temp
                game_self.dungeon.object = game_self.object_temp

                #dungeon load?????
            else:
                game_self.game_state = CITY
                game_self.city = city.City()
                game_self.menu = None
Ejemplo n.º 28
0
 def setUp(self):
     self.dungeon_map = dungeon.Dungeon("dungeon_map.txt")
     self.human = hero.Human("Dorah", 150, "the Explorer")
     self.orc = hero.Orc("Can't think of a name", 200, 1.2)
Ejemplo n.º 29
0
def dungeon_packer(d_dict, map=dungeon.test_dungeon):
    newDungeon = dungeon.Dungeon(d_dict, map)
    # set newDungeon first room.
    # method or some stuff.
    return newDungeon
Ejemplo n.º 30
0
 def setUp(self):
     self.dungeon = dungeon.Dungeon("basic_dungeon.txt")