diff --git a/mscore.py b/mscore.py index fe85643..7c1533a 100644 --- a/mscore.py +++ b/mscore.py @@ -18,7 +18,9 @@ IS_MINE = 9 DEAD = 20 def check_params(height, width, mines): - if mines > height * width: + if height <= 0 or width <= 0: + return (False, "地图太小!") + elif mines > height * width: return (False, "放不下这么多雷嘛!") elif mines == height * width: return (False, "一点就爆炸,有意思吗?") @@ -101,8 +103,6 @@ class Board(): if not automatic and self.map[row][col] == 9: self.map[row][col] = DEAD self.state = 3 - elif self.__do_i_win(): - self.state = 2 elif self.map[row][col] == 0: self.map[row][col] += 10 # open this block # open other blocks @@ -125,6 +125,8 @@ class Board(): self.__open(nbr[0], nbr[1], automatic=True) else: self.map[row][col] += 10 + if self.__do_i_win(): + self.state = 2 def move(self, row_col): if self.state == 0: diff --git a/tgmsbot.py b/tgmsbot.py index c288575..4d3d07b 100644 --- a/tgmsbot.py +++ b/tgmsbot.py @@ -104,7 +104,7 @@ def send_keyboard(bot, update, args): else: msg.reply_text(ck[1]) return - if len(args) == 0: + elif len(args) == 0: board = Board(HEIGHT, WIDTH, MINES) else: msg.reply_text('你输入的是什么鬼!') @@ -163,7 +163,7 @@ def handle_button_click(bot, update): else: mmap = deepcopy(board.map) board.move((row, col)) - if FIRST_MOVE or (not array_equal(board.map, mmap)): + if FIRST_MOVE or (not array_equal(board.map, mmap)) or board.state == 2: keyboard = list() for row in range(board.height): current_row = list()