From 58c6e61a30fc8ae7446ff59fcf4fdbb49ce09f26 Mon Sep 17 00:00:00 2001 From: Jerry Date: Mon, 31 Dec 2018 10:57:09 +0800 Subject: [PATCH] stop the game right after the player wins or loses --- tgmsbot.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tgmsbot.py b/tgmsbot.py index c271586..5b5fbd1 100644 --- a/tgmsbot.py +++ b/tgmsbot.py @@ -60,6 +60,7 @@ class Game(): self.actions = dict() self.last_player = None self.start_time = time.time() + self.stopped = False self.extra = {"timeout": 0} def save_action(self, user, spot): '''spot is supposed to be a tuple''' @@ -211,6 +212,8 @@ def handle_button_click(bot, update): if game is None: logger.debug("No game found for hash {}".format(bhash)) return + elif game.stopped: + return board = game.board if board.state == 0: mmap = None @@ -221,6 +224,7 @@ def handle_button_click(bot, update): mmap = deepcopy(board.map) board.move((row, col)) if board.state != 1: + game.stopped = True # if this is the first move, there's no mmap if mmap is not None: game.save_action(user, (row, col)) @@ -240,10 +244,9 @@ def handle_button_click(bot, update): time=round(time_used, 4), timeouts=timeouts) msg.reply_text(myreply, parse_mode="Markdown") game_manager.remove(bhash) - else: - if mmap is not None and (not array_equal(board.map, mmap)): - game.save_action(user, (row, col)) - update_keyboard(bot, bhash, game, chat_id, msg.message_id) + elif mmap is not None and (not array_equal(board.map, mmap)): + game.save_action(user, (row, col)) + update_keyboard(bot, bhash, game, chat_id, msg.message_id)