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


Python Dungeon.move方法代码示例

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


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

示例1: TestDungeon

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move [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: DungeonTest

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move [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

示例3: test_move_down_and_fight

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move [as 别名]
    def test_move_down_and_fight(self):
        second_content = 'S.##......\n#S##..###.\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", 100, "DragonSlayer")
        player2 = Orc('karakondjul', 10 , 1.5)
        second_map.spawn(player1.name, player1)
        second_map.spawn(player2.name, player2)
        second_map.move(player1.name, 'right')
        #self.new_map.print_map()
        self.assertTrue(second_map.move(player1.name, 'down'))

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

示例4: TestDungeon

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move [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

示例5: test_start_fight_both_alive

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move [as 别名]
 def test_start_fight_both_alive(self):
     fight_map = Dungeon("fight_map.txt")
     blademaster = Orc("Yurnero", 120, 1.2)
     fight_map.spawn("player_1", self.paladin)
     fight_map.spawn("player_2", blademaster)
     fight_map.move("player_1", "right")
     fight_map.move("player_2", "left")
     fight_map.move("player_1", "right")
     self.assertTrue(self.paladin.is_alive())
     self.assertTrue(blademaster.is_alive())
开发者ID:mihail-nikolov,项目名称:hackBG,代码行数:12,代码来源:test_dungeon.py

示例6: test_start_fight_paladin_dead

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move [as 别名]
 def test_start_fight_paladin_dead(self):
     axe = Weapon("axe", 10, 0.5)
     blademaster = Orc("Yurnero", 120, 1.2)
     blademaster.equip_weapon(axe)
     fight_map = Dungeon("fight_map.txt")
     fight_map.spawn("player_1", self.paladin)
     fight_map.spawn("player_2", blademaster)
     fight_map.move("player_1", "right")
     fight_map.move("player_2", "left")
     fight_map.move("player_1", "right")
     expected_arr = [['.', '.', 'O', '.']]
     self.assertFalse(self.paladin.is_alive())
     self.assertTrue(blademaster.is_alive())
     #testing _make_changes_after_fight
     self.assertEqual(fight_map.map_array, expected_arr)
开发者ID:mihail-nikolov,项目名称:hackBG,代码行数:17,代码来源:test_dungeon.py

示例7: DungeonTest

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move [as 别名]
class DungeonTest(unittest.TestCase):
    """Simulation dungeon"""
    def setUp(self):
        file_path = "basic_dungeon.txt"
        self.my_dungeon = Dungeon(file_path)
        self.dungeon_map = {
            0: list("S.##......"),
            1: list("#.##..###."),
            2: list("#.###.###."),
            3: list("#.....###."),
            4: list("###.#####S")
        }

        self.my_hero = Hero("Tedi", 100, "Da Geek")
        super_laptop = Weapon("Mind-Control Super-Laptop", 20, 0.5)
        self.my_hero.equip_weapon(super_laptop)
        self.my_orc = Orc("Shrek", 100, 2)
        ugly_weapon = Weapon("Bludgeon", 10, 0.5)
        self.my_orc.equip_weapon(ugly_weapon)

    def test_init_dungeon(self):
        self.assertEqual(self.dungeon_map, self.my_dungeon.get_map())

    def test_spawn_hero(self):
        self.assertTrue(self.my_dungeon.spawn("HackTedi", self.my_hero))
        dungeon_map = self.my_dungeon.get_map()
        self.dungeon_map[0][0] = 'H'
        self.assertEqual(self.dungeon_map, dungeon_map)

    def test_spawn_orc(self):
        self.assertTrue(self.my_dungeon.spawn("UglyOrc", self.my_orc))
        dungeon_map = self.my_dungeon.get_map()
        self.dungeon_map[0][0] = 'O'
        self.assertEqual(self.dungeon_map, dungeon_map)

    def test_spawn_hero_and_orc(self):
        self.my_dungeon.spawn("HackTedi", self.my_hero)
        self.my_dungeon.spawn("UglyOrc", self.my_orc)
        dungeon_map = self.my_dungeon.get_map()
        self.dungeon_map[0][0] = 'H'
        self.dungeon_map[4][9] = 'O'
        self.assertEqual(self.dungeon_map, dungeon_map)

    def test_spawn_more_than_available(self):
        self.my_dungeon.spawn("HackTedi", self.my_hero)
        self.my_dungeon.spawn("UglyOrc", self.my_orc)
        self.assertTrue(not self.my_dungeon.spawn("UglyOrc2", self.my_orc))

    def test_move(self):
        self.my_dungeon.spawn("HackTedi", self.my_hero)
        self.my_dungeon.move("HackTedi", "right")
        self.dungeon_map[0][0] = "."
        self.dungeon_map[0][1] = "H"
        dungeon_map = self.my_dungeon.get_map()
        self.assertEqual(self.dungeon_map, dungeon_map)

        players = self.my_dungeon.get_players()
        self.assertEqual(players["HackTedi"]["position"], (0, 1))

    def test_move_into_obstacle(self):
        self.my_dungeon.spawn("HackTedi", self.my_hero)
        self.assertTrue(not self.my_dungeon.move("HackTedi", "down"))
        players = self.my_dungeon.get_players()
        self.assertEqual(players["HackTedi"]["position"], (0, 0))

    def test_move_outside_map(self):
        self.my_dungeon.spawn("HackTedi", self.my_hero)
        self.assertTrue(not self.my_dungeon.move("HackTedi", "up"))
        players = self.my_dungeon.get_players()
        self.assertEqual(players["HackTedi"]["position"], (0, 0))

    def test_move_into_enemy(self):
        file_path = "basic_dungeon_for_fight.txt"
        self.my_dungeon = Dungeon(file_path)

        self.my_dungeon.spawn("HackTedi", self.my_hero)
        self.my_dungeon.spawn("UglyOrc", self.my_orc)
        self.my_dungeon.move("HackTedi", "right")
        map_string = ""
        dungeon_map = self.my_dungeon.get_map()
        for row in dungeon_map:
            map_string += "".join(dungeon_map[row]) + "\n"
        self.assertTrue(map_string == ".H\n" or map_string == ".O\n")

        players = self.my_dungeon.get_players()
        self.assertEqual(1, len(players))
开发者ID:tblazhev,项目名称:HackBulgaria-Programming101,代码行数:88,代码来源:dungeon_tests.py

示例8: Dungeon_Test

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move [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

示例9: TestDungeon

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

    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)

    def tearDown(self):
        remove(self.map.filename)
        remove('battle_map.txt')

    def test_dungeon_init(self):
        self.assertEqual(self.map.filename, 'basic_dungeon.txt')

    def test_print_map(self):
        self.assertEqual(self.map.print_map(), self.start_map_content)

    def test_first_spawn_succesful(self):
        self.assertTrue(self.map.spawn('player_1', self.hero_player))

    def is_map_changed_after_spawning_entity(self, entity, symbol):
        self.map.spawn('player', entity)
        with open(self.map.filename, 'r') as map_file:
            map_content_after_spawn = map_file.read()
        return map_content_after_spawn == self.start_map_content.replace(
            'S', symbol, 1)

    def test_map_changed_after_spawning_hero(self):
        self.assertTrue(
            self.is_map_changed_after_spawning_entity(self.hero_player, 'H'))

    def test_map_changed_after_spawning_orc(self):
        self.assertTrue(
            self.is_map_changed_after_spawning_entity(self.orc_player, 'O'))

    def test_spawn_unsuccesful_on_full_map(self):
        self.map.spawn('player1', self.hero_player)
        self.map.spawn('player2', self.orc_player)
        self.assertFalse(self.map.spawn('player3', self.orc_player))

    def test_correct_move(self):
        self.map.spawn('player1', self.hero_player)
        self.assertTrue(self.map.move('player1', 'right'))

    def test_out_of_map_move(self):
        self.map.spawn('player1', self.hero_player)
        self.assertFalse(self.map.move('player1', 'left'))

    def test_move_through_obstacle(self):
        self.map.spawn('player1', self.hero_player)
        self.assertFalse(self.map.move('player1', 'down'))

    def test_move_reflected_on_map(self):
        self.map.spawn('player1', self.hero_player)
        self.map.spawn('player2', self.orc_player)
        self.map.move('player1', 'right')
        self.map.move('player1', 'down')
        self.map.move('player2', 'up')
        self.map.move('player2', 'up')
        self.assertEqual(
            self.map.print_map(),
            '..##......\n#H##..###.\n#.###.###O\n#.....###.\n###.#####.'
        )

    def test_move_into_battle(self):
        self.battle_map.move('human', 'right')
        self.battle_map.move('orc', 'up')
        player_dead = not self.hero_player.is_alive(
        ) or not self.orc_player.is_alive()
        self.assertTrue(player_dead)

    def test_map_accurate_after_battle(self):
        self.battle_map.move('human', 'right')
        self.battle_map.move('orc', 'up')
        self.assertEqual(self.battle_map.print_map(), '.H#\n#.#')
开发者ID:stoyaneft,项目名称:HackBulgariaProgramming-101,代码行数:88,代码来源:test_dungeon.py

示例10: DungeonTests

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

    def setUp(self):
        file = open("test_file.txt", "w")
        content = ["S...S", "", "Spoon 4 0.2", "RustyFork 6 0.7"]
        file.write("\n".join(content))
        file.close()

        self.dungeon = Dungeon("test_file.txt")

        self.hero = Hero("Don Quixote", 20, "The Common Sense")
        self.orc = Orc("Oplik", 20, 1.5)

    def test_init(self):
        self.assertEqual([['S', '.', '.', '.', 'S']], self.dungeon.dungeon)
        weapons = list(map(lambda x: x.type, deepcopy(self.dungeon.weapons)))
        self.assertEqual(["Spoon", "RustyFork"], weapons)
        self.assertEqual({}, self.dungeon.players)

    def test_load_map(self):
        self.assertEqual([['S', '.', '.', '.', 'S']],
                         self.dungeon.load_map("test_file.txt"))

    def test_is_map_row(self):
        self.assertTrue(self.dungeon.is_map_row("#..S..#"))
        self.assertFalse(self.dungeon.is_map_row("##Not.really.a.row"))

    def test_set_weapons(self):
        self.dungeon.weapons = []
        self.dungeon.set_weapons(["Knife 7 0.3"])
        self.assertEqual("Knife", self.dungeon.weapons[0].type)
        self.assertEqual(7.0, self.dungeon.weapons[0].damage)
        self.assertEqual(0.3, self.dungeon.weapons[0].critical_strike_percent)

    def test_print_map(self):
        self.assertTrue(self.dungeon.print_map())

    def test_free_spawning_points(self):  # help function
        self.dungeon.dungeon = [['T'], ['T']]
        self.assertFalse(self.dungeon.free_spawning_points())
        self.dungeon.dungeon = [['T'], ['S']]
        self.assertTrue(self.dungeon.free_spawning_points())

    def test_spawn(self):
        self.assertTrue(self.dungeon.spawn("player 1", self.hero))
        self.assertTrue(self.dungeon.spawn("player 2", self.orc))
        self.assertEqual({"player 1": (self.hero, 0, 0),
                          "player 2": (self.orc, 4, 0)}, self.dungeon.players)

    def test_spawn_player_not_unique_value_error(self):
        self.dungeon.spawn("player 1", self.hero)
        with self.assertRaises(ValueError):
            self.dungeon.spawn("player 1", self.hero)

    def test_spawn_no_spawning_points(self):
        self.dungeon.dungeon = [['.', '.']]
        self.assertFalse(self.dungeon.spawn("player 1", self.hero))

    def test_entity_kind(self):
        self.assertEqual('H', self.dungeon.entity_kind(self.hero))
        self.assertEqual('O', self.dungeon.entity_kind(self.orc))

    def test_entity_kind_wrong_instance(self):
        with self.assertRaises(ValueError):
            self.dungeon.entity_kind("tomatoe")

    def test_move(self):
        self.dungeon.dungeon = [['S', '.']]
        self.dungeon.spawn("player", self.hero)
        self.dungeon.move("player", "right")
        self.assertEqual([['.', 'H']], self.dungeon.dungeon)

    def test_move_obstacle(self):
        self.dungeon.dungeon = [['S', '#']]
        self.dungeon.spawn("player", self.hero)
        self.assertFalse(self.dungeon.move("player", "right"))

    def test_move_out_of_bounds(self):
        self.dungeon.spawn("player", self.hero)
        self.assertFalse(self.dungeon.move("player", "up"))

    def test_move_weapon_found(self):
        self.dungeon.dungeon = [['S', '.']]
        weapon = Weapon("Knife", 7, 0.3)
        self.dungeon.weapons = [weapon]
        self.dungeon.spawn_weapons()
        self.dungeon.spawn("player", self.hero)
        self.dungeon.move("player", "right")
        self.assertEqual(weapon, self.dungeon.players["player"][0].weapon)
        self.assertEqual([['.', 'H']], self.dungeon.dungeon)

    def test_move_start_fight(self):
        self.dungeon.spawn("player 1", self.hero)
        self.dungeon.spawn("player 2", self.orc)
        self.dungeon.spawn_weapons()
        self.dungeon.move("player 1", "right")
        self.dungeon.move("player 1", "right")
        self.dungeon.move("player 2", "left")
        self.dungeon.move("player 2", "left")
        self.assertTrue([['.', '.', 'H', '.', '.']] == self.dungeon.dungeon or
#.........这里部分代码省略.........
开发者ID:Fusl,项目名称:Hack-Bulgaria-Programming-101,代码行数:103,代码来源:dungeon_test.py

示例11: TestDungeon

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move [as 别名]
class TestDungeon(unittest.TestCase):
    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)
        #self.dung.print_map()

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

    def test_dungeon_init(self):
        self.assertEqual(self.list, self.dung2.map)

    def test_spawn(self):
        self.assertTrue(self.spawn_hero)
        self.assertTrue(self.spawn_orc)
        self.assertFalse(self.spawn_orc2)

    def test_spawn_right_positions(self):
        player1 = self.dung.players["player2"]
        self.assertListEqual(player1, [self.test_orc, 0, 9])
        self.assertEqual(self.dung.map[0][9], "O")
        self.assertEqual(self.dung.map[3][1], "H")

    def test_move_right(self):
        move_hero_right = self.dung.move("player1", "right")
        move_orc_right = self.dung.move("player2", "right")
        self.assertTrue(move_hero_right)
        self.assertFalse(move_orc_right)

    def test_move_left(self):
        move_hero_left = self.dung.move("player1", "left")
        move_orc_left = self.dung.move("player2", "left")
        self.assertFalse(move_hero_left)
        self.assertTrue(move_orc_left)
        #self.dung.print_map()

    def test_move_up(self):
        move_hero_up = self.dung.move("player1", "up")
        move_orc_up = self.dung.move("player2", "up")
        self.assertTrue(move_hero_up)
        self.assertFalse(move_orc_up)
        #self.dung.print_map()

    def test_move_down(self):
        self.dung.move("player1", "right")
        move_hero_down = self.dung.move("player1", "down")
        move_orc_down = self.dung.move("player2", "down")

        self.assertFalse(move_hero_down)
        self.assertTrue(move_orc_down)
        #self.dung.print_map()

    def test_get_player_by_coordinates(self):
        player = self.dung.get_player_by_coordinates(3, 1)
        self.assertEqual("player1", player)

    def test_fight_right(self):
        self.spawn_hero = self.dung2.spawn("player1", self.test_hero)
        self.spawn_orc = self.dung2.spawn("player2", self.test_orc)
        move_orc_right = self.dung2.move("player1", "right")
        self.assertTrue(move_orc_right)

    def test_fight_left(self):
        self.spawn_hero = self.dung2.spawn("player1", self.test_hero)
        self.spawn_orc = self.dung2.spawn("player2", self.test_orc)

        move_orc_left = self.dung2.move("player2", "left")
        self.assertTrue(move_orc_left)


    def test_fight_up(self):
        self.spawn_hero = self.dung2.spawn("player1", self.test_hero)
#.........这里部分代码省略.........
开发者ID:nkgeorgiev,项目名称:HackBulgaria---Programming101---2,代码行数:103,代码来源:dungeon_test.py

示例12: TestDungeon

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move [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

示例13: DungeonTests

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

    def setUp(self):
        self.single_loc_map = Dungeon("single_map.txt")
        self.paladin = Hero("Arthas", 100, "Warhammer")
        self.single_loc_map.spawn("player_1", self.paladin)

    def test_dungeon_init(self):
        new_dungeon = Dungeon("new_dungeon.txt")
        self.assertEqual(new_dungeon.path, "new_dungeon.txt")

    def test_path_reading(self):
        expected_content = "S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S\n"
        new_dungeon = Dungeon("new_dungeon.txt")
        self.assertEqual(new_dungeon.content, expected_content)

    def test_create_map_array(self):
        new_dungeon = Dungeon("dung_arr.txt")
        expected_array = [["1", "2", "3"], ["4", "5", "6"]]
        self.assertEqual(new_dungeon.map_array, expected_array)

    def test_spawn_return_false(self):
        false_map = Dungeon("false_map.txt")
        tmp_arr = false_map.map_array
        self.assertFalse(false_map.spawn("player_1", self.paladin))
        self.assertEqual(false_map.map_array, tmp_arr)

    def test_spawn_single_location(self):
        expected_arr = [['H', '.', '#', '#', '.', '.', '.', '.', '.', '.'],
                        ['#', '.', '#', '#', '.', '.', '#', '#', '#', '.'],
                        ['#', '.', '#', '#', '#', 'S', '#', '#', '#', '.'],
                        ['#', '.', '.', '.', '.', '.', '#', '#', '#', '.'],
                        ['#', '#', '#', '.', '#', '#', '#', '#', '#', '#']]
        self.assertEqual(self.single_loc_map.map_array, expected_arr)

    def test_moving_right_true(self):
        expected_arr = [['.', 'H', '#', '#', '.', '.', '.', '.', '.', '.'],
                        ['#', '.', '#', '#', '.', '.', '#', '#', '#', '.'],
                        ['#', '.', '#', '#', '#', 'S', '#', '#', '#', '.'],
                        ['#', '.', '.', '.', '.', '.', '#', '#', '#', '.'],
                        ['#', '#', '#', '.', '#', '#', '#', '#', '#', '#']]
        self.single_loc_map.move("player_1", "right")
        self.assertEqual(self.single_loc_map.map_array, expected_arr)

    def test_moving_down_true(self):
        expected_arr = [['.', '.', '#', '#', '.', '.', '.', '.', '.', '.'],
                        ['#', 'H', '#', '#', '.', '.', '#', '#', '#', '.'],
                        ['#', '.', '#', '#', '#', 'S', '#', '#', '#', '.'],
                        ['#', '.', '.', '.', '.', '.', '#', '#', '#', '.'],
                        ['#', '#', '#', '.', '#', '#', '#', '#', '#', '#']]
        self.single_loc_map.move("player_1", "right")
        self.single_loc_map.move("player_1", "down")
        self.assertEqual(self.single_loc_map.map_array, expected_arr)

    def test_moving_left_False(self):
        self.assertFalse(self.single_loc_map.move("player_1", "left"))

    def test_moving_up_False(self):
        self.assertFalse(self.single_loc_map.move("player_1", "up"))

    def test_moving_wrong_input(self):
        self.assertFalse(self.single_loc_map.move("player_1", "dqsno"))

    def test_give_me_player_own_coordinates(self):
        x, y = self.single_loc_map._give_me_own_players_coordinates("player_1")
        self.assertEqual(x, 0)
        self.assertEqual(y, 0)

    def test_return_entity_letter(self):
        self.assertEqual(self.single_loc_map._return_entity_letter(self.paladin), "H")

    def test_give_me_own_players_coordinates(self):
        x, y = self.single_loc_map._give_me_own_players_coordinates("player_1")
        self.assertEqual(x, 0)
        self.assertEqual(y, 0)

    def test_change_own_players_coordinates_down_right(self):
        self.single_loc_map._change_own_players_coordinates("player_1", "right")
        self.single_loc_map._change_own_players_coordinates("player_1", "down")
        tmp_arr = self.single_loc_map.entities_dic["player_1"]
        x = tmp_arr[0]
        y = tmp_arr[1]
        self.assertEqual(x, 1)
        self.assertEqual(y, 1)

    def test_give_me_player_instance(self):
        instance = self.single_loc_map._give_me_player_instance("player_1")
        self.assertEqual(self.paladin, instance)

    def test_move_left_right(self):
        self.assertFalse(self.single_loc_map._move_left_right("player_1", "left"))
        expected_arr = [['.', 'H', '#', '#', '.', '.', '.', '.', '.', '.'],
                        ['#', '.', '#', '#', '.', '.', '#', '#', '#', '.'],
                        ['#', '.', '#', '#', '#', 'S', '#', '#', '#', '.'],
                        ['#', '.', '.', '.', '.', '.', '#', '#', '#', '.'],
                        ['#', '#', '#', '.', '#', '#', '#', '#', '#', '#']]
        self.single_loc_map._move_left_right("player_1", "right")
        self.assertEqual(self.single_loc_map.map_array, expected_arr)
        tmp_arr = self.single_loc_map.entities_dic["player_1"]
        x = tmp_arr[0]
#.........这里部分代码省略.........
开发者ID:mihail-nikolov,项目名称:hackBG,代码行数:103,代码来源:test_dungeon.py

示例14: TestDungeon

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move [as 别名]
class TestDungeon(unittest.TestCase):
    def setUp(self):
        self.content = 'S.##......\n#.##..###.\n#.###.###.\n#.....###.\n###.#####S'
        self.filename = "basic_dungeon.txt" 
        self.file = open(self.filename,'w')
        self.file.write(self.content)
        self.file.close()

        ##-------------------------

        self.new_map = Dungeon(self.filename)
    def tearDown(self):
        #pass
        os.remove(self.filename)

    
    def test_spawn_true(self):
        player1 = Hero("Bron", 100, "DragonSlayer")
        player2 = Orc('karakondjul', 100 , 1.5)
        self.assertTrue(self.new_map.spawn(player1.name, player1))
        self.assertTrue(self.new_map.spawn(player2.name, player2))

        #self.new_map.print_map()

    def test_spawn_false(self):
        player1 = Hero("Bron", 100, "DragonSlayer")
        player2 = Orc('karakondjul', 100 , 1.5)
        player3 = Hero("Bron1", 100, "DragonSlayer")
        self.assertTrue(self.new_map.spawn(player1.name, player1))
        self.assertTrue(self.new_map.spawn(player2.name, player2))
        self.assertFalse(self.new_map.spawn(player3.name, player3))

        #self.new_map.print_map()

    def test_print_map(self):
        
        self.assertEqual(self.new_map.get_content(),self.content)
        #print(self.content)
        #self.new_map.print_map()

    def test_move_right_true(self):
        player1 = Hero("Bron", 100, "DragonSlayer")
        self.new_map.spawn(player1.name, player1)
        self.assertTrue(self.new_map.move(player1.name,"right"))
        #self.new_map.print_map()

    def test_move_right_false(self):
        player1 = Hero("Bron", 100, "DragonSlayer")
        player2 = Orc('karakondjul', 100 , 1.5)
        self.new_map.spawn(player1.name, player1)
        self.new_map.spawn(player2.name, player2)
        #self.new_map.move(player1.name,"right")
        self.assertFalse(self.new_map.move(player2.name,"right"))
        #self.new_map.print_map()

    def test_move_left_true(self):
        player1 = Hero("Bron", 100, "DragonSlayer")
        self.new_map.spawn(player1.name, player1)
        self.new_map.move(player1.name,"right")
        #self.new_map.print_map()
        self.assertTrue(self.new_map.move(player1.name,"left"))
        #self.new_map.print_map()

    def test_move_left_false(self):
        player1 = Hero("Bron", 100, "DragonSlayer")
        self.new_map.spawn(player1.name, player1)
        self.assertFalse(self.new_map.move(player1.name,"left"))
        #self.new_map.print_map()

    def test_move_up_true(self):
        player1 = Hero("Bron", 100, "DragonSlayer")
        player2 = Orc('karakondjul', 100 , 1.5)
        self.new_map.spawn(player1.name, player1)
        self.new_map.spawn(player2.name, player2)
        self.assertTrue(self.new_map.move(player2.name,"up"))
        #self.new_map.print_map()

    def test_move_up_false(self):
        player1 = Hero("Bron", 100, "DragonSlayer")
        self.new_map.spawn(player1.name, player1)
        self.assertFalse(self.new_map.move(player1.name,"up"))
        #self.new_map.print_map()

    def test_move_down_true(self):
        player1 = Hero("Bron", 100, "DragonSlayer")
        self.new_map.spawn(player1.name, player1)

        self.new_map.move(player1.name,"right")
        self.assertTrue(self.new_map.move(player1.name,"down"))
        #self.new_map.print_map()

    def test_move_down_false(self):
        player1 = Hero("Bron", 100, "DragonSlayer")
        player2 = Orc('karakondjul', 100 , 1.5)
        self.new_map.spawn(player1.name, player1)
        self.new_map.spawn(player2.name, player2)
        self.assertFalse(self.new_map.move(player2.name,"down"))
        #self.new_map.print_map()
#ok
    def test_move_right_and_fight(self):
#.........这里部分代码省略.........
开发者ID:dsspasov,项目名称:HackBulgaria,代码行数:103,代码来源:dungeon_test.py

示例15: __init__

# 需要导入模块: from dungeon import Dungeon [as 别名]
# 或者: from dungeon.Dungeon import move [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


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