当前位置: 首页>>代码示例>>Python>>正文


Python dungeon.Dungeon类代码示例

本文整理汇总了Python中dungeon.Dungeon的典型用法代码示例。如果您正苦于以下问题:Python Dungeon类的具体用法?Python Dungeon怎么用?Python Dungeon使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Dungeon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_smtg_test

class test_smtg_test(unittest.TestCase):
    """Testing the unit"""

    def setUp(self):
        self.filename = 'test_dng_map.txt'
        f = open(self.filename, "w")
        content_map = 'S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S'
        f.write(content_map)
        f.close()

        self.new_map = Dungeon(self.filename)

    def test_load_map(self):
        expected = 'S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S'
        self.assertEqual(expected, self.new_map.load_map())

    def test_map_to_matrix(self):
        expected = [['S', '.', '#', '#', '.', '.', '.', '.', '.', '.'], ['#', '.', '#', '#', '.', '.', '#', '#', '#', '.'], ['#', '.', '#', '#', '#', '.', '#', '#', '#', '.'], ['#', '.', '.', '.', '.', '.', '#', '#', '#', '.'], ['#', '#', '#', '.', '#', '#', '#', '#', '#', 'S']]

        self.assertEqual(expected, self.new_map.map_to_matrix())

    def tearDown(self):
        # fpath = os.getcwd()
        try:
            os.remove(self.filename)
        except OSError:
            print('No such file')
开发者ID:fyllmax,项目名称:Programming101,代码行数:27,代码来源:dungeon_test.py

示例2: TestDungeon

class TestDungeon(unittest.TestCase):
    def setUp(self):
        self.my_map = Dungeon("basic_dungeon.txt")

    #def test_map_dungeon(self):
     #   self.my_map.print_map()

    def test_spawn_hero(self):
        good_hero = hero.Hero("Sebastian", 100, "The great")
        self.assertTrue(self.my_map.spawn("The Great", good_hero))
    #    self.my_map.print_map()
        bad_orc = orc.Orc("Mudagog", 100, 1.4)
        self.assertTrue(self.my_map.spawn("The Badass", bad_orc))
    #    self.my_map.print_map()

    def test_move_hero(self):
        good_hero = hero.Hero("Sebastian", 100, "The great")
        self.assertTrue(self.my_map.spawn("The Great", good_hero))
    #    self.my_map.print_map()
        bad_orc = orc.Orc("Mudagog", 100, 1.4)
        self.assertTrue(self.my_map.spawn("The Badass", bad_orc))
    #    self.my_map.print_map()
        self.assertFalse(self.my_map.move("The Great", "up")) 
        self.assertFalse(self.my_map.move("The Great", "left")) 
        self.assertTrue(self.my_map.move("The Badass", "up")) 
        self.assertFalse(self.my_map.move("The Badass", "right")) 


        self.my_map.print_map()
开发者ID:GAngelov5,项目名称:HackBulgaria,代码行数:29,代码来源:test_dungeon.py

示例3: __init__

class Game:
    def __init__(self):
        self.screen = create_screen()

        self.tmp_dungeon = Dungeon(80, 20)
        self.tmp_dungeon.generate()
        self.dungeons = [self.tmp_dungeon]

        self.player = Player(*self.dungeons[0].up_stair)

    def play(self):
        self.screen.get_key()
        self.screen.draw_dungeon(self.dungeons[self.player.floor - 1], self.player)
        self.screen.push_message('Welcome to Necronomicon, my first roguelike...')

        while True:  # Main game loop
            char = self.screen.get_key()

            if char == 'q':  # Quit game
                quit = self.screen.ask_message('Do you really want to quit?')
                if quit.lower() in ['y', 'yes', 'yea']:
                    break

            elif char == '?':  # Show help
                self.screen.push_message('This is a fantastic game... :)')

            elif char in ['h', 'j', 'k', 'l', 'y', 'u', 'b', 'n', '.']:  # Movement
                success = self.player.move(char, self.dungeons[self.player.floor - 1])
                if success:
                    self.screen.draw_dungeon(self.dungeons[self.player.floor - 1], self.player)
                    self.screen.update_info(self.player)
                else:
                    self.screen.push_message('You can\'t go on this way')

            elif char == '>':
                if self.dungeons[self.player.floor - 1].cell(self.player.x, self.player.y).char == '>':
                    self.dungeons.append(Dungeon(80, 20))
                    self.player.floor += 1
                    self.dungeons[self.player.floor - 1].generate()
                    self.player.moves += 1
                    self.screen.update_info(self.player)
                    self.player.x, self.player.y = self.dungeons[self.player.floor - 1].up_stair
                    self.screen.draw_dungeon(self.dungeons[self.player.floor - 1], self.player)
                    self.screen.push_message('Welcome to the %d floor' % self.player.floor)
                else:
                    self.screen.push_message('There isn\'t down stairs here')

            elif char == '<':
                if self.dungeons[self.player.floor - 1].cell(self.player.x, self.player.y).char == '<':
                    if self.player.floor == 1:
                        self.screen.push_message('You can\'t escape from the dungeon')
                    else:
                        self.player.floor -= 1
                        self.player.moves += 1
                        self.player.x, self.player.y = self.dungeons[self.player.floor - 1].down_stair
                        self.screen.push_message('You returned at the %d dungeon' % self.player.floor)
                        self.screen.update_info(self.player)
                        self.screen.draw_dungeon(self.dungeons[self.player.floor - 1], self.player)
                else:
                    self.screen.push_message('There isn\'up stairs here')
开发者ID:andrea96,项目名称:necronomicon,代码行数:60,代码来源:game.py

示例4: setUp

    def setUp(self):
        self.filename = "basic_dungeon.txt"
        self.filename2 = "basic_dungeon2.txt"
        self.string = "..##.....S\n" \
            "#.##..###.\n" \
            "#.###.###.\n" \
            "#S....###.\n" \
            "###.#####.\n"
        self.string2 = "..##....SS\n" \
            "#.##..###.\n" \
            "#S###.###.\n" \
            "#S....###.\n" \
            "###.#####.\n"
        with open(self.filename, 'w+') as file:
            file.write(self.string)
        with open(self.filename2, "w+") as file:
            file.write(self.string2)
        self.dung = Dungeon(self.filename)
        self.dung2 = Dungeon(self.filename2)
        self.l = self.string2.split('\n')
        self.l.pop()
        self.list = []
        for line in self.l:
            self.list.append(list(line))

        self.test_orc = Orc("Garosh", 100, 1)
        self.test_hero = Hero("Varyan", 100, "test")
        self.spawn_orc = self.dung.spawn("player2", self.test_orc)
        self.spawn_hero = self.dung.spawn("player1", self.test_hero)
        self.spawn_orc2 = self.dung.spawn("player3", self.test_orc)
开发者ID:nkgeorgiev,项目名称:HackBulgaria---Programming101---2,代码行数:30,代码来源:dungeon_test.py

示例5: moddungeon

def moddungeon(request, did):
    d = Dungeon()
    d.load(did)
    monster_infos = []
    for i in MonsterDB.objects.all():
        mon = {}
        mon["id"] = "%d" % i.mid
        mon["name"] = i.name
        monster_infos.append(mon)
    ailist = []
    for i in actmode.actionmodelist:
        ai = {}
        ai["id"] = "%d" % i.id
        ai["name"] = i.name
        ailist.append(ai)
    skill_list = []
    for i in skills.skilllist:
        sk = {}
        sk["id"] = "%d" % i.id
        sk["name"] = i.name
        skill_list.append(sk)
    response = render_to_response('dungeonmod.tpl', {"did":did, "name":d.name, "minfo":monster_infos, "ailist":ailist, "sk":skill_list, "data":d.data}, context_instance=RequestContext(request))
    if 'text/html' in response['Content-Type']:
        response.content = short(response.content)
    return response
开发者ID:litexavier,项目名称:CrystalLandGame,代码行数:25,代码来源:views.py

示例6: setUp

 def setUp(self):
     self.start_map_content = 'S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S'
     with open('basic_dungeon.txt', 'w') as map_file:
         map_file.write(self.start_map_content)
     self.map = Dungeon('basic_dungeon.txt')
     self.hero_player = Hero('Stoyan', 100, 'DeathBringer')
     self.hero_player.equip_weapon(Weapon('Sword', 20, 0.5))
     self.orc_player = Orc('Broks', 100, 1.5)
     self.orc_player.equip_weapon(Weapon('Stick', 10, 0.1))
     self.battle_map_content = 'S.#\n#S#'
     with open('battle_map.txt', 'w') as map_file:
         map_file.write(self.battle_map_content)
     self.battle_map = Dungeon('battle_map.txt')
     self.battle_map.spawn('human', self.hero_player)
     self.battle_map.spawn('orc', self.orc_player)
开发者ID:stoyaneft,项目名称:HackBulgariaProgramming-101,代码行数:15,代码来源:test_dungeon.py

示例7: main

def main():
    """
    Quick game setup for testing purposes.
    """
    win = pygcurse.PygcurseWindow(80, 30)
    win.font = pygame.font.Font(pygame.font.match_font("consolas"), 18)
    level1 = Dungeon.load_from_file("map/bigmap.txt")
    player = Player(1, 1)
    level1.add_player(player)
    msgbox = MessageBox()

    view = GameView(
        win, {ScrollingView(level1): (0, 0), HUDView(player): (700, 0), MessageBoxView(msgbox, 80, 5): (0, 460)}
    )

    controller = Controller(level1, msgbox, view)
    win.autoupdate = False
    mainClock = pygame.time.Clock()
    running = True

    while running:
        for event in pygame.event.get():
            if event.type == QUIT:
                running = False
            else:
                controller.process_event(event)

        controller.view.draw()
        win.blittowindow()
        mainClock.tick(30)

    pygame.quit()
    sys.exit()
开发者ID:IndexErrorCoders,项目名称:Pythoria,代码行数:33,代码来源:main.py

示例8: setUp

 def setUp(self):
     self.filename = 'dungeon.txt'
     self.file_to_read = open(self.filename, 'w')
     field = ["S.##......", "#.##..###.", "#.###.###.", "#.....###.", "###.#####S"]
     self.file_to_read.write("\n".join(field))
     self.file_to_read.close()
     self.dungeon = Dungeon("dungeon.txt")
开发者ID:stoilov,项目名称:Programming101,代码行数:7,代码来源:dungeon_test.py

示例9: run

    def run(self):
        running = True
        system('clear')
        print("Welcome to Dungeons & Pythons!")
        print("What are you waiting for? Create your character and start slaying...")
        self.initialize_game()
        print("Loading Level " + str(self.level) + '...')
        sleep(3)

        while running:
            system('clear')
            if not self.hero.is_alive():
                print("\n\nGAME OVER!")
                sleep(3)
                self.run()

            print("Character: {0}".format(str(self.hero)))
            print("Health: {0}".format(str(self.hero.get_health())))
            print("Weapon: {0}".format(str(self.hero.weapon)))
            print("Level: {0}".format(str(self.level)))
            print("\n")

            self.map.print_map()
            command = input("\nEnter direction <u, d, r, l>: ")
            self.parser.take_command(command)
            self.hero = self.map.hero
            if self.map.game_ended:
                system('clear')
                self.level += 1
                self.map = Dungeon(self.level)
                if not self.map.map:
                    print("YOU WON!!! Congratulations, Dungeon Master! ;)")
                self.map.spawn(self.hero)
                print("Loading Level " + str(self.level) + '...')
                sleep(3)
开发者ID:tdhris,项目名称:HackBulgaria,代码行数:35,代码来源:game.py

示例10: setUp

 def setUp(self):
     self.hero = Hero("Ahri", "Kingslayer", 100, 100, 2)
     self.enemy = Enemy(100, 100, 20)
     self.dungeon = Dungeon("level1.txt")
     self.weapon = Weapon("The Axe of Destiny", damage=20)
     self.spell = Spell(
         name="Fireball", damage=30, mana_cost=50, cast_range=1)
开发者ID:kobso1245,项目名称:Programming101-v3,代码行数:7,代码来源:dungeons_and_pythons_tests.py

示例11: setUp

 def setUp(self):
     self.hero = Hero("Bron", 100, "DragonSlayer")
     self.orc = Ork("BronOrk", 100, 1.1)
     self.axe = Weapon("Axe", 12.45, 0.2)
     self.sword = Weapon("Sword of Arthur", 13, 0.5)
     self.battle = Fight(self.hero, self.orc)
     self.dungeon = Dungeon("dungeon.txt")
开发者ID:IvanAlexandrov,项目名称:HackBulgaria-Tasks,代码行数:7,代码来源:test_entity.py

示例12: setUp

    def setUp(self):
        map_dungeon = """S.##.....T
#T##..###.
#.###E###E
#.E...###.
###T#####G"""
        self.dungeon = Dungeon.create_from_string(map_dungeon)
        self.hero = Hero("Bron", "Dragon", 100, 100, 2)
开发者ID:slaviana88,项目名称:Programming101-3,代码行数:8,代码来源:test_dungeon.py

示例13: test_move_left_and_fight

    def test_move_left_and_fight(self):
        second_content = 'SS##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####.'
        second_filename = "basic_dungeon1.txt" 
        second_file = open(second_filename,'w')
        second_file.write(second_content)
        second_file.close()

        second_map = Dungeon(second_filename)
        #----------------------------------------------
        player1 = Hero("Bron", 10, "DragonSlayer")
        player2 = Orc('karakondjul', 100 , 1.5)

        second_map.spawn(player1.name, player1)
        second_map.spawn(player2.name, player2)
        self.assertTrue(second_map.move(player2.name, 'left'))

        os.remove(second_filename)
开发者ID:dsspasov,项目名称:HackBulgaria,代码行数:17,代码来源:dungeon_test.py

示例14: setUp

    def setUp(self):
        self.filename = 'test_dng_map.txt'
        f = open(self.filename, "w")
        content_map = 'S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S'
        f.write(content_map)
        f.close()

        self.new_map = Dungeon(self.filename)
开发者ID:fyllmax,项目名称:Programming101,代码行数:8,代码来源:dungeon_test.py

示例15: initialize_game

 def initialize_game(self):
     name = input("Character Name> ")
     health = 100
     nickname = input("Character Nickname> ")
     self.hero = Hero(name, health, nickname)
     self.level = 1
     self.map = Dungeon()
     self.map.spawn(self.hero)
开发者ID:tdhris,项目名称:HackBulgaria,代码行数:8,代码来源:game.py


注:本文中的dungeon.Dungeon类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。