several bug fix

This commit is contained in:
JerryXiao 2018-12-29 21:25:05 +08:00
parent b5c7a79ada
commit 986300d9fe
Signed by: Jerry
GPG key ID: 9D9CE43650FF2BAA
2 changed files with 7 additions and 5 deletions

View file

@ -18,7 +18,9 @@ IS_MINE = 9
DEAD = 20 DEAD = 20
def check_params(height, width, mines): def check_params(height, width, mines):
if mines > height * width: if height <= 0 or width <= 0:
return (False, "地图太小!")
elif mines > height * width:
return (False, "放不下这么多雷嘛!") return (False, "放不下这么多雷嘛!")
elif mines == height * width: elif mines == height * width:
return (False, "一点就爆炸,有意思吗?") return (False, "一点就爆炸,有意思吗?")
@ -101,8 +103,6 @@ class Board():
if not automatic and self.map[row][col] == 9: if not automatic and self.map[row][col] == 9:
self.map[row][col] = DEAD self.map[row][col] = DEAD
self.state = 3 self.state = 3
elif self.__do_i_win():
self.state = 2
elif self.map[row][col] == 0: elif self.map[row][col] == 0:
self.map[row][col] += 10 # open this block self.map[row][col] += 10 # open this block
# open other blocks # open other blocks
@ -125,6 +125,8 @@ class Board():
self.__open(nbr[0], nbr[1], automatic=True) self.__open(nbr[0], nbr[1], automatic=True)
else: else:
self.map[row][col] += 10 self.map[row][col] += 10
if self.__do_i_win():
self.state = 2
def move(self, row_col): def move(self, row_col):
if self.state == 0: if self.state == 0:

View file

@ -104,7 +104,7 @@ def send_keyboard(bot, update, args):
else: else:
msg.reply_text(ck[1]) msg.reply_text(ck[1])
return return
if len(args) == 0: elif len(args) == 0:
board = Board(HEIGHT, WIDTH, MINES) board = Board(HEIGHT, WIDTH, MINES)
else: else:
msg.reply_text('你输入的是什么鬼!') msg.reply_text('你输入的是什么鬼!')
@ -163,7 +163,7 @@ def handle_button_click(bot, update):
else: else:
mmap = deepcopy(board.map) mmap = deepcopy(board.map)
board.move((row, col)) 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() keyboard = list()
for row in range(board.height): for row in range(board.height):
current_row = list() current_row = list()