棋型变量设置
之前的内容里,有写到棋型的设置,但在整个程序中,为了让计算机对棋型的数量、类型进行识别,需要设置一些棋型变量:
python
class SITUATION(IntEnum): # 棋型
NONE = 0, # 无
SLEEP_TWO = 1, # 眠二
LIVE_TWO = 2, # 活二
SLEEP_THREE = 3, # 眠三
LIVE_THREE = 4, # 活三
CHONG_FOUR = 5, # 冲四
LIVE_FOUR = 6, # 活四
LIVE_FIVE = 7, # 活五
SITUATION_NUM = 8 # 长度
# 方便后续调用枚举内容
FIVE = SITUATION.LIVE_FIVE.value
L4, L3, L2 = SITUATION.LIVE_FOUR.value, SITUATION.LIVE_THREE.value, SITUATION.LIVE_TWO.value
S4, S3, S2 = SITUATION.CHONG_FOUR.value, SITUATION.SLEEP_THREE.value, SITUATION.SLEEP_TWO.value
多人游戏类设置
python
class MultiStartButton(Button): # 开始按钮(多人游戏)
def __init__(self, screen, text, x, y): # 构造函数
super().__init__(screen, text, x, y, [(153, 51, 250), (221, 160, 221)], True) # 紫色
def click(self, game): # 点击,pygame内置方法
if self.enable: # 启动游戏并初始化,变换按钮颜色
game.start()
game.winner = None
game.multiple=True
self.msg_image = self.font.render(self.text, True, self.text_color, self.button_color[1])
self.enable = False
return True
return False
def unclick(self): # 取消点击
if not self.enable:
self.msg_image = self.font.render(self.text, True, self.text_color, self.button_color[0])
self.enable = True