本文整理汇总了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
#.........这里部分代码省略.........