本文整理汇总了Python中ui.UI.welcome方法的典型用法代码示例。如果您正苦于以下问题:Python UI.welcome方法的具体用法?Python UI.welcome怎么用?Python UI.welcome使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ui.UI
的用法示例。
在下文中一共展示了UI.welcome方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import welcome [as 别名]
class World:
def run(self):
self.player = Monster(name='Player')
self._load_history(self.player)
monster = random.choice(list(monsters.viewkeys()))
self.monster = Monster(monsters[monster][0], monster, description=monsters[monster][1])
self.ui = UI(self.player)
self.ui.monster = self.monster
self.ui.welcome()
a = 1
while a != 0:
self._load_history(self.monster)
a = self.run_loop()
if a != 0:
self.ui.update_display()
self._save_history(self.player)
self._save_history(self.monster)
monster = random.choice(list(monsters.viewkeys()))
self.monster = Monster(monsters[monster][0], monster, description=monsters[monster][1])
self.ui.monster = self.monster
def run_loop(self):
player_move = "Run"
while player_move.lower() != ACTION_QUIT:
if self.player.offbalance:
moves = [MOVE_BASH, MOVE_DEFEND]
else:
moves = [MOVE_ATTACK, MOVE_BASH, MOVE_DEFEND]
if self.monster.offbalance:
monster_moves = [MOVE_BASH, MOVE_DEFEND]
else:
monster_moves = [MOVE_ATTACK, MOVE_BASH, MOVE_DEFEND]
player_move = self.ui.player_move(moves)
if player_move == ACTION_QUIT:
break
if player_move not in moves:
self.ui.msg = "I don't understand your input, try again."
self.ui.update_display()
continue
monster_move = self.monster.attack(monster_moves, self.player)
self.ui.monster.move = monster_move
self.ui.player.move = player_move
if player_move + monster_move in action_table:
outcome = action_table[player_move + monster_move]
self.monster.take_damage(outcome[2])
self.monster.offbalance = outcome[3]
self.player.take_damage(outcome[0])
self.player.offbalance = outcome[1]
else:
outcome = action_table[monster_move + player_move]
self.monster.take_damage(outcome[0])
self.monster.offbalance = outcome[1]
self.player.take_damage(outcome[2])
self.player.offbalance = outcome[3]
# record the moves just made for the AI
self.player.history.append(player_move)
self.monster.history.append(monster_move)
self.ui.update_display()
if self.player.is_dead() and self.monster.is_dead():
self.ui.msg = "You have slain the foul " + self.monster.name + ", but it appears that, in its dying throes, the " + self.monster.name + "has also slain you."
return 0
elif self.player.is_dead():
self.ui.msg = "Oh no! You seem to have perished!"
return 0
elif self.monster.is_dead():
self.ui.msg = "You have slain the " + self.monster.name + "."
return 1
return 0
def _load_history(self, monster):
name = 'player'
if monster.name.lower() != 'player':
name = 'monster'
try:
f = open(name + '.moves', 'r+')
monster.history = pickle.load(f)
f.close()
except Exception:
pass
def _save_history(self, monster):
name = 'player'
if monster.name.lower() != 'player':
#.........这里部分代码省略.........