web123456

【Python Development Practice】AI Human-Computer Battle Gozi-Implementation of Button Function

  • class Button:
  • def __int__(self,screen,text,x,y,color,enable):
  • =screen
  • =button_w
  • =button_h
  • self.button_color=color
  • self.text_color=(255,255,255)
  • =enable
  • =(None,button_h*2//3)
  • =(0,0,,)
  • =(x,y)
  • =text
  • self.init_msg()
  • #Rewrite pygame function and initialize button
  • def init_msg(self):
  • if :
  • self.msg_iamge=(,True,self.text_color,self.button_color[0])
  • else:
  • self.msg_iamge=(,True,self.text_color,self.button_color[1])
  • self.msg_iamge_rect=self.msg_iamge.get_rect()
  • self.msg_iamge_rect.center=
  • #Fill in color according to the enable status of the button, the specific color is controlled in subsequent subclasses
  • def draw(self):
  • if :
  • (self.button_color[0],)
  • else:
  • (self.button_color[1],)
  • (self.msg_iamge,self.msg_iamge_rect)