Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.67 KB | None | 0 0
  1. import pygame
  2. import pygame.freetype
  3. import random
  4.  
  5.  
  6. pygame.init()
  7. res = (1440, 740)
  8. screen = pygame.display.set_mode(res)
  9. image = pygame.image.load("shuffle.png")
  10. my_font = pygame.freetype.Font("NotoSans-Regular.ttf", 24)
  11. yellow = (255,255,0)
  12. white = (255,255,255)
  13. green = (0, 200, 0)
  14.  
  15.  
  16.  
  17.  
  18. def lvl1():
  19. x = 420
  20. y = 60
  21. baralhar = [0,0,1,1,2,2,3,3,4,4,5,5]
  22. cores = [(200,0,0), (200,200,200), (0,0,200), (200,200,0), (0,200,200), (150,50,200)]
  23. cardpos = []
  24. cardcolor = []
  25. cartasreveladas = []
  26. cartasreveladaspos = []
  27. numero_reveladas = 0
  28. win = 0
  29. score = 0
  30. s = 0
  31.  
  32.  
  33. screen.fill((0,0,20))
  34. random.shuffle(baralhar)
  35.  
  36. #desenha as cartas
  37.  
  38. cardpos.append(pygame.Rect(420, 60, 120, 180))
  39. for a in range(12):
  40. pygame.draw.rect(screen, green, (x, y, 120, 180), 0)
  41. x = x + 160
  42.  
  43. if (a == 3 or a == 7):
  44. y = y + 220
  45. x = 260
  46. x = x + 160
  47.  
  48. m_rect = pygame.Rect(x,y, 120, 180)
  49. cardpos.append(m_rect)
  50.  
  51.  
  52.  
  53. for j in range(len(baralhar)):
  54. cardcolor.append(cores[baralhar[j]])
  55.  
  56.  
  57.  
  58. while(True):
  59. for event in pygame.event.get():
  60. if(event.type == pygame.QUIT):
  61. exit()
  62. pos = pygame.mouse.get_pos()
  63. if(event.type == pygame.MOUSEBUTTONUP):
  64. for i in range(len(cardpos)):
  65. if (cardpos[i][0]<pos[0]<cardpos[i][0]+120 and cardpos[i][1]<pos[1]<cardpos[i][1]+180):
  66. cartasreveladas.append(cardcolor[i])
  67. cartasreveladaspos.append(cardpos[i])
  68. print(cartasreveladaspos)
  69. pygame.draw.rect(screen, cardcolor[i], cardpos[i], 0)
  70. numero_reveladas+=1
  71. pygame.display.flip()
  72. if(numero_reveladas == 2):
  73. pygame.time.wait(1000)
  74. if(cartasreveladas[0]==cartasreveladas[1] and cartasreveladaspos[0]!=cartasreveladaspos[1]):
  75. cardpos[i] = pygame.Rect(0,0,0,0)
  76. cardpos[i] = pygame.Rect(0,0,0,0)
  77. cartasreveladas.pop(1)
  78. cartasreveladas.pop(0)
  79. cartasreveladaspos.pop(1)
  80. cartasreveladaspos.pop(0)
  81. numero_reveladas = 0
  82. win+=1
  83. score+=100
  84. pygame.draw.rect(screen, (0,0,20), (50,50,200,200), 0)
  85. s = 0
  86.  
  87. else:
  88. pygame.draw.rect(screen, green, cartasreveladaspos[0], 0)
  89. pygame.draw.rect(screen, green, cartasreveladaspos[1], 0)
  90. cartasreveladas.pop(1)
  91. cartasreveladas.pop(0)
  92. cartasreveladaspos.pop(1)
  93. cartasreveladaspos.pop(0)
  94. numero_reveladas = 0
  95. if(score<0):
  96. score = 0
  97. if(score>0):
  98. score-=20*s
  99. s+=1
  100. pygame.draw.rect(screen, (0,0,20), (50,50,200,200), 0)
  101.  
  102. if(win==6):
  103. screen.fill((0,0,20))
  104. my_font.render_to(screen, (640,370), "Congratulations!!!", white)
  105.  
  106.  
  107.  
  108. #desenha botão exit
  109. pygame.draw.rect(screen, yellow, (50,650,140,30), 2)
  110. my_font.render_to(screen, (100,655), "Exit", yellow)
  111. #desenha o score
  112. my_font.render_to(screen, (50,50), "Score: " + str(score), yellow)
  113. pos = pygame.mouse.get_pos()
  114. #coisas brancaas?
  115.  
  116. #botão exit
  117. if(50<pos[0]<50+140 and 650<pos[1]<650+30):
  118. pygame.draw.rect(screen, white, (50,650,140,30), 2)
  119. my_font.render_to(screen, (100,655), "Exit", white)
  120.  
  121. pygame.display.flip()
  122.  
  123. #voltar ao menu
  124. if(50<pos[0]<50+140 and 650<pos[1]<650+30):
  125. if(event.type == pygame.MOUSEBUTTONUP):
  126. main()
  127.  
  128. def lvl2():
  129. x = 420
  130. y = 60
  131. baralhar = [0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
  132. cores = [(200,0,0), (200,200,200), (0,0,200), (200,200,0), (0,200,200), (150,50,200), (200,0,200), (92,51,23)]
  133. cardpos = []
  134. cardcolor = []
  135. cartasreveladas = []
  136. cartasreveladaspos = []
  137. numero_reveladas = 0
  138. win = 0
  139. score = 0
  140. s = 0
  141.  
  142.  
  143. screen.fill((0,0,20))
  144. random.shuffle(baralhar)
  145.  
  146.  
  147. #desenha as cartas
  148.  
  149. cardpos.append(pygame.Rect(420, 60, 120, 140))
  150. for a in range(16):
  151. pygame.draw.rect(screen, green, (x, y, 120, 140), 0)
  152. x = x + 160
  153.  
  154. if (a == 3 or a == 7 or a == 11):
  155. y = y + 160
  156. x = 260
  157. x = x + 160
  158.  
  159. m_rect = pygame.Rect(x,y, 120, 140)
  160. cardpos.append(m_rect)
  161.  
  162.  
  163.  
  164. for j in range(len(baralhar)):
  165. cardcolor.append(cores[baralhar[j]])
  166.  
  167.  
  168.  
  169. while(True):
  170. for event in pygame.event.get():
  171. if(event.type == pygame.QUIT):
  172. exit()
  173. pos = pygame.mouse.get_pos()
  174. if(event.type == pygame.MOUSEBUTTONUP):
  175. for i in range(len(cardpos)):
  176. if (cardpos[i][0]<pos[0]<cardpos[i][0]+120 and cardpos[i][1]<pos[1]<cardpos[i][1]+140):
  177. cartasreveladas.append(cardcolor[i])
  178. cartasreveladaspos.append(cardpos[i])
  179. print(cartasreveladaspos)
  180. pygame.draw.rect(screen, cardcolor[i], cardpos[i], 0)
  181. numero_reveladas+=1
  182. pygame.display.flip()
  183. if(numero_reveladas == 2):
  184. pygame.time.wait(1000)
  185. if(cartasreveladas[0]==cartasreveladas[1] and cartasreveladaspos[0]!=cartasreveladaspos[1]):
  186. cardpos[i] = pygame.Rect(0,0,0,0)
  187. cardpos[i] = pygame.Rect(0,0,0,0)
  188. cartasreveladas.pop(1)
  189. cartasreveladas.pop(0)
  190. cartasreveladaspos.pop(1)
  191. cartasreveladaspos.pop(0)
  192. numero_reveladas = 0
  193. win+=1
  194. score+=100
  195. pygame.draw.rect(screen, (0,0,20), (50,50,200,200), 0)
  196. s = 0
  197.  
  198. else:
  199. pygame.draw.rect(screen, green, cartasreveladaspos[0], 0)
  200. pygame.draw.rect(screen, green, cartasreveladaspos[1], 0)
  201. cartasreveladas.pop(1)
  202. cartasreveladas.pop(0)
  203. cartasreveladaspos.pop(1)
  204. cartasreveladaspos.pop(0)
  205. numero_reveladas = 0
  206. if(score<0):
  207. score = 0
  208. if(score>0):
  209. score-=20*s
  210. s+=1
  211. pygame.draw.rect(screen, (0,0,20), (50,50,200,200), 0)
  212.  
  213. if(win==8):
  214. screen.fill((0,0,20))
  215. my_font.render_to(screen, (640,370), "Congratulations!!!", white)
  216.  
  217. #desenha botão exit
  218. pygame.draw.rect(screen, yellow, (50,650,140,30), 2)
  219. my_font.render_to(screen, (100,655), "Exit", yellow)
  220. #desenha o score
  221. my_font.render_to(screen, (50,50), "Score: " + str(score), yellow)
  222. pos = pygame.mouse.get_pos()
  223.  
  224. if(50<pos[0]<50+140 and 650<pos[1]<650+30):
  225. pygame.draw.rect(screen, white, (50,650,140,30), 2)
  226. my_font.render_to(screen, (100,655), "Exit", white)
  227.  
  228. pygame.display.flip()
  229. #voltar ao menu
  230. if(50<pos[0]<50+140 and 650<pos[1]<650+30):
  231. if(event.type == pygame.MOUSEBUTTONUP):
  232. main()
  233.  
  234. def lvl3():
  235. x = 400
  236. y = 60
  237. baralhar = [0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9]
  238. cores = [(200,0,0), (200,200,200), (0,0,200), (200,200,0), (0,200,200), (150,50,200), (200,0,200), (92,51,23), (33,94,33), (0,20,0)]
  239. cardpos = []
  240. cardcolor = []
  241. cartasreveladas = []
  242. cartasreveladaspos = []
  243. numero_reveladas = 0
  244. win = 0
  245. score = 0
  246. s = 0
  247.  
  248.  
  249. screen.fill((0,0,20))
  250. random.shuffle(baralhar)
  251.  
  252.  
  253. #desenha as cartas
  254.  
  255. cardpos.append(pygame.Rect(400, 60, 120, 140))
  256. for a in range(20):
  257. pygame.draw.rect(screen, green, (x, y, 120, 140), 0)
  258. x = x + 160
  259.  
  260. if (a == 4 or a == 9 or a == 14):
  261. y = y + 160
  262. x = 400
  263.  
  264.  
  265. m_rect = pygame.Rect(x,y, 120, 140)
  266. cardpos.append(m_rect)
  267.  
  268.  
  269.  
  270. for j in range(len(baralhar)):
  271. cardcolor.append(cores[baralhar[j]])
  272.  
  273.  
  274.  
  275. while(True):
  276. for event in pygame.event.get():
  277. if(event.type == pygame.QUIT):
  278. exit()
  279. pos = pygame.mouse.get_pos()
  280. if(event.type == pygame.MOUSEBUTTONUP):
  281. for i in range(len(cardpos)):
  282. if (cardpos[i][0]<pos[0]<cardpos[i][0]+120 and cardpos[i][1]<pos[1]<cardpos[i][1]+140):
  283. cartasreveladas.append(cardcolor[i])
  284. cartasreveladaspos.append(cardpos[i])
  285. print(cartasreveladaspos)
  286. pygame.draw.rect(screen, cardcolor[i], cardpos[i], 0)
  287. numero_reveladas+=1
  288. pygame.display.flip()
  289. if(numero_reveladas == 2):
  290. pygame.time.wait(1000)
  291. if(cartasreveladas[0]==cartasreveladas[1] and cartasreveladaspos[0]!=cartasreveladaspos[1]):
  292. cardpos[i] = pygame.Rect(0,0,0,0)
  293. cardpos[i] = pygame.Rect(0,0,0,0)
  294. cartasreveladas.pop(1)
  295. cartasreveladas.pop(0)
  296. cartasreveladaspos.pop(1)
  297. cartasreveladaspos.pop(0)
  298. numero_reveladas = 0
  299. win+=1
  300. score+=100
  301. pygame.draw.rect(screen, (0,0,20), (50,50,200,200), 0)
  302. s = 0
  303.  
  304. else:
  305. pygame.draw.rect(screen, green, cartasreveladaspos[0], 0)
  306. pygame.draw.rect(screen, green, cartasreveladaspos[1], 0)
  307. cartasreveladas.pop(1)
  308. cartasreveladas.pop(0)
  309. cartasreveladaspos.pop(1)
  310. cartasreveladaspos.pop(0)
  311. numero_reveladas = 0
  312. if(score<0):
  313. score = 0
  314. if(score>0):
  315. score-=20*s
  316. s+=1
  317. pygame.draw.rect(screen, (0,0,20), (50,50,200,200), 0)
  318.  
  319. if(win==10):
  320. screen.fill((0,0,20))
  321. my_font.render_to(screen, (640,370), "Congratulations!!!", white)
  322.  
  323. #desenha botão exit
  324. pygame.draw.rect(screen, yellow, (50,650,140,30), 2)
  325. my_font.render_to(screen, (100,655), "Exit", yellow)
  326. #desenha o score
  327. my_font.render_to(screen, (50,50), "Score: " + str(score), yellow)
  328. pos = pygame.mouse.get_pos()
  329.  
  330. if(50<pos[0]<50+140 and 650<pos[1]<650+30):
  331. pygame.draw.rect(screen, white, (50,650,140,30), 2)
  332. my_font.render_to(screen, (100,655), "Exit", white)
  333.  
  334. pygame.display.flip()
  335. #voltar ao menu
  336. if(50<pos[0]<50+140 and 650<pos[1]<650+30):
  337. if(event.type == pygame.MOUSEBUTTONUP):
  338. main()
  339.  
  340. def lvl4():
  341. x = 380
  342. y = 60
  343. baralhar = [0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14]
  344. cores = [(200,0,0), (200,200,200), (0,0,200), (200,200,0), (0,200,200), (150,50,200), (200,0,200), (92,51,23), (33,94,33), (0,20,0), (255,165,0), (0,0,0), (89,89,171), (140,120,83), (143,143,189)]
  345. cardpos = []
  346. cardcolor = []
  347. cartasreveladas = []
  348. cartasreveladaspos = []
  349. numero_reveladas = 0
  350. win = 0
  351. score = 0
  352. s = 0
  353.  
  354.  
  355. screen.fill((0,0,20))
  356. random.shuffle(baralhar)
  357.  
  358.  
  359. #desenha as cartas
  360.  
  361. cardpos.append(pygame.Rect(380, 60, 80, 100))
  362. for a in range(30):
  363. pygame.draw.rect(screen, green, (x, y, 80, 100), 0)
  364. x = x + 120
  365.  
  366. if (a == 5 or a == 11 or a == 17 or a == 23):
  367. y = y + 120
  368. x = 380
  369.  
  370.  
  371. m_rect = pygame.Rect(x,y, 80, 100)
  372. cardpos.append(m_rect)
  373.  
  374.  
  375.  
  376. for j in range(len(baralhar)):
  377. cardcolor.append(cores[baralhar[j]])
  378.  
  379.  
  380.  
  381. while(True):
  382. for event in pygame.event.get():
  383. if(event.type == pygame.QUIT):
  384. exit()
  385. pos = pygame.mouse.get_pos()
  386. if(event.type == pygame.MOUSEBUTTONUP):
  387. for i in range(len(cardpos)):
  388. if (cardpos[i][0]<pos[0]<cardpos[i][0]+80 and cardpos[i][1]<pos[1]<cardpos[i][1]+100):
  389. cartasreveladas.append(cardcolor[i])
  390. cartasreveladaspos.append(cardpos[i])
  391. print(cartasreveladaspos)
  392. pygame.draw.rect(screen, cardcolor[i], cardpos[i], 0)
  393. numero_reveladas+=1
  394. pygame.display.flip()
  395. if(numero_reveladas == 2):
  396. pygame.time.wait(1000)
  397. if(cartasreveladas[0]==cartasreveladas[1] and cartasreveladaspos[0]!=cartasreveladaspos[1]):
  398. cardpos[i] = pygame.Rect(0,0,0,0)
  399. cardpos[i] = pygame.Rect(0,0,0,0)
  400. cartasreveladas.pop(1)
  401. cartasreveladas.pop(0)
  402. cartasreveladaspos.pop(1)
  403. cartasreveladaspos.pop(0)
  404. numero_reveladas = 0
  405. win+=1
  406. score+=100
  407. pygame.draw.rect(screen, (0,0,20), (50,50,200,200), 0)
  408. s = 0
  409.  
  410. else:
  411. pygame.draw.rect(screen, green, cartasreveladaspos[0], 0)
  412. pygame.draw.rect(screen, green, cartasreveladaspos[1], 0)
  413. cartasreveladas.pop(1)
  414. cartasreveladas.pop(0)
  415. cartasreveladaspos.pop(1)
  416. cartasreveladaspos.pop(0)
  417. numero_reveladas = 0
  418. if(score<0):
  419. score = 0
  420. if(score>0):
  421. score-=20*s
  422. s+=1
  423. pygame.draw.rect(screen, (0,0,20), (50,50,200,200), 0)
  424.  
  425. if(win==15):
  426. screen.fill((0,0,20))
  427. my_font.render_to(screen, (640,370), "Congratulations!!!", white)
  428.  
  429. #desenha botão exit
  430. pygame.draw.rect(screen, yellow, (50,650,140,30), 2)
  431. my_font.render_to(screen, (100,655), "Exit", yellow)
  432. #desenha o score
  433. my_font.render_to(screen, (50,50), "Score: " + str(score), yellow)
  434. pos = pygame.mouse.get_pos()
  435.  
  436. if(50<pos[0]<50+140 and 650<pos[1]<650+30):
  437. pygame.draw.rect(screen, white, (50,650,140,30), 2)
  438. my_font.render_to(screen, (100,655), "Exit", white)
  439.  
  440. pygame.display.flip()
  441. #voltar ao menu
  442. if(50<pos[0]<50+140 and 650<pos[1]<650+30):
  443. if(event.type == pygame.MOUSEBUTTONUP):
  444. main()
  445.  
  446.  
  447. def lvl5():
  448. screen.fill((0,0,20))
  449. while(True):
  450. for event in pygame.event.get():
  451. if(event.type == pygame.QUIT):
  452. exit()
  453. my_font.render_to(screen, (640,370), "Coming soon...", white)
  454. #desenha botão exit
  455. pygame.draw.rect(screen, yellow, (50,650,140,30), 2)
  456. my_font.render_to(screen, (100,655), "Exit", yellow)
  457. pos = pygame.mouse.get_pos()
  458. if(50<pos[0]<50+140 and 650<pos[1]<650+30):
  459. pygame.draw.rect(screen, white, (50,650,140,30), 2)
  460. my_font.render_to(screen, (100,655), "Exit", white)
  461.  
  462. pygame.display.flip()
  463. #voltar ao menu
  464. if(50<pos[0]<50+140 and 650<pos[1]<650+30):
  465. if(event.type == pygame.MOUSEBUTTONUP):
  466. main()
  467.  
  468. def main():
  469. while(True):
  470. for event in pygame.event.get():
  471. if(event.type == pygame.QUIT):
  472. exit()
  473. screen.fill((0,0,20))
  474. #desenha o menu
  475. y = 330
  476. for i in range(5):
  477. pygame.draw.rect(screen, yellow, (650,y,140,30), 2)
  478. y = y + 40
  479.  
  480. pygame.draw.rect(screen, yellow, (650,370+180,140,30), 2)
  481.  
  482. screen.blit(image, ((740/2)-35,0))
  483.  
  484. my_font.render_to(screen, (700,370-35), "4x3", yellow)
  485. my_font.render_to(screen, (700,370+5), "4x4", yellow)
  486. my_font.render_to(screen, (700,370+45), "5x4", yellow)
  487. my_font.render_to(screen, (700,370+85), "6x5", yellow)
  488. my_font.render_to(screen, (700,370+125), "6x6", yellow)
  489. my_font.render_to(screen, (700,370+185), "Exit", yellow)
  490. #muda as cores do menu de amarelo para branco
  491. pos = pygame.mouse.get_pos()
  492. if(650<pos[0]<650+140 and 370-40<pos[1]<370-40+30):
  493. pygame.draw.rect(screen, white, (650,370-40,140,30), 2)
  494. my_font.render_to(screen, (700,370-35), "4x3", white)
  495. elif(650<pos[0]<650+140 and 370<pos[1]<370+30):
  496. pygame.draw.rect(screen, white, (650,370,140,30), 2)
  497. my_font.render_to(screen, (700,370+5), "4x4", white)
  498. elif(650<pos[0]<650+140 and 370+40<pos[1]<370+40+30):
  499. pygame.draw.rect(screen, white, (650,370+40,140,30), 2)
  500. my_font.render_to(screen, (700,370+45), "5x4", white)
  501. elif(650<pos[0]<650+140 and 370+80<pos[1]<370+80+30):
  502. pygame.draw.rect(screen, white, (650,370+80,140,30), 2)
  503. my_font.render_to(screen, (700,370+85), "6x5", white)
  504. elif(650<pos[0]<650+140 and 370+120<pos[1]<370+120+30):
  505. pygame.draw.rect(screen, white, (650,370+120,140,30), 2)
  506. my_font.render_to(screen, (700,370+125), "6x6", white)
  507. elif(650<pos[0]<650+140 and 370+180<pos[1]<370+180+30):
  508. pygame.draw.rect(screen, white, (650,370+180,140,30), 2)
  509. my_font.render_to(screen, (700,370+185), "Exit", white)
  510. pygame.display.flip()
  511. #sair do jogo
  512. if(650<pos[0]<650+140 and 370+180<pos[1]<370+180+30):
  513. if(event.type == pygame.MOUSEBUTTONUP):
  514. exit()
  515. #Nivel 1
  516. if(650<pos[0]<650+140 and 370-40<pos[1]<370-40+30):
  517. if(event.type == pygame.MOUSEBUTTONUP):
  518. lvl1()
  519. #Nivel 2
  520. if(650<pos[0]<650+140 and 370<pos[1]<370+30):
  521. if(event.type == pygame.MOUSEBUTTONUP):
  522. lvl2()
  523.  
  524. if(650<pos[0]<650+140 and 370<pos[1]<370+40+30):
  525. if(event.type == pygame.MOUSEBUTTONUP):
  526. lvl3()
  527.  
  528. if(650<pos[0]<650+140 and 370<pos[1]<370+80+30):
  529. if(event.type == pygame.MOUSEBUTTONUP):
  530. lvl4()
  531.  
  532. if(650<pos[0]<650+140 and 370<pos[1]<370+120+30):
  533. if(event.type == pygame.MOUSEBUTTONUP):
  534. lvl5()
  535.  
  536. pygame.time.wait(5)
  537. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement