1010import ms_toollib as ms
1111import configparser
1212# from pathlib import Path
13- # import time
13+ import time
1414import os
1515import hashlib , uuid
1616# from PyQt5.QtWidgets import QApplication
@@ -77,7 +77,7 @@ def __init__(self, MainWindow, args):
7777 self .frameShortcut9 .activated .connect (self .screenShot )
7878 self .shortcut_hidden_score_board .activated .connect (self .hidden_score_board )
7979
80- self .game_state = 'ready'
80+ self ._game_state = self . game_state = 'ready'
8181 # 用状态机控制局面状态。
8282 # 约定:'ready':预备状态。表示局面完全没有左键点过,可能被右键标雷;刚打开或点脸时进入这种状态。
8383 # 此时可以改雷数、改格子大小(ctrl+滚轮)、行数、列数(拖拉边框)。
@@ -111,6 +111,25 @@ def gameMode(self):
111111 def gameMode (self , game_mode ):
112112 self .label .ms_board .mode = game_mode
113113 self ._game_mode = game_mode
114+
115+ @property
116+ def game_state (self ):
117+ return self ._game_state
118+
119+ @game_state .setter
120+ def game_state (self , game_state : str ):
121+ # print(self._game_state, " -> " ,game_state)
122+ if self ._game_state in ("playing" , "show" , "joking" ) and \
123+ game_state not in ("playing" , "show" , "joking" ):
124+ self .timer_10ms .stop ()
125+ elif self ._game_state in ("display" , "showdisplay" ) and \
126+ game_state not in ("display" , "showdisplay" ):
127+ self .timer_video .stop ()
128+ self .ui_video_control .QWidget .close ()
129+ self .label .paint_cursor = False
130+ elif self ._game_state == 'study' :
131+ self .num_bar_ui .QWidget .close ()
132+ self ._game_state = game_state
114133
115134 def layMine (self , i , j ):
116135 xx = self .row
@@ -139,7 +158,7 @@ def timeCount(self):
139158 self .time_10ms = int (t * 100 )
140159 self .showTime (self .time_10ms // 100 )
141160 since_time_unix_2 = QtCore .QDateTime .currentDateTime ().\
142- ArithmeticErrortoMSecsSinceEpoch () - self .start_time_unix_2
161+ toMSecsSinceEpoch () - self .start_time_unix_2
143162 if abs (t * 1000 - since_time_unix_2 ) > 10 and \
144163 (self .game_state == "playing" or self .game_state == "joking" ):
145164 # 防CE作弊
@@ -302,8 +321,12 @@ def mineAreaLeftAndRightPressed(self, i, j):
302321
303322
304323 def mineMouseMove (self , i , j ):
324+ # 正常情况的鼠标移动事件,与高亮的显示有关
325+ if self .game_state == 'playing' or self .game_state == 'joking' or self .game_state == 'ready' :
326+ self .label .ms_board .step ('mv' , (i , j ))
327+ self .label .update ()
305328 # 按住空格后的鼠标移动事件,与概率的显示有关
306- if self .game_state == 'show' or self .game_state == 'study' :
329+ elif self .game_state == 'show' or self .game_state == 'study' :
307330 if not self .pos_is_in_board (i , j ):
308331 self .label_info .setText ('(是雷的概率)' )
309332 else :
@@ -316,10 +339,7 @@ def mineMouseMove(self, i, j):
316339 else :
317340 text4 = '{:.3f}' .format (max (0 , self .label .ms_board .game_board_poss [i // self .pixSize ][j // self .pixSize ]))
318341 self .label_info .setText (text4 )
319- # 正常情况的鼠标移动事件,与高亮的显示有关
320- elif self .game_state == 'playing' or self .game_state == 'joking' or self .game_state == 'ready' :
321- self .label .ms_board .step ('mv' , (i , j ))
322- self .label .update ()
342+
323343
324344 def resizeWheel (self , i , x , y ):
325345 # 按住ctrl滚轮,调整局面大小
@@ -421,14 +441,14 @@ def gameStart(self):
421441 self .operationStream = [] # 记录整局的鼠标操作流,格式例如[('l1',(x,y)),('r1',(x,y)),('c2',(x,y))]
422442
423443 self .label .paintPossibility = False
424- self .label .paint_cursor = False
444+ # self.label.paint_cursor = False
425445 # self.label.setMouseTracking(False) # 鼠标未按下时,组织移动事件回调
426446
427- if self .game_state == 'display' :
428- self .timer_video .stop ()
429- self .ui_video_control .QWidget .close ()
430- elif self .game_state == 'study' :
431- self .num_bar_ui .QWidget .close ()
447+ # if self.game_state == 'display':
448+ # self.timer_video.stop()
449+ # self.ui_video_control.QWidget.close()
450+ # elif self.game_state == 'study':
451+ # self.num_bar_ui.QWidget.close()
432452 self .label_info .setText (self .player_designator )
433453 # elif self.game_state == 'show':
434454 # self.label.setMouseTracking(False)
@@ -458,12 +478,12 @@ def gameRestart(self, e = None): # 画界面,但是不埋雷,改数据而
458478 return
459479 # 此时self.label.ms_board是mm.abstract_game_board的实例
460480 if self .game_state == 'display' or self .game_state == 'showdisplay' :
461- self .timer_video .stop ()
462- self .ui_video_control .QWidget .close ()
481+ # self.timer_video.stop()
482+ # self.ui_video_control.QWidget.close()
463483 self .label .ms_board = ms .BaseVideo ([[0 ] * self .column for _ in range (self .row )], self .pixSize )
464484 self .label .ms_board .mode = self .gameMode
465485 elif self .game_state == 'study' :
466- self .num_bar_ui .QWidget .close ()
486+ # self.num_bar_ui.QWidget.close()
467487 self .score_board_manager .visible ()
468488 self .label .ms_board = ms .BaseVideo ([[0 ] * self .column for _ in range (self .row )], self .pixSize )
469489 self .label .ms_board .mode = self .gameMode
@@ -483,7 +503,7 @@ def gameRestart(self, e = None): # 画界面,但是不埋雷,改数据而
483503 self .label .update ()
484504
485505 self .label .paintPossibility = False
486- self .label .paint_cursor = False
506+ # self.label.paint_cursor = False
487507 # self.label.setMouseTracking(False) # 鼠标未按下时,组织移动事件回调
488508
489509 self .score_board_manager .with_namespace ({
@@ -530,9 +550,9 @@ def gameWin(self): # 成功后改脸和状态变量,停时间
530550 def checksum_module_ok (self ):
531551 # 检查校验和模块的签名
532552 # 调试的时候不会自动存录像,除非将此处改为return True
533- # return True
534- return hashlib .sha256 (bytes (metaminesweeper_checksum .get_self_key ())).hexdigest () == \
535- '590028493bb58a25ffc76e2e2ad490df839a1f449435c35789d3119ca69e5d4f'
553+ return True
554+ # return hashlib.sha256(bytes(metaminesweeper_checksum.get_self_key())).hexdigest() ==\
555+ # '590028493bb58a25ffc76e2e2ad490df839a1f449435c35789d3119ca69e5d4f'
536556
537557 def save_evf_file (self ):
538558 # 搜集本局各种信息,存成evf文件
@@ -796,10 +816,10 @@ def setBoard(self, row, column, mineNum):
796816
797817 def setBoard_and_start (self , row , column , mineNum ):
798818 # 把局面设置成(row, column, mineNum),把3BV的限制设置成min3BV, max3BV
799- if self .game_state == 'display' : # 先把定时器停了再说
819+ if self .game_state == 'display' or self . game_state == 'showdisplay' :
800820 self .label .paintPossibility = False
801- self .label .paint_cursor = False
802- self .timer_video .stop ()
821+ # self.label.paint_cursor = False
822+ # self.timer_video.stop()
803823 if (self .row , self .column , self .mineNum ) != (row , column , mineNum ):
804824 self .setBoard (row , column , mineNum )
805825 self .gameStart ()
@@ -875,6 +895,11 @@ def screenShot(self):
875895
876896 if self .game_state == "playing" :
877897 self .game_state = "joking"
898+ if self .game_state == "display" or self .game_state == "showdisplay" :
899+ self .video_playing = False
900+ self .timer_video .stop ()
901+
902+
878903 self .enable_screenshot ()
879904
880905 ui = captureScreen .CaptureScreen ()
@@ -896,8 +921,8 @@ def screenShot(self):
896921
897922
898923 # 连续截屏时
899- if self .game_state == 'study' :
900- self .num_bar_ui .QWidget .close ()
924+ # if self.game_state == 'study':
925+ # self.num_bar_ui.QWidget.close()
901926 self .game_state = 'study' # 局面进入研究模式
902927
903928 # 主定时器停一下,不停的话需要的修补太多
0 commit comments