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


Python Fight.start_attack方法代码示例

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


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

示例1: Dungeon

# 需要导入模块: from fight import Fight [as 别名]
# 或者: from fight.Fight import start_attack [as 别名]
class Dungeon(Fight):

    @staticmethod
    def load(file_name):
        opened = open(file_name, "r")
        my_file = opened.read().split("\n")
        lists = [lis for lis in my_file if lis.strip() != ""]
        place = [[elem for elem in x] for x in lists]
        opened.close()
        return place

    def __init__(self, file_name):
        self.place = Dungeon.load(file_name)
        self.treasures_list = {
                                "mana":[10,15,20,30],
                                "health":[10,12,17,23],
                                "weapon":[Weapon("Axe", 20), Weapon("Water_sword", 40)],
                                "spell":[Spell("low_level", 10, 20, 1), Spell("strong", 30, 70, 6)]}
        self.hero = Our_Hero("Gayster", "GaySlayer")
        self.enemy = Enemy(health=100, mana=100, damage=20)
        self.f = Fight(self.hero, self.enemy)
    def spawn(self, hero):
        if hero.is_alive():
            for elem in self.place:
                for x in elem:
                    if x == "S":
                        self.place[self.place.index(elem)][elem.index(x)] = "H"
                        return True
            else:
                return False
        else:
            return False

    def move_hero(self, direction):
        if direction not in ["up", "down", "left", "right"]:
            raise ValueError("Invalid direction")
        elif self.hero.is_alive():
            if direction == "up":
                for elem in self.place:
                    for x in elem:
                        if "H" in elem:
                            if self.place.index(elem) - 1 >= 0:
                                if self.place[self.place.index(elem) - 1][elem.index("H")] == ".":
                                    self.place[self.place.index(elem) - 1][elem.index("H")] = "H"
                                    self.place[self.place.index(elem)][elem.index("H")] = "."
                                    return True
                                if self.place[self.place.index(elem) - 1][elem.index("H")] == "#":
                                    return False
                                if self.place[self.place.index(elem) - 1][elem.index("H")] == "E":
                                    self.place[self.place.index(elem) - 1][elem.index("H")] = "H"
                                    self.place[self.place.index(elem)][elem.index("H")] = "."
                                    return self.f.start_attack()
                                if self.place[self.place.index(elem) - 1][elem.index("H")] == "T":
                                    self.place[self.place.index(elem) - 1][elem.index("H")] = "H"
                                    self.place[self.place.index(elem)][elem.index("H")] = "."
                                    return self.pick_treasure()
                                if self.place[self.place.index(elem) - 1][elem.index("H")] == "G":
                                    self.place[self.place.index(elem) - 1][elem.index("H")] = "H"
                                    self.place[self.place.index(elem)][elem.index("H")] = "."
                                    print("Our Hero Escaped! You win!")
                                    return sys.exit()
                            else:
                                return False
            if direction == "down":
                for elem in self.place:
                    for x in elem:
                        if "H" in elem:
                            if self.place.index(elem) + 1 <= len(self.place) - 1:
                                if self.place[self.place.index(elem) + 1][elem.index("H")] == ".":
                                    self.place[self.place.index(elem) + 1][elem.index("H")] = "H"
                                    self.place[self.place.index(elem)][elem.index("H")] = "."
                                    return True
                                if self.place[self.place.index(elem) + 1][elem.index("H")] == "#":
                                    return False
                                if self.place[self.place.index(elem) + 1][elem.index("H")] == "E":
                                    self.place[self.place.index(elem) + 1][elem.index("H")] = "H"
                                    self.place[self.place.index(elem)][elem.index("H")] = "."
                                    return self.f.start_attack()
                                if self.place[self.place.index(elem) + 1][elem.index("H")] == "T":
                                    self.place[self.place.index(elem) + 1][elem.index("H")] = "H"
                                    self.place[self.place.index(elem)][elem.index("H")] = "."
                                    return self.pick_treasure()
                                if self.place[self.place.index(elem) + 1][elem.index("H")] == "G":
                                    self.place[self.place.index(elem) + 1][elem.index("H")] = "H"
                                    self.place[self.place.index(elem)][elem.index("H")] = "."
                                    print("Our Hero Escaped! You win!")
                                    return sys.exit()
                            else:
                                return False
            if direction == "right":
                for elem in self.place:
                    for x in elem:
                        if "H" in elem:
                            if elem.index("H") + 1 <= len(elem) - 1:
                                if self.place[self.place.index(elem)][elem.index("H") + 1] == ".":
                                    self.place[self.place.index(elem)][elem.index("H") + 1] = "H"
                                    self.place[self.place.index(elem)][elem.index("H")] = "."
                                    return True
                                if self.place[self.place.index(elem)][elem.index("H") + 1] == "#":
                                    return False
#.........这里部分代码省略.........
开发者ID:VladislavAtanasov,项目名称:Dungeons-and-Pythons,代码行数:103,代码来源:dungeon.py


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