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


Python Dungeon.print_map方法代码示例

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


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

示例1: TestDungeon

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
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,代码行数:31,代码来源:test_dungeon.py

示例2: TestDungeon

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
class TestDungeon(unittest.TestCase):

    def setUp(self):

        self.without_weapon = Weapon("With bare hands", 0, 0)
        self.thanes_hummer = Weapon("Thanes hummer", 15, 0.4)
        self.yurnero_blade = Weapon("Yurneros blade", 10, 0.35)
        self.the_hero = Hero("Thanes", 150, 150, "Mountain King")
        self.the_orc = Orc("Yurnero the Blademaster", 150, 150, 1.3)
        self.the_chen = Orc("Chen", 150, 150, 1.3)
        self.small_potion = Potion("Small potion", 15)
        self.midium_potion = Potion("Midium potion", 25)
        self.the_hero.equip_weapon(self.thanes_hummer)
        self.the_orc.equip_weapon(self.yurnero_blade)
        self.map = Dungeon("map.txt")
        self.map.read_map()
        self.map.dict_of_items[self.yurnero_blade] = []
        self.map.dict_of_items[self.thanes_hummer] = []
        self.map.dict_of_items[self.small_potion] = []
        self.map.dict_of_items[self.midium_potion] = []
        self.map.dict_of_herous[self.the_orc] = []
        self.map.dict_of_herous[self.the_hero] = []
        self.map.spawn_player("shosho", self.the_hero)
        #self.map.spawn_player("kosho", self.the_orc)
        #self.map.dict_champion_name[self.the_hero] = "shosho"
        self.map.dict_champion_name[self.the_orc] = "kosho"



    #def test_validate_player(self):
    #    self.assertEqual(self.the_hero, self.map.validate_player_name("hero"))
    def test_spawn_player(self):
        #self.assertFalse(self.map.spawn_player("shosho", self.the_hero))
        self.assertTrue(self.map.spawn_player("kosho", self.the_orc))
        self.assertFalse(self.map.spawn_player("kosho", self.the_chen))

    def test_can_move(self):
        #print("{}\n{}".format(self.map.number_of_rows, self.map.number_of_chars))
        #print((self.map.number_of_rows))
        self.current_user = self.the_orc
        self.map.print_map()

        self.assertFalse(self.map.can_move_up(-1, 0))
        self.assertFalse(self.map.can_move_down(1, 0))
        self.assertTrue(self.map.can_move_right(0, 1))
        self.map.validate_player_name("orc")
        print("{}     {}".format(self.map.current_x, self.map.current_y))
        self.assertFalse(self.map.can_move_up(-1, 0))
        self.assertFalse(self.map.can_move_down(1, 0))
        self.assertTrue(self.map.can_move_right(0, 1))
        self.assertFalse(self.map.can_move_left(0, -1))

    def test_validate_player_name(self):

        self.map.spawn_player("kosho", self.the_orc)
        self.assertEqual(self.map.validate_player_name("kosho"), self.the_orc)
        self.map.print_map()
开发者ID:VictorVangelov,项目名称:HackBulgaria,代码行数:59,代码来源:test_dungeon.py

示例3: DungeonTest

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
class DungeonTest(unittest.TestCase):
    """docstring for DungeonTest"""

    def setUp(self):
        self.test_m = ['..##......',
                    '#.##..###.',
                    '#.###.###.',
                    '#..S.S###.',
                    '###.#####.']
        test_map_file = open('test_map.txt', 'w')
        test_map_file.write('\n'.join(self.test_m))
        test_map_file.close()
        self.test_map = Dungeon('test_map.txt')

    def test_print_map(self):
        self.assertEqual('\n'.join(self.test_m), self.test_map.print_map())

    def test_spawn(self):
        hero = Hero('p1', 100, 'first')
        orc = Orc('p2', 100, 2)
        self.test_map.spawn('player1', hero)
        self.assertEqual('H', self.test_map.print_map()[36])
        self.assertEqual('S', self.test_map.print_map()[38])
        self.test_map.spawn('player2', orc)
        self.assertEqual('O', self.test_map.print_map()[38])
        self.assertEqual(False, self.test_map.spawn('player3', orc))

    def tearDown(self):
        remove('test_map.txt')

    def test_move(self):
        after_move = ['..##......',
                    '#.##..###.',
                    '#.###.###.',
                    '#...HO###.',
                    '###.#####.']
        hero = Hero('p1', 100, 'first')
        orc = Orc('p2', 100, 2)
        hero_weapon = Weapon('Axe', 25, 0.1)
        hero.equip_weapon(hero_weapon)
        orc_weapon = Weapon('Stick', 5, 0.01)
        orc.equip_weapon(orc_weapon)
        self.test_map.spawn('player1', hero)
        self.test_map.spawn('player2', orc)
        self.assertTrue(self.test_map.move('player1', 'right'))
        self.assertEqual(False, self.test_map.move('player1', 'up'))
        self.assertEqual(False, self.test_map.move('player1', 'fuckedUpDirection'))
        self.assertEqual('\n'.join(after_move), self.test_map.print_map())
        self.test_map.move('player1', 'right')

    def test_fight(self):
        pass
开发者ID:smo93,项目名称:hackbulgaria,代码行数:54,代码来源:dungeon_test.py

示例4: main

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
def main():
    my_dungeon = Dungeon("area.txt")
    my_dungeon.spawn(my_dungeon.hero)
    my_dungeon.hero.learn(Spell("strong", 30, 70, 6))
    while my_dungeon.hero.is_alive():
        print(my_dungeon.print_map())
        command = input("Enter Direction: ")
        my_dungeon.move_hero(command)
开发者ID:VladislavAtanasov,项目名称:Dungeons-and-Pythons,代码行数:10,代码来源:Game.py

示例5: test_the_game

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
    def test_the_game(self):
        h = Hero(name="Bron", title="Dragonslayer",
                 health=100, mana=100, mana_regeneration_rate=2)
        w = Weapon(name="The Axe of Destiny", damage=20)
        h.equip(w)
        s = Spell(name="Lightning bolt", damage=30, mana_cost=50, cast_range=2)
        h.learn(s)
        dungeon = Dungeon("level1.txt")
        dungeon.spawn(h)
        dungeon.move_hero("right")
        dungeon.move_hero("down")
        dungeon.try_range_attack()
        dungeon.move_hero("down")
        dungeon.move_hero("down")
        dungeon.try_range_attack()
        # dungeon.move_hero("right")
        # dungeon.move_hero("right")

        dungeon.print_map()
开发者ID:kobso1245,项目名称:Programming101-v3,代码行数:21,代码来源:dungeons_and_pythons_tests.py

示例6: TestDungeon

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
class TestDungeon(unittest.TestCase):
    def setUp(self):
        self.filename = "maze.txt"
        self.contents = "S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S"
        with open(self.filename, "w+") as f:
            f.write(self.contents)
            f.close()

        self.peshtera = Dungeon("maze.txt")
        self.orc = Orc("Ivancho", 100, 1.3)
        self.hero = Hero("Petarcho", 100, "Garbage")

    def tearDown(self):
        os.remove(self.filename)

    def test_dungeon_map(self):
        with open(self.filename, "r+") as f:
            actual = f.read()
            f.close()
        self.assertEqual(self.contents, actual)

    def test_print_map(self):
        output = self.peshtera.print_map()
        with open(self.filename, "r+") as f:
            actual = f.read()
            f.close()
        self.assertEqual(output, actual)

    def test_spawn_character(self):
        self.peshtera.spawn("Player One", self.orc)
        with open(self.filename, "r+") as f:
            actual = f.read()
            f.close()
        contents = "O.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S"
        self.assertEqual(actual, contents)

    def test_spawn_already_spawned_character(self):
        self.peshtera.spawnlist = {"Player One": self.orc}
        result = self.peshtera.spawn("Player One", self.orc)
        self.assertEqual("Character is already spawned.", result)

    def test_spawn_with_no_free_slots(self):
        self.filename = "maze.txt"
        self.contents = "..##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####."
        with open(self.filename, "w+") as f:
            f.write(self.contents)
            f.close()
        result = self.peshtera.spawn("One", self.orc)
        self.assertEqual("No free spawn slot.", result)

    def test_move_to_unknown_given_direction(self):
        self.peshtera.spawn("Orc", self.orc)
        result = self.peshtera.move("Orc", "test")
        self.assertEqual("Wrong direction given.", result)
开发者ID:kazuohirai,项目名称:HackBulgaria,代码行数:56,代码来源:dungeon_test.py

示例7: TestDungeon

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]

#.........这里部分代码省略.........
    def setUp(self):
        self.existing_file = str(uuid4)
        self.test_map = \
            "S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S"
        with open(self.existing_file, "w") as writeFile:
            writeFile.write(self.test_map)
        self.dungeon = Dungeon(self.existing_file)

        self.hero = Hero("Hero", 100, "Nick")
        self.orc = Orc("Orc", 100, 2)

    def tearDown(self):
        remove(self.existing_file)

    def test_dungeon_init_existing_file(self):
        self.assertEqual(self.dungeon.map, self.test_map)
        self.assertEqual(10, self.dungeon._get_row_length())

    def test_dungeon_init_nonexisting_file(self):
        fileName = str(uuid4())
        with self.assertRaises(FileNotFoundError):
            Dungeon(fileName)

    def test_spawn_success(self):
        self.assertTrue(self.dungeon.spawn("the_hero", self.hero))
        self.test_map = self.test_map.replace("S", "H", 1)
        self.assertEqual(self.dungeon.map, self.test_map)
        self.assertEqual(self.dungeon.player_pos["the_hero"], 0)

        self.assertTrue(self.dungeon.spawn("the_orc", self.orc))
        self.test_map = self.test_map.replace("S", "O", 1)
        self.assertEqual(self.dungeon.map, self.test_map)
        self.assertEqual(self.dungeon.player_pos["the_orc"],
                         len(self.test_map) - 1)

    def test_spawn_fail(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.spawn("the_orc", self.orc)
        self.assertFalse(self.dungeon.spawn("new_hero", self.hero))

    def test_spawn_type_error(self):
        with self.assertRaises(TypeError):
            self.dungeon.spawn("Dingo")

    def test_move_invalid_direction(self):
        self.dungeon.spawn("the_hero", self.hero)

        with self.assertRaises(ValueError):
            self.dungeon.move("the_hero", "dooooooown")

    def test_move_invalid_player_name(self):
        with self.assertRaises(ValueError):
            self.dungeon.move("invalid", "down")

    def test_move_right_success(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.assertTrue(self.dungeon.move("the_hero", "right"))

    def test_move_right_fail(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.spawn("the_orc", self.orc)
        self.assertFalse(self.dungeon.move("the_orc", "right"))

    def test_move_left_success(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.move("the_hero", "right")
        self.assertTrue(self.dungeon.move("the_hero", "left"))

    def test_move_left_fail(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.spawn("the_orc", self.orc)
        self.assertFalse(self.dungeon.move("the_hero", "left"))
        self.assertFalse(self.dungeon.move("the_orc", "left"))

    def test_move_up_success(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.spawn("the_orc", self.orc)
        self.assertTrue(self.dungeon.move("the_orc", "up"))

    def test_move_up_fail(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.assertFalse(self.dungeon.move("the_hero", "up"))

    def test_move_down_success(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.move("the_hero", "right")
        self.assertTrue(self.dungeon.move("the_hero", "down"))
        self.assertTrue(self.dungeon.move("the_hero", "down"))

    def test_move_down_fail(self):
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.spawn("the_orc", self.orc)
        self.assertFalse(self.dungeon.move("the_hero", "down"))
        self.assertFalse(self.dungeon.move("the_orc", "down"))

    def test_move_fight(self):
        self.dungeon.map = self.dungeon.map.replace(".", "S", 1)
        self.dungeon.spawn("the_hero", self.hero)
        self.dungeon.spawn("the_orc", self.orc)
        self.dungeon.print_map()
开发者ID:antonpetkoff,项目名称:Programming101,代码行数:104,代码来源:dungeon_test.py

示例8: TestDungeon

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
class TestDungeon(unittest.TestCase):

    def setUp(self):
        self.my_map = Dungeon("basic_dungeon.txt")
        my_file = open("basic_dungeon.txt", 'w')
        new_content = "S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S\n"
        my_file.write("".join(new_content))
        my_file.close()

    def test_dungeon_init(self):
        self.assertEqual(self.my_map.file_path, "basic_dungeon.txt")

    def test_print_map(self):
        self.assertEqual(self.my_map.print_map(), "S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S\n")

    def test_spawn(self):
        bron_orc = Orc("Bron", 100, 1.3)
        self.assertTrue(self.my_map.spawn("player_1", bron_orc))

    def test_spawn_when_dont_have_spowning_point(self):
        bron_orc = Orc("Bron", 100, 1.3)
        bron_hero = Hero("Bron", 100, "DragonSlayer")
        self.my_map.spawn("player_1", bron_orc)
        self.my_map.spawn("player_2", bron_hero)
        self.assertFalse(self.my_map.spawn("player_3", bron_orc))

    def test__fail_move_on_map(self):
        bron_orc = Orc("Bron", 100, 1.3)
        bron_hero = Hero("Bron", 100, "DragonSlayer")
        axe = Weapon("Mighty Axe", 25, 0.2)
        bron_orc.weapon = axe
        self.my_map.spawn("player_1", bron_orc)
        self.my_map.spawn("player_2", bron_hero)
        self.assertFalse(self.my_map.move("player_1", "left"))
        self.assertTrue(self.my_map.move("player_1", "right"))
        self.assertFalse(self.my_map.move("player_1", "up"))
        self.assertFalse(self.my_map.move("player_1", "right"))
        self.assertFalse(self.my_map.move("player_2", "down"))
        #self.assertTrue(self.my_map.move("player_2", "up"))

    def test_move_right(self):
        orc = Orc("Bron", 100, 1.3)
        self.my_map.spawn("player_1", orc)
        self.my_map.move("player_1", "right")
        self.assertEqual(self.my_map.print_map(), ".O##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S\n")

    def test_move_left(self):
        orc = Orc("Bron", 100, 1.3)
        self.my_map.spawn("player_1", orc)
        self.my_map.move("player_1", "right")
        self.my_map.move("player_1", "left")
        self.assertEqual(self.my_map.print_map(), "O.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S\n")

    def test_move_up(self):
        orc = Orc("Bron", 100, 1.3)
        hero = Hero("Bron", 100, "DragonSlayer")
        self.my_map.spawn("player_1", orc)
        self.my_map.spawn("player_2", hero)
        self.my_map.move("player_2", "up")
        self.assertEqual(self.my_map.print_map(), "O.##......\n#.##..###.\n#.###.###.\n#.....###H\n###.#####.\n")

    def test_move_down(self):
        orc = Orc("Bron", 100, 1.3)
        hero = Hero("Bron", 100, "DragonSlayer")
        self.my_map.spawn("player_1", orc)
        self.my_map.spawn("player_2", hero)
        self.my_map.move("player_2", "up")
        self.my_map.move("player_2", "down")
        self.assertEqual(self.my_map.print_map(), "O.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####H\n")

    def test_battle(self):
        orc = Orc("Bron", 100, 1.3)
        hero = Hero("Bron", 100, "DragonSlayer")
        axe = Weapon("Mighty Axe", 25, 0.2)
        orc.weapon = axe
        self.my_map.spawn("player_1", orc)
        self.my_map.spawn("player_2", hero)
        self.my_map.move("player_1", "right")
        self.my_map.move("player_1", "left")
        self.my_map.move("player_1", "right")
        self.my_map.move("player_2", "up")
        self.my_map.move("player_1", "down")
        self.my_map.move("player_1", "down")
        self.my_map.move("player_1", "down")
        for i in range(0, 4):
            self.my_map.move("player_2", "up")
        for i in range(0, 4):
            self.my_map.move("player_2", "left")
        self.my_map.move("player_2", "down")
        self.my_map.move("player_2", "down")
        self.my_map.move("player_2", "down")
        self.my_map.move("player_1", "right")
        self.my_map.move("player_2", "left")
        self.my_map.move("player_2", "left")
        self.my_map.move("player_1", "right")
        self.assertEqual(self.my_map.print_map(), "..##......\n#.##..###.\n#.###.###.\n#..O..###.\n###.#####.\n")
开发者ID:AlexanderTankov,项目名称:HackBulgaria-Programming-101,代码行数:98,代码来源:dungeon_test.py

示例9: __init__

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
class Game:
    def __init__(self):
        self.parser = CommandParser()
        self.load_functions()
        self.run()

    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)

    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)

    def move_up(self, arguments):
        self.map.move('up')

    def move_down(self, arguments):
        self.map.move('down')

    def move_right(self, arguments):
        self.map.move('right')

    def move_left(self, arguments):
        self.map.move('left')

    def load_functions(self):
        self.parser.add_function('u', self.move_up)
        self.parser.add_function('d', self.move_down)
        self.parser.add_function('r', self.move_right)
        self.parser.add_function('l', self.move_left)
开发者ID:tdhris,项目名称:HackBulgaria,代码行数:70,代码来源:game.py

示例10: CommandLineInterface

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
class CommandLineInterface():

    def __init__(self):
        self.command_list = {
            "show_map": self.display_map,
            "create_hero": self.create_character,
            "known_as": self.known_as,
            "spawn_hero": self.spawn_character,
            "move": self.move_character,
            "heal": self.heal_character,
            "help": self.help_message,
            "exit": self.exit_game
        }
        self.exit = False
        self.is_created = False
        self.map_loaded = False
        self.validator = None
        self.input = None
        self.help = """show_map - Displays current dungeon map
create_hero <Name> <Health> <Nickname> - Creates hero with entered attributes
spawn_hero <Username> - Spawns hero with specified username into the dungeon
known_as - Displays name and nickname of hero
move <username> <direction> - Moves the hero in the specified direction
help - Displays this message
exit - Closes the program"""

    def start_game(self):
        print("Welcome. Type 'help' for available commands")
        while self.exit is False:
            command = self.get_input_command()
            if command[0] in self.command_list:
                execute = self.command_list[command[0]]
                output = execute()
                print(output) if output is not None else None
            else:
                print("Invalid command. Type 'help' for available commands.")

    def get_input_command(self):
        self.input = input("--> ").strip().split(" ")
        return self.input

    def load_map(self, map_path):
        self.validator = MapValidator(map_path)
        if not self.validator.validate_map():
            return self.validator.generate_message()
        else:
            self.dungeon = Dungeon(map_path)
            if self.dungeon.map:
                self.map_loaded = True
                return self.validator.generate_message()

    def display_map(self):
        return self.dungeon.print_map()

    def create_character(self):
        self.char = Hero(self.input[1], int(self.input[2]), self.input[3])
        self.char.weapon = Weapon("Ashbringer", 40, 0.8)
        self.is_created = True

    def known_as(self):
        return self.char.known_as()

    def spawn_character(self):
        if self.is_created is True:
            self.dungeon.spawn(self.input[1], self.char)
            self.dungeon.spawn_npcs()
        else:
            return "No created characters."

    def move_character(self):
        if self.input[1] not in self.dungeon.ingame:
            return "Player name is incorrect."

        elif not self.dungeon.ingame[self.input[1]].is_alive():
            self.exit = True
            return "Your character is dead. Game over."
        else:
            if self.dungeon.unlocked:
                self.exit = True
                return "Game Over. You have won."
            return self.dungeon.move_player(self.input[1], self.input[2])
            to_move = self.dungeon.get_random_npc()
            if not self.dungeon.ingame[to_move].is_alive():
                self.dungeon.ingame = {i: self.dungeon.ingame[i]
                                       for i in self.dungeon.ingame
                                       if i != 0}
                self.dungeon.npcs = {i: self.dungeon.npcs[i]
                                     for i in self.dungeon.npcs if i != 0}
            else:
                return self.dungeon.move_npc(to_move)
            return self.display_map()

    def heal_character(self):
        if self.is_created and self.map_loaded:
            self.char.health = self.char.max_health
        else:
            return "No created characters."

    def help_message(self):
        return self.help
#.........这里部分代码省略.........
开发者ID:sslavov93,项目名称:TreasureDungeon,代码行数:103,代码来源:CLI.py

示例11: print

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
                if orc.is_alive():
                    self.orc_attack()
                else:
                    print("{} has slained {}!".format(hero.name, orc.name))
                    break
            else:
                self.orc_attack()
                if hero.is_alive():
                    self.hero_attack()
                else:
                    print("{} has slained {}!".format(orc.name, hero.name))
                    break
            print()


hero = Hero("Ashe", 100, "OrcSlayer")
orc = Orc("Kaiba", 100, 1.25)
axe = Weapon("Axe", 10, 0.35)
sword = Weapon("Sword", 15, 0.15)
hero.equip_weapon(sword)
orc.equip_weapon(axe)
battle = Fight(hero, orc)
battle.simulate_fight()

the_map = Dungeon("basic_dungeon.txt")
print(the_map.spawn("player_1", hero))
the_map.print_map()
print(the_map.spawn("player_2", orc))
# print(the_map.test())
the_map.print_map()
开发者ID:kobso1245,项目名称:Programming101-v3,代码行数:32,代码来源:fight.py

示例12: Dungeon_Test

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
class Dungeon_Test(unittest.TestCase):

    def setUp(self):
        self.sniper = Weaphon("Gun", 85, 0.10)
        self.hammer = Weaphon("One-Hand", 30, 0)

        self.bron_orc = Orc("Pesho", 100, 1.50)
        self.bron_hero = Hero("Ivan", 100, "Magician")

        self.bron_orc.equip_weapon(self.hammer)
        self.bron_hero.equip_weapon(self.sniper)
        self.magura = Dungeon("/home/biser/TDD/simple_dungeon.txt")

    def tearDown(self):
        f1 = open("/home/biser/TDD/simple_dungeon.txt", 'w+')
        a = "S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S\n"
        self.magura.lst = []
        f1.write(a)

    def test_constructor(self):
        self.assertEqual(
            "/home/biser/TDD/simple_dungeon.txt", self.magura.path)

    def test_print_map(self):
        a = "S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S\n"
        self.assertEqual(a, self.magura.print_map())

    def test_spawn_first_entity(self):
        self.magura.spown("Ivan", self.bron_hero)
        f1 = open("/home/biser/TDD/simple_dungeon.txt", 'r')
        first_spowning_point = f1.readline()[0]
        f1.close()
        self.assertEqual(first_spowning_point, "H")

    def test_spawn_wrong_object_as_argument(self):
        self.magura.spown("Ivan", self.sniper)
        self.assertEqual(
            "wrong instance given", self.magura.spown("Ivan", self.sniper))

    def test_spawn_second_entity(self):
        temp = ""
        self.magura.spown("Ivan", self.bron_hero)
        self.magura.spown("Ivan", self.bron_orc)
        f1 = open("/home/biser/TDD/simple_dungeon.txt", 'r')
        print
        for line in f1:
            temp = line
        temp = temp[len(temp)-2:]
        self.assertEqual("O\n", temp)

    def test_spawn_one_more_than_the_map_can_handle(self):
        self.magura.spown("Ivan", self.bron_hero)
        self.magura.spown("Gosho", self.bron_orc)
        self.assertEqual("currently there is no free spowning point", self.magura.spown("Pesho", self.bron_orc))

    def test_entity_move(self):
        self.magura.spown("Ivan", self.bron_hero)
        self.magura.move("Ivan", "right")
        f1 = open("/home/biser/TDD/simple_dungeon.txt", 'r')
        first_spowning_point = f1.readline()[1]
        f1.close()
        self.assertEqual(first_spowning_point, "H")

    def test_entity_move_through_wall(self):
        pass
        self.magura.spown("Ivan", self.bron_hero)
        self.magura.move("Ivan", "right")
        self.assertFalse(self.magura.move("Ivan", "right"))

    def test_move_outside_the_map(self):
        pass
        self.magura.spown("Ivan", self.bron_hero)
        self.assertFalse(self.magura.move("Ivan", "left"))
开发者ID:golfdman,项目名称:HackBulgaria,代码行数:75,代码来源:test_hero.py

示例13: dungeon_test

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
class dungeon_test(unittest.TestCase):
    def setUp(self):
        self.dungeon_map = [
            ['.', 'S', '#', '#', '.', '.', '.', '.', '.', 'T'],
            ['#', 'T', '#', '#', '.', '.', '#', '#', '#', '.'],
            ['#', '.', '#', '#', '#', 'E', '#', '#', '#', 'E'],
            ['#', '.', 'E', '.', '.', '.', '#', '#', '#', '.'],
            ['#', '#', '#', 'T', '#', '#', '#', '#', '#', 'G']]
        f = open('test_level.txt', 'w')
        for line in self.dungeon_map:
            f.write(''.join(line) + '\n')
        f.close()
        self.dungeon = Dungeon("test_level.txt")

    def tearDown(self):
        os.remove("test_level.txt")

    def test_init(self):
        self.assertEqual(self.dungeon.dungeon_map, self.dungeon_map)

    def test_find_item_coordinates(self):
        self.assertEqual(self.dungeon._find_item_coordinates('S'), (0, 1))
        self.assertEqual(self.dungeon._find_item_coordinates('G'), (4, 9))

    def test_spawn(self):
        hero = Unit(100, 100, 5)
        self.dungeon.spawn(hero)
        self.assertEqual(self.dungeon.dungeon_map[0][1], 'H')

    def test_prin_map(self):
        map_string = """.S##.....T
#T##..###.
#.###E###E
#.E...###.
###T#####G"""
        self.assertEqual(self.dungeon.print_map(), map_string)

    def test_move_hero(self):
        hero = Unit(100, 100, 5)
        self.dungeon.spawn(hero)
        self.assertFalse(self.dungeon.move_hero('up'))
        self.assertTrue(self.dungeon.move_hero('left'))
        # self.assertTrue(self.dungeon.move_hero('rigth'))
        self.assertTrue(self.dungeon.move_hero('rigth'))
        self.assertTrue(self.dungeon.move_hero('down'))
        self.assertTrue(self.dungeon.move_hero('down'))
        self.assertEqual(self.dungeon.hero_possition, (2, 1))
        self.assertEqual(self.dungeon.dungeon_map[1][1], '.')
        self.dungeon_map[0][1] = '.'
        self.dungeon_map[1][1] = '.'
        self.dungeon_map[2][1] = 'H'
        self.assertEqual(self.dungeon.dungeon_map, self.dungeon_map)

    def test_found_treasure(self):
        hero = Unit(100, 100, 5)
        hero.health = 1
        hero.mana = 1
        self.dungeon.spawn(hero)
        self.dungeon._found_treasure('mana')
        self.assertGreater(hero.mana, 1)
        self.dungeon._found_treasure('health')
        self.assertGreater(hero.health, 1)
        self.dungeon._found_treasure('weapon')
        self.assertNotEqual(hero.weapon, None)
        self.dungeon._found_treasure('spell')
        self.assertNotEqual(hero.spell, None)

    def test_create_enemy(self):
        enemy = self.dungeon._create_enemy(100, 100, 100)
        self.assertEqual(enemy.health, 100)
        self.assertEqual(enemy.mana, 100)
        self.assertEqual(enemy.damage, 100)

    def test_find_enemy(self):
        self.dungeon.hero_possition = (3, 3)
        self.dungeon.dungeon_map[3][3] = 'H'

    def test_hero_attack(self):
        hero = Unit(100, 100, 5)
        hero.learn(Spell('a', 10, 10, 2))
        self.dungeon.spawn(hero)
        self.dungeon.move_hero('down')
        self.dungeon.move_hero('down')
        self.assertEqual('Nothing in casting range 2',
                         self.dungeon.hero_attack(by="spell"))
        self.dungeon.move_hero('down')
        self.assertIsInstance(self.dungeon.hero_attack(by='spell'), Fight)
开发者ID:sevgo,项目名称:PyCraft,代码行数:89,代码来源:dungeon_test.py

示例14: start

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
def start():
    print("Welcome. Type 'help' for available commands")
    exit = False
    created = False
    loaded_map = False
    while exit is False:
        full_command = input('--> ').strip().split(' ')
        if full_command[0] == 'load_map':
            dungeon = Dungeon(full_command[1])
            if dungeon.map:
                loaded_map = True
        elif full_command[0] == 'show_map' and loaded_map:
            print(dungeon.print_map())
        elif full_command[0] == 'create_hero' and loaded_map:
            my_hero = Hero(
                full_command[1], int(full_command[2]), full_command[3])
            my_hero.weapon = Weapon('Ashbringer', 40, 0.8)
            created = True
        elif full_command[0] == 'spawn_hero' and loaded_map:
            if created is True:
                dungeon.spawn(full_command[1], my_hero)
                dungeon.spawn_npcs()
            else:
                print('No created characters.')
        elif full_command[0] == 'move' and loaded_map:
            if full_command[1] not in dungeon.ingame:
                print ('Player name is incorrect.')

            elif not dungeon.ingame[full_command[1]].is_alive():
                exit = True
                return 'Your character is dead. Game over.'
            else:
                if dungeon.unlocked:
                    exit = True
                    return 'Game Over. You have won.'
                print(dungeon.move_player(full_command[1], full_command[2]))
                to_move = dungeon.get_random_npc()
                if not dungeon.ingame[to_move].is_alive():
                    dungeon.ingame = {
                        i: dungeon.ingame[i] for i in dungeon.ingame if i != 0}
                    dungeon.npcs = {i: dungeon.npcs[i]
                                    for i in dungeon.npcs if i != 0}
                else:
                    print(dungeon.move_npc(to_move))
                print(dungeon.print_map())
        elif full_command[0] == 'heal':
            if created and loaded_map:
                my_hero.health = my_hero.max_health
            else:
                print('No created characters.')
        elif full_command[0] == 'known_as':
            if created and loaded_map:
                print (my_hero.known_as())
            else:
                print('No created characters.')
        elif full_command[0] == 'help':
            print(helper)
        elif full_command[0] == 'exit':
            exit = True
        else:
            print("Invalid command. Type 'help' for available commands.")
开发者ID:sslavov93,项目名称:TreasureDungeon,代码行数:63,代码来源:CLI-deprecate.py

示例15: Dungeon

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import print_map [as 别名]
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')
d.move('FishHead', 'left')
d.move('FishHead', 'left')
d.print_map()
开发者ID:IvanAlexandrov,项目名称:HackBulgaria-Tasks,代码行数:31,代码来源:manual_test_dungeon.py


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