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


Python Question.is_answer方法代码示例

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


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

示例1: __init__

# 需要导入模块: from question import Question [as 别名]
# 或者: from question.Question import is_answer [as 别名]

#.........这里部分代码省略.........
            self.buttons[0].set_text(str(self.question.choices[0]))
            self.buttons[1].set_text(str(self.question.choices[1]))
            self.buttons[2].set_text(str(self.question.choices[2]))
            self.buttons[3].set_text(str(self.question.choices[3]))

            self.buttons[0].set_color(self.buttons[0].color, False)
            self.buttons[1].set_color(self.buttons[0].color, False)
            self.buttons[2].set_color(self.buttons[0].color, False)
            self.buttons[3].set_color(self.buttons[0].color, False)

            self.question_text_label = self.lg_font.render(str(self.question), 1, Color.BLACK)
            self.hurdle_number += 1
            self.score_label = self.lg_font.render(str(self.points),1,Color.BLACK)
            self.question_label = self.font.render("Hurdle #" + str(self.hurdle_number), 1, Color.BLACK)
            question_board.fill(Color.WHITE)

            self.score_label = self.lg_font.render(str(self.points), 1, Color.BLACK)

        def set_answer(answer_index):
            #unselect the previous answer button
            if self.last_answer_index >= 0:
                self.buttons[self.last_answer_index].set_selected(False)
            
            if answer_index >= 0:
                self.last_answer = Fraction(self.buttons[answer_index].text)
                self.buttons[answer_index].set_selected(True)
                self.last_answer_index = answer_index
            else:
                self.last_answer = -1
                self.last_answer_index = -1
            

        def evaluate_answer(answer):
            if self.question.is_answer(answer):
                self.points += 100
                self.score_label = self.lg_font.render(str(self.points), 1, Color.BLACK)
                self.jump_sfx.play()
            else:
                self.set_gameover(True)
                if self.last_answer_index >= 0:
                    self.buttons[self.last_answer_index].set_color(Color.RED, False)
                
            self.buttons[self.question.answer_index].set_color(Color.GREEN, False)

        while self.running:
            if self.playing:
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        pygame.quit()
                        return
                    elif event.type == pygame.VIDEORESIZE:
                        pygame.display.set_mode(event.size, pygame.RESIZABLE)
                    elif event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_p:
                            self.paused = not self.paused
                        elif event.key == pygame.K_c:
                            set_answer(self.question.answer_index)
                    elif event.type == pygame.MOUSEBUTTONDOWN:
                        if not self.gameover:
                            for i in range(0, 4):
                                self.buttons[i].mouse_click(
                                    pygame.mouse.get_pos(),
                                    set_answer,
                                    i
                                )
开发者ID:craigcabrey,项目名称:math-hurdler,代码行数:69,代码来源:math-hurdler.py


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