Advertisement
Melanie1204

Untitled

May 24th, 2024 (edited)
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.31 KB | Source Code | 0 0
  1. import pygame
  2. from pygame.locals import *
  3. pygame.init()
  4. window=pygame.display.set_mode((300,300))
  5. window_color=(255,255,255)
  6. line_color=(0,0,0)
  7. BUTTON_LENGTH=30
  8. BUTTON_HIGHT=34
  9.  
  10. state=0
  11. running=True
  12. clicked=False
  13. clicked_circles=[]
  14. clicked_cross=[]
  15. button_states=[]
  16.  
  17. cross=pygame.image.load('cross.png').convert_alpha()
  18. cross=pygame.transform.scale(cross,(BUTTON_LENGTH,BUTTON_HIGHT))
  19.  
  20. circle=pygame.image.load('circle.png').convert_alpha()
  21. circle=pygame.transform.scale(circle,(BUTTON_LENGTH,BUTTON_HIGHT))
  22.  
  23. while running:
  24.  
  25.     pos=pygame.mouse.get_pos()
  26.  
  27.     window.fill(window_color)
  28.  
  29.  
  30.  
  31.  
  32.     for event in pygame.event.get():
  33.         if event.type==pygame.QUIT:
  34.             running=False
  35.             pygame.quit()
  36.  
  37.     #creating Grid
  38.     pygame.draw.line(window,line_color,[100,100],[100,246],3)
  39.     pygame.draw.line(window,line_color,[135,100],[135,246],3)
  40.     pygame.draw.line(window,line_color,[170,100],[170,246],3)
  41.  
  42.     pygame.draw.line(window,line_color,[69,135],[201,135],3)
  43.     pygame.draw.line(window,line_color,[69,173],[201,173],3)
  44.     pygame.draw.line(window,line_color,[69,211],[201,211],3)
  45.  
  46. #creating buttons
  47.    
  48.  
  49.    
  50.            
  51.    
  52.     button1_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  53.     button1_surface.fill((255,0,0))
  54.     button1=pygame.Rect(69,100,BUTTON_LENGTH,BUTTON_HIGHT)
  55.     button1=window.blit(button1_surface,(button1.x,button1.y))
  56.    
  57.  
  58.     button2_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  59.     button2_surface.fill((255,0,0))
  60.     button2=pygame.Rect(103,100,BUTTON_LENGTH,BUTTON_HIGHT)
  61.     button2=window.blit(button2_surface,(button2.x,button2.y))
  62.  
  63.    
  64.     button3_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  65.     button3_surface.fill((255,0,0))
  66.     button3=pygame.Rect(138,100,BUTTON_LENGTH,BUTTON_HIGHT)
  67.     button3=window.blit(button3_surface,(button3.x,button3.y))
  68.  
  69.    
  70.     button4_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  71.     button4_surface.fill((255,0,0))
  72.     button4=pygame.Rect(173,100,BUTTON_LENGTH,BUTTON_HIGHT)
  73.     button4=window.blit(button4_surface,(button4.x,button4.y))
  74.    
  75.     button5_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  76.     button5_surface.fill((255,0,0))
  77.     button5=pygame.Rect(69,138,BUTTON_LENGTH,BUTTON_HIGHT)
  78.     button5=window.blit(button5_surface,(button5.x,button5.y))
  79.    
  80.  
  81.     button6_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  82.     button6_surface.fill((255,0,0))
  83.     button6=pygame.Rect(103,138,BUTTON_LENGTH,BUTTON_HIGHT)
  84.     button6=window.blit(button6_surface,(button6.x,button6.y))
  85.  
  86.    
  87.     button7_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  88.     button7_surface.fill((255,0,0))
  89.     button7=pygame.Rect(138,138,BUTTON_LENGTH,BUTTON_HIGHT)
  90.     button7=window.blit(button7_surface,(button7.x,button7.y))
  91.  
  92.    
  93.     button8_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  94.     button8_surface.fill((255,0,0))
  95.     button8=pygame.Rect(173,138,BUTTON_LENGTH,BUTTON_HIGHT)
  96.     button8=window.blit(button8_surface,(button8.x,button8.y))
  97.  
  98.     button9_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  99.     button9_surface.fill((255,0,0))
  100.     button9=pygame.Rect(69,176,BUTTON_LENGTH,BUTTON_HIGHT)
  101.     button9=window.blit(button9_surface,(button9.x,button9.y))
  102.    
  103.  
  104.     button10_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  105.     button10_surface.fill((255,0,0))
  106.     button10=pygame.Rect(103,176,BUTTON_LENGTH,BUTTON_HIGHT)
  107.     button10=window.blit(button10_surface,(button10.x,button10.y))
  108.  
  109.    
  110.     button11_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  111.     button11_surface.fill((255,0,0))
  112.     button11=pygame.Rect(138,176,BUTTON_LENGTH,BUTTON_HIGHT)
  113.     button11=window.blit(button11_surface,(button11.x,button11.y))
  114.  
  115.    
  116.     button12_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  117.     button12_surface.fill((255,0,0))
  118.     button12=pygame.Rect(173,176,BUTTON_LENGTH,BUTTON_HIGHT)
  119.     button12=window.blit(button12_surface,(button12.x,button12.y))
  120.  
  121.     button13_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  122.     button13_surface.fill((255,0,0))
  123.     button13=pygame.Rect(69,214,BUTTON_LENGTH,BUTTON_HIGHT)
  124.     button13=window.blit(button13_surface,(button13.x,button13.y))
  125.    
  126.  
  127.     button14_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  128.     button14_surface.fill((255,0,0))
  129.     button14=pygame.Rect(103,214,BUTTON_LENGTH,BUTTON_HIGHT)
  130.     button14=window.blit(button14_surface,(button14.x,button14.y))
  131.  
  132.    
  133.     button15_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  134.     button15_surface.fill((255,0,0))
  135.     button15=pygame.Rect(138,214,BUTTON_LENGTH,BUTTON_HIGHT)
  136.     button15=window.blit(button15_surface,(button15.x,button15.y))
  137.  
  138.    
  139.     button16_surface=pygame.Surface((BUTTON_LENGTH,BUTTON_HIGHT))
  140.     button16_surface.fill((255,0,0))
  141.     button16=pygame.Rect(173,214,BUTTON_LENGTH,BUTTON_HIGHT)
  142.     button16=window.blit(button16_surface,(button16.x,button16.y))
  143.  
  144.  
  145.     #creating lists with the buttons
  146.  
  147.     buttons=[button1,button2,button3,button4,button5,button6,button7,button8,button9,button10,button11,button12,button13,button14,button15,button16]
  148.    
  149.     #print(circles[0])
  150.    # running=False
  151.  
  152.     #clicked condition
  153.    
  154.    
  155.     for i in range(16):
  156.              if buttons[i].collidepoint(pos):
  157.                 if pygame.mouse.get_pressed()[0]==1 and clicked==False:
  158.                     clicked=True
  159.                     if state%2==0:
  160.                      clicked_circles.append(buttons[i])
  161.                     elif state%2==1:
  162.                      clicked_cross.append(buttons[i])
  163.  
  164.                    # button_states.append(str(buttons[i].x) + "," + str(buttons[i].y) + " state: ")
  165.                    # x=buttons[i].x
  166.                   #  y=buttons[i].y
  167.                     print(clicked_circles)
  168.                     print(clicked_cross)
  169.                    # print(button_states)
  170.                
  171.  
  172.              if clicked and state%2==0:
  173.                  for circles in clicked_circles:
  174.                     window.blit(circle,(circles))
  175.                     state=state+1
  176.              if clicked and state%2==1:
  177.                  for crosses in clicked_cross:
  178.                     window.blit(cross,(crosses))
  179.                     state=state+1
  180.                  
  181.     if pygame.mouse.get_pressed()[0]==0:
  182.         clicked=False
  183.              
  184.     pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement