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


Python Game.is_over方法代码示例

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


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

示例1: test_black_win

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import is_over [as 别名]
 def test_black_win(self):
     game = Game(3, Game.Modes.human_human, Game.DifficultyLevels.easy,
                 True, 5)
     self.assertTrue(not game.is_over())
     self.play_game_sequence(game, ['b1', 'a1', 'c3', 'c1'])
     self.assertTrue(game.is_over())
     self.assertEqual(game.BLACK_MSG, game.get_winner_message())
开发者ID:ElenaArslanova,项目名称:rev,代码行数:9,代码来源:tests.py

示例2: test_game_is_over

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import is_over [as 别名]
 def test_game_is_over(self):
     game1 = Game(3, Game.Modes.human_human, Game.DifficultyLevels.easy,
                  True, 5)
     self.play_game_sequence(game1, ['b1', 'a1', 'c1', 'c3'])
     self.assertTrue(game1.is_over())
     game2 = Game(2, Game.Modes.human_human, Game.DifficultyLevels.easy,
                  True, 5)
     self.assertTrue(game2.is_over())
开发者ID:ElenaArslanova,项目名称:rev,代码行数:10,代码来源:tests.py

示例3: test_white_win

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import is_over [as 别名]
 def test_white_win(self):
     game = Game(4, Game.Modes.human_human, Game.DifficultyLevels.easy,
                 True, 5)
     self.assertTrue(not game.is_over())
     self.play_game_sequence(game, ['d2', 'd3', 'd4', 'b1', 'a3', 'b4',
                                    'a4', 'a2', 'c4'])
     self.assertTrue(game.is_over())
     self.assertEqual(game.WHITE_MSG, game.get_winner_message())
开发者ID:ElenaArslanova,项目名称:rev,代码行数:10,代码来源:tests.py

示例4: main

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import is_over [as 别名]
def main(width=4, height=4, goal=2048, intial_value=2):
    game = Game(int(width), int(height), int(goal), int(intial_value))
    game.start()

    while True:
        try:
            pretty_print(game.grid)

            line = raw_input("> ").strip().lower()

            if line == "q" or line == "quit":
                print "bye"
                return

            dir_ = get_dir(line)

            if dir_ is None:
                print "options: %s, q" % (", ".join(sorted(dirs.keys())))
                continue

            game.slam(dir_)

            if game.is_over():
                pretty_print(game.grid)

                if game.goal_met():
                    print "You won! Yay!"
                else:
                    print "Game over! You suck!"
                return

        except KeyboardInterrupt:
            print
            return
开发者ID:edwarburg,项目名称:gridgame,代码行数:36,代码来源:main.py

示例5: test_tie

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import is_over [as 别名]
 def test_tie(self):
     game = Game(2, Game.Modes.human_human, Game.DifficultyLevels.easy,
                 True, 5)
     self.assertTrue(game.is_over())
     self.assertEqual(game.TIE_MSG, game.get_winner_message())
开发者ID:ElenaArslanova,项目名称:rev,代码行数:7,代码来源:tests.py

示例6: ReversiWindow

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import is_over [as 别名]

#.........这里部分代码省略.........
            image)

    def draw_text(self, painter, font_size):
        painter.setPen(QColor(Qt.black))
        painter.setFont(QFont('Decorative', font_size))
        painter.drawText(QPoint(10, self.toolbar.height() + font_size),
                         'Time left for move: {}'.format(self.count))

    def reset_count(self):
            if not self.ai_thread.isRunning():
                self.count = self.time_for_move

    def count_down(self):
        if self.count != 0:
            self.count -= 1
        else:
            if not self.ai_thread.isRunning():
                self.game.pass_move()
                self.reset_count()
                self.update()

    def ai_finish(self):
        self.update()
        self.reset_count()
        self.ai_finished = True

    def load_images(self):
        images_path = os.path.join(os.getcwd(), 'images')
        for image in os.listdir(images_path):
            self.images[image] = QImage(os.path.join(images_path, image))

    def mousePressEvent(self, QMouseEvent):
        if self.game.game_state == Game.States.human:
            position = QMouseEvent.pos()
            position.setY(
                position.y() - self.toolbar.height() - self.font_size)
            self.game.next_move(position)
            if self.game.game_state == Game.States.ai:
                self.reset_count()
            self.update()

    def timerEvent(self, event):
        if self.game.is_over():
            self.timer.stop()
            self.move_timer.stop()
            self.show_end_of_game_dialog()
        else:
            if self.game.game_state == Game.States.ai and self.ai_finished:
                self.ai_finished = False
                self.ai_thread.start()
        self.update()

    def paintEvent(self, event):
        with painter(self) as p:
            for cell in self.game.mover.board.cells():
                self.draw_cell(p, cell)
            self.draw_text(p, self.font_size)

    def show_end_of_game_dialog(self):
        message_box = QMessageBox()
        message_box.setText('The game is over! {}'.format
                            (self.game.get_winner_message()))
        message_box.exec_()
        if self.game_was_saved:
            self.ask_question(
                'Do you want to play from your last saved position?',
                message_box)
            self.check_answer(message_box.exec_(), self.load_saved_game,
                              self.play_again_action)
        else:
            self.play_again_action()

    def play_again_action(self):
        message_box = QMessageBox()
        message_box.setText('Do you want to play again?')
        self.ask_question('', message_box)
        self.check_answer(message_box.exec_(), self.restart,
                          self.close)

    def restart(self):
        self.game_was_saved = False
        self.game.restart()
        self.timer.start(1, self)
        self.move_timer.start(1000)

    def load_saved_game(self):
        with open('saved_game.pickle', 'rb') as f:
            self.game = pickle.load(f)
            self.timer.start(1, self)

    def ask_question(self, question, message_box):
        message_box.setInformativeText(question)
        message_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)

    def check_answer(self, clicked_button, yes_action, no_action):
        if clicked_button == QMessageBox.Yes:
            yes_action()
        elif clicked_button == QMessageBox.No:
            no_action()
        self.update()
开发者ID:ElenaArslanova,项目名称:rev,代码行数:104,代码来源:reversi.py


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