本文整理汇总了Python中ui.UI.add_input方法的典型用法代码示例。如果您正苦于以下问题:Python UI.add_input方法的具体用法?Python UI.add_input怎么用?Python UI.add_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ui.UI
的用法示例。
在下文中一共展示了UI.add_input方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GameOver
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import add_input [as 别名]
class GameOver(State):
def __init__(self, score):
State.__init__(self)
self.ui = UI(self, Jules_UIContext)
self.nextState = lambda: SplashScreen(current=1)
self.eventid = TimerEvents.GameOver
self.score = score
self.countdown = 5 * 1000
for key, (name, value) in sorted(HighScores.high_scores.items()):
if score > value:
self.replace = key
break
else:
self.replace = None
def start(self):
if self.replace == None:
TimerEvents().start(self.eventid, self.countdown)
State.start(self)
def handle(self, event):
if event.type == self.eventid:
self.transition()
def transition(self):
TimerEvents().stop(self.eventid)
State.transition(self)
def input_text(self, text):
new_scores = {}
text = text.upper()
old_scores = sorted(HighScores.high_scores.keys())
index = old_scores.index(self.replace)
for key in old_scores[:index]:
new_scores[key] = HighScores.high_scores[key]
new_scores[self.replace] = (text, self.score)
for index in xrange(index + 1, len(HighScores.high_scores)):
new_scores[old_scores[index]] = HighScores.high_scores[old_scores[index - 1]]
HighScores.high_scores = new_scores
high_scores.save()
self.transition()
def setup(self, screen):
if self.replace == None:
pass
else:
size = (75, 50)
location = ((W/2) - (size[0] / 2), 6 * H/10)
with self.ui.newcontext(UIContext(font_size=30, len_cap=3)):
self.ui.add_input(screen, "___",
lambda text: self.input_text(text),
location=location, size=size)
def update(self, screen):
if self.replace == None:
self.ui.draw_text(screen, "Game Over", (W/2, H/10), align=0)
self.ui.draw_text(screen, "Your Score: " + str(self.score),
(W/2, 3 * H/10), align=0)
else:
self.ui.draw_text(screen, "Game Over", (W/2, H/10), align=0)
self.ui.draw_text(screen, "New High Score!", (W/2, 3*H/10), align=0)
self.ui.draw_text(screen, "Your Score: " + str(self.score),
(W/2, 4 * H/10), align=0)
self.ui.draw_text(screen, "Enter your initials:", (W/2, 5 * H/10),
align=0)