本文整理汇总了Python中hero.Hero.print_char方法的典型用法代码示例。如果您正苦于以下问题:Python Hero.print_char方法的具体用法?Python Hero.print_char怎么用?Python Hero.print_char使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hero.Hero
的用法示例。
在下文中一共展示了Hero.print_char方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LevelUp
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import print_char [as 别名]
class LevelUp():
def __init__(self, code):
self.lines = code.splitlines()
self.line_num = 0
# Get name from first line (optional)
try:
name_line = re.match("Name\s?:\s?(.+)", self.lines[0], re.I)
name = name_line.groups(0)[0]
self.lines = self.lines[1:]
except IndexError:
name = "Hero"
# Get class
try:
class_line = re.match("Class\s?:\s?(.+)", self.lines[0], re.I)
hero_class = class_line.groups(0)[0].title()
self.lines = self.lines[1:]
except IndexError:
exit("Error: Missing or invalid class line")
self.hero = Hero(name, hero_class)
self.labels = {}
self.quest = None
self.input = None
self.expected = None
self.output = None
self.quest_line_num = None
self.getch = _Getch()
def run(self):
while self.line_num < len(self.lines):
self.execute_line(self.lines[self.line_num])
self.line_num += 1
def execute_line(self, line):
line = line.strip()
if not line or line[0] == '#':
return
line_types = [["^(\w+):$", self.set_label, []],
["^jmp (\w+)$", self.jump_to_label, [Skills.JMP]],
["^jez (\w+)\s+(\w+)$", self.jump_to_label, [Skills.JEZ]],
["^inc (\w+)$", self.hero.increment, [Skills.INCREMENT]],
["^dec (\w+)$", self.hero.decrement, [Skills.DECREMENT]],
["^pch (\w+)$", self.print_char, [Skills.PRINT_CHAR]],
["^ich (\w+)$", self.input_char, [Skills.INPUT_CHAR]],
["^add (\w+) (\w+) (\w+)$", self.hero.add, [Skills.ADDITION]],
["^Begin quest: '([\w ]+)'$", self.begin_quest, []],
["^Claim reward$", self.claim_reward, []]]
for regex, func, prereqs in line_types:
match = re.match(regex, line, re.I)
if match:
for skill in prereqs:
if skill not in self.hero.skills:
exit("Error: need skill '{}' for line '{}'!".format(skill.value, line))
func(*match.groups())
return
exit("Error: Invalid line '{}'".format(line))
def set_label(self, label):
self.labels[label] = self.line_num
def jump_to_label(self, *args):
label = args[-1]
if len(args) < 2 or self.hero.get_elem(args[0]) == 0:
if label not in self.labels:
try:
label_match = re.match("(\w+):", self.lines[self.line_num])
while not label_match:
self.line_num += 1
label_match = re.match("(\w+):", self.lines[self.line_num])
except IndexError:
exit("Error: Invalid label {}".format(label))
else:
self.line_num = self.labels[label]
def input_char(self, name):
if self.quest is None:
if sys.stdin.isatty():
# Console
#.........这里部分代码省略.........