Advertisement
KreeZe

jeu 1.0 fini

Nov 16th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.25 KB | None | 0 0
  1. """
  2. Jeu Réalisé Par KreeZe
  3.  
  4. """
  5.  
  6. #bibliothèque
  7. import pygame
  8. from random import*
  9.  
  10. #initialisation pygame+fenetre+utilitaire
  11. pygame.display.set_caption("Cluedo par Yamis")
  12. pygame.init()
  13. rouge_blanc_color = (255, 245 ,243)
  14. blank_color = (255, 255 ,255)
  15. black_color = (0, 0, 0)
  16. resolution = (1368, 768)
  17. fenetre = pygame.display.set_mode(resolution)
  18. font = pygame.font.SysFont(None, 24)
  19. fenetre.fill(blank_color)
  20.  
  21. #liste
  22. main_indice=["Couteau","Chandelier","Clé anglaise","Matraque"]
  23. sec_indice=["Revolver","Corde","Montre", "Appareil Photo","Ecouteur","Pendentifs"]
  24. action=["vous avez avancé","vous avez été à gauche","vous avez reculé","vous avez été a droite","erreur","Au revoir"]
  25. piece=["l'Entrée","le Salon","la Salle a manger","la Salle de jeu","la Salle de reception","la Cuisine","la Chambre"]
  26. piece_2=["l'Entrée","le Salon","la Salle a manger","la Salle de jeu","la Salle de reception","la Cuisine","la Chambre"]
  27.  
  28. #fermer la fenetre
  29. def fin():
  30. launched = True
  31. while launched:
  32. for event in pygame.event.get():
  33. if event.type == pygame.QUIT:
  34. launched = False
  35.  
  36. if event.type == pygame.QUIT :
  37. pygame.quit()
  38.  
  39.  
  40. #afficher un text
  41. def text1(word,x,y):
  42. text = font.render(word,1,black_color)
  43. fenetre.blit(text, (x, y))
  44.  
  45. #2e fonction text car pas envie de modifier tous
  46. def text2(word,x,y,size):
  47. font = pygame.font.SysFont(None, size)
  48. text = font.render(word,1,black_color)
  49. fenetre.blit(text, (x, y))
  50.  
  51. #afficher image
  52. def image(p,x,y,fill):
  53.  
  54. p = pygame.image.load(p)
  55. p.convert()
  56. if fill == True and p!= "GG.png":
  57. fenetre.fill(blank_color)
  58. fenetre.blit(p, [x, y])
  59. else:
  60. fenetre.blit(p, [x, y])
  61.  
  62. #fonction image avec width en + car flemem de tous changer
  63. def image2(p,x,y,fill):
  64.  
  65. p = pygame.image.load(p)
  66. p = pygame.transform.scale(p, (300, 300))
  67. p.convert()
  68. if fill == True:
  69. fenetre.fill(blank_color)
  70. fenetre.blit(p, [x, y])
  71. else:
  72. fenetre.blit(p, [x, y])
  73.  
  74. #fonction inutile mais flemme je reorganiserai a la fin
  75. def touche_entree():
  76. for event in pygame.event.get():
  77. if event.type == pygame.KEYDOWN:
  78. if event.key == pygame.K_ENTER:
  79. return 1
  80.  
  81.  
  82.  
  83.  
  84.  
  85. #fonction choix random (sortie indice_I/II/III et presence_I/II/III)
  86. indice_1=randint(0,2)
  87. indice_I=main_indice[indice_1]
  88.  
  89. indice_2=randint(0,5)
  90. indice_II=sec_indice[indice_2]
  91. del sec_indice[indice_2]
  92. indice_3=randint(0,5-1)
  93. indice_III=sec_indice[indice_3]
  94. del sec_indice[indice_3]
  95.  
  96. presence_1=randint(1,5)
  97. presence_I=piece_2[presence_1]
  98. del piece_2[presence_1]
  99. presence_2=randint(1,5-1)
  100. presence_II=piece_2[presence_2]
  101. del piece_2[presence_2]
  102. presence_3=randint(1,5-2)
  103. presence_III=piece_2[presence_3]
  104. del piece_2[presence_3]
  105.  
  106. #fonction entrée salle
  107. def entree_salle(liste_salle):
  108. temp="vous êtes entrée dans "
  109. temp_2=piece[liste_salle]
  110. temp_3=temp+temp_2
  111. return temp_3
  112.  
  113. def tueur():
  114. text1("Vous avez trouvez tous les indice : "+indice_I+", "+indice_II+", "+indice_III,400,0)
  115. text1("Trouver le meurtier !",550,20)
  116.  
  117. text1("le major-d'home",150,450)
  118. image("Chandelier.png",100,100,False)
  119.  
  120.  
  121. text1("le policier",450,450)
  122. image("Matraque.png",400,100,False)
  123.  
  124. text1("le cuisinier",750,450)
  125. image("Couteau.png",700,100,False)
  126.  
  127. text1("le mécano",1050,450)
  128. image("clef.png",1000,100,False)
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. #fonction principale(jeu)
  136. def main():
  137. ecran_fin = 0
  138. clic = 0
  139. points_1=0
  140. points_2=0
  141. points_3=0
  142. quiter=0
  143. suite=0
  144. position=piece[0]
  145. continuer = 0
  146. touche = 0
  147.  
  148. while continuer == 0:
  149.  
  150. #detection touche
  151. for event in pygame.event.get():
  152. if event.type == pygame.KEYDOWN:
  153. if event.key == pygame.K_ESCAPE:
  154. continuer = 1
  155. quiter=1
  156. suite=1
  157. ecran_fin = 1
  158. if event.key == pygame.K_w:
  159. touche="z"
  160. if event.key == pygame.K_a:
  161. touche="q"
  162. if event.key == pygame.K_s:
  163. touche="s"
  164. if event.key == pygame.K_d:
  165. touche="d"
  166. if event.key == pygame.K_RETURN:
  167. touche = "entrer"
  168. #mecanisme du jeu
  169.  
  170. if touche == 0:
  171. image("cluedo.png",150,100,True)
  172. text2("bienvenu dans cluedo",370,30,70)
  173. text1("apuyer sur entrer pour commencer",500 , 0)
  174. text1("Déplacement :",300,620)
  175. text1("z pour allez ver l'avant",300,660)
  176. text1("q pour allez à gauche",600,660)
  177. text1("s pour allez ver l'arrière",300,680)
  178. text1("d pour allez à droite",600,680)
  179. image("echap.png",1100,0,False)
  180. position = -1
  181. elif touche == "entrer" and position== -1:
  182. fenetre.fill(blank_color)
  183. image("l'Entree.png",150,100,True)
  184. text1("vous êtes dans l'entrée",900,400)
  185. position=piece[0]
  186. touche=""
  187. image2("carte 0.png",950,80,False)
  188. elif touche=="z" and position==piece[0]:
  189. fenetre.fill(blank_color)
  190. image("le Salon.png",150,100,True)
  191. text1(entree_salle(1),900,400)
  192. position=piece[1]
  193. touche=""
  194. image2("carte 1.png",950,80,False)
  195. elif (touche=="q" or touche=="s" or touche=="d") and position==piece[0]:
  196. fenetre.fill(blank_color)
  197. image("l'Entree.png",150,100,True)
  198. text1("vous ne pouver aller par là",900,400)
  199. position=piece[0]
  200. touche=""
  201. image2("carte 0.png",950,80,False)
  202. elif touche=="q" and position==piece[1]:
  203. fenetre.fill(blank_color)
  204. image("la Salle a manger.png",150,100,True)
  205. text1(entree_salle(2),900,400)
  206. position=piece[2]
  207. touche=""
  208. image2("carte 2.png",950,80,False)
  209. elif touche=="z" and position==piece[1]:
  210. fenetre.fill(blank_color)
  211. image("la Salle de reception.png",150,100,True)
  212. text1(entree_salle(4),900,400)
  213. position=piece[4]
  214. touche=""
  215. image2("carte 4.png",950,80,False)
  216. elif touche=="d" and position==piece[1]:
  217. fenetre.fill(blank_color)
  218. image("la Salle de jeu.png",150,100,True)
  219. text1(entree_salle(3),900,400)
  220. position=piece[3]
  221. touche=""
  222. image2("carte 3.png",950,80,False)
  223. elif touche=="s" and position==piece[1]:
  224. fenetre.fill(blank_color)
  225. image("l'Entree.png",150,100,True)
  226. text1(entree_salle(0),900,400)
  227. position=piece[0]
  228. touche=""
  229. image2("carte 0.png",950,80,False)
  230. elif touche=="z" and position==piece[2]:
  231. fenetre.fill(blank_color)
  232. image("la Cuisine.png",150,100,True)
  233. text1(entree_salle(5),900,400)
  234. position=piece[5]
  235. touche=""
  236. image2("carte 5.png",950,80,False)
  237. elif (touche=="q" or touche=="s" )and position==piece[2]:
  238. fenetre.fill(blank_color)
  239. image("la Salle a manger.png",150,100,True)
  240. text1("vous ne pouver aller par là",900,400)
  241. position=piece[2]
  242. touche=""
  243. image2("carte 2.png",950,80,False)
  244. elif touche=="d" and position==piece[2]:
  245. fenetre.fill(blank_color)
  246. image("le Salon.png",150,100,True)
  247. text1(entree_salle(1),900,400)
  248. position=piece[1]
  249. touche=""
  250. image2("carte 1.png",950,80,False)
  251. elif touche=="q" and position==piece[3]:
  252. fenetre.fill(blank_color)
  253. image("le Salon.png",150,100,True)
  254. text1(entree_salle(1),900,400)
  255. position=piece[1]
  256. touche=""
  257. image2("carte 1.png",950,80,False)
  258. elif touche=="z" and position==piece[3]:
  259. fenetre.fill(blank_color)
  260. image("la Chambre.png",150 ,100,True)
  261. text1(entree_salle(6),900,400)
  262. position=piece[6]
  263. touche=""
  264. image2("carte 6.png",950,80,False)
  265. elif (touche=="s" or touche=="d") and position==piece[3]:
  266. fenetre.fill(blank_color)
  267. image("la Salle de jeu.png",150,100,True)
  268. text1("vous ne pouver aller par là",900,400)
  269. position=piece[3]
  270. touche=""
  271. image2("carte 3.png",950,80,False)
  272. elif touche=="z" and position==piece[4]:
  273. fenetre.fill(blank_color)
  274. image("la Salle de reception.png",150,100,True)
  275. text1("vous ne pouver aller par là",900,400)
  276. position=piece[4]
  277. touche=""
  278. image2("carte 4.png",950,80,False)
  279. elif touche=="q" and position==piece[4]:
  280. fenetre.fill(blank_color)
  281. image("la Cuisine.png",150,100,True)
  282. text1(entree_salle(5),900,400)
  283. position=piece[5]
  284. touche=""
  285. image2("carte 5.png",950,80,False)
  286. elif touche=="s" and position==piece[4]:
  287. fenetre.fill(blank_color)
  288. image("le Salon.png",150,100,True)
  289. text1(entree_salle(1),950,400)
  290. position=piece[1]
  291. touche=""
  292. image2("carte 1.png",950,80,False)
  293. elif touche=="d" and position==piece[4]:
  294. fenetre.fill(blank_color)
  295. image("la Chambre.png",150 ,100,True)
  296. text1(entree_salle(6),900,400)
  297. position=piece[6]
  298. touche=""
  299. image2("carte 6.png",950,80,False)
  300. elif (touche=="z" or touche=="q") and position==piece[5]:
  301. fenetre.fill(blank_color)
  302. image("la Cuisine.png",150,100,True)
  303. text1("vous ne pouver aller par là",900,400)
  304. position=piece[5]
  305. touche=""
  306. image2("carte 5.png",950,80,False)
  307. elif touche=="s" and position==piece[5]:
  308. fenetre.fill(blank_color)
  309. image("la Salle a manger.png",150,100,True)
  310. text1(entree_salle(2),900,400)
  311. position=piece[2]
  312. touche=""
  313. image2("carte 2.png",950,80,False)
  314. elif touche=="d" and position==piece[5]:
  315. fenetre.fill(blank_color)
  316. image("la Salle de reception.png",150,100,True)
  317. text1(entree_salle(4),900,400)
  318. position=piece[4]
  319. touche=""
  320. image2("carte 4.png",950,80,False)
  321. elif (touche=="z" or touche=="d") and position==piece[6]:
  322. fenetre.fill(blank_color)
  323. image("la Chambre.png",150 ,100,True)
  324. text1("vous ne pouver aller par là",900,400)
  325. position=piece[6]
  326. touche=""
  327. image2("carte 6.png",950,80,False)
  328. elif touche=="s" and position==piece[6]:
  329. fenetre.fill(blank_color)
  330. image("la Salle de jeu.png",150,100,True)
  331. text1(entree_salle(3),900,400)
  332. position=piece[3]
  333. touche=""
  334. image2("carte 3.png",950,80,False)
  335. elif touche=="q" and position==piece[6]:
  336. fenetre.fill(blank_color)
  337. image("la Salle de reception.png",150,100,True)
  338. text1(entree_salle(4),900,400)
  339. position=piece[4]
  340. touche=""
  341. image2("carte 4.png",950,80,False)
  342.  
  343.  
  344. #detection decouverte indice
  345. if position==presence_I:
  346. image(position+".png",150 ,100,True)
  347. text1("vous êtes entrée dans "+position,900,400)
  348. text1("vous avez trouvé un indice : "+indice_I,900,450)
  349. numero = int(piece.index(position))
  350. image2("carte "+str(numero)+".png",950,80,False)
  351. image("echap.png",1100,0,False)
  352. points_1=1
  353. elif position==presence_II:
  354. image(position+".png",150 ,100,True)
  355. text1("vous êtes entrée dans "+position,900,400)
  356. text1("vous avez trouvé un indice : "+indice_II,900,450)
  357. numero = int(piece.index(position))
  358. image2("carte "+str(numero)+".png",950,80,False)
  359. image("echap.png",1100,0,False)
  360. points_2=1
  361. elif position==presence_III:
  362. image(position+".png",150 ,100,True)
  363. text1("vous êtes entrée dans "+position,900,400)
  364. text1("vous avez trouvé un indice : "+indice_III,900,450)
  365. numero = int(piece.index(position))
  366. image2("carte "+str(numero)+".png",950,80,False)
  367. image("echap.png",1100,0,False)
  368. points_3=1
  369. pygame.display.flip()
  370.  
  371. #afficher "Vous pouvez fermer" et "Au revoir et A bientot"
  372. if quiter == 1:
  373. text1("Vous pouvez fermer",1130,0)
  374. text1("Au revoir et A bientot",800,0)
  375. pygame.display.flip()
  376.  
  377. #fin de la 1ère étape apres avoir trouvé tous les indices
  378. if (points_1+points_2+points_3) == 3:
  379. continuer=1
  380. image("echap.png",1100,0,False)
  381.  
  382. pygame.time.delay(500)
  383.  
  384. pygame.time.delay(1000)
  385. fenetre.fill(blank_color)
  386.  
  387. premiere_zone = pygame.Rect((100, 100), (250, 300))
  388. rect_surf_1 = pygame.Surface(premiere_zone.size)
  389. rect_surf_1.set_alpha(0)
  390. deuxieme_zone = pygame.Rect((400, 100), (250, 300))
  391. rect_surf_2 = pygame.Surface(deuxieme_zone.size)
  392. rect_surf_2.set_alpha(0)
  393. troisieme_zone = pygame.Rect((700, 100), (250, 300))
  394. rect_surf_3 = pygame.Surface(troisieme_zone.size)
  395. rect_surf_3.set_alpha(0)
  396. quatrieme_zone = pygame.Rect((1000, 100), (250, 300))
  397. rect_surf_4 = pygame.Surface(quatrieme_zone.size)
  398. rect_surf_4.set_alpha(0)
  399.  
  400.  
  401. fenetre.blit(rect_surf_1, premiere_zone)
  402.  
  403. fenetre.blit(rect_surf_2, deuxieme_zone)
  404. fenetre.blit(rect_surf_3, troisieme_zone)
  405. fenetre.blit(rect_surf_4, quatrieme_zone)
  406. pygame.display.flip()
  407.  
  408.  
  409. while suite == 0:
  410. perdu = 0
  411. fenetre.fill(blank_color)
  412. #detection touche
  413. for event in pygame.event.get():
  414. if event.type == pygame.KEYDOWN:
  415. if event.key == pygame.K_ESCAPE:
  416. text1("Vous pouvez fermer",1130,0)
  417. text1("Au revoir et A bientot",1130,20)
  418. suite=1
  419. ecran_fin = 1
  420. if event.type == pygame.MOUSEBUTTONDOWN: # quand je relache le bouton
  421. if event.button == 1: # 1= clique gauche
  422. if premiere_zone.collidepoint(event.pos) and meutrier == 2:
  423. suite = 1
  424. elif premiere_zone.collidepoint(event.pos) and meutrier != 2:
  425. perdu = 1
  426. elif deuxieme_zone.collidepoint(event.pos) and meutrier == 1:
  427. suite = 1
  428. elif deuxieme_zone.collidepoint(event.pos) and meutrier != 1:
  429. perdu = 1
  430. elif troisieme_zone.collidepoint(event.pos) and meutrier == 0:
  431. suite = 1
  432. elif troisieme_zone.collidepoint(event.pos) and meutrier != 0:
  433. perdu = 1
  434. elif quatrieme_zone.collidepoint(event.pos) and meutrier == 3:
  435. suite = 1
  436. elif quatrieme_zone.collidepoint(event.pos) and meutrier != 3:
  437. perdu = 1
  438.  
  439. text1("Vous avez trouvez tous les indice : "+indice_I+", "+indice_II+", "+indice_III,400,0)
  440. text1("Trouver le meurtier !",550,20)
  441. text2("Utiliser la souris pour cliquer sur le tueur présumé",400,600,40)
  442.  
  443.  
  444. #detection du tueur
  445. if indice_I == "Couteau" or indice_II == "Couteau" or indice_III == "Couteau":
  446. meutrier = 0
  447. elif indice_I == "Matraque" or indice_II == "Matraque" or indice_III == "Matraque":
  448. meutrier = 1
  449. elif indice_I == "Chandelier" or indice_II == "Chandelier" or indice_III == "Chandelier":
  450. meutrier = 2
  451. elif indice_I == "Clé anglaise" or indice_II == "Clé anglaise" or indice_III == "Clé anglaise":
  452. meutrier = 3
  453.  
  454. tueur()
  455.  
  456. if perdu == 1:
  457. text1("Vous avez Perdu ",600,500)
  458. text1("Ce n'est pas le tueur ",590,530)
  459. text1("Recommencer",610,560)
  460. image("echap.png",1100,0,False)
  461. pygame.display.flip()
  462. pygame.time.delay(1000)
  463.  
  464.  
  465. image("echap.png",1100,0,False)
  466. pygame.display.flip()
  467.  
  468.  
  469. while ecran_fin == 0:
  470. image("GG.png",400 ,100,True)
  471. image("echap.png",1100,0,False)
  472. text2("Bien joué vous avez trouvé le teur",350,50,60)
  473. text1("Jeu réalisé pas KreeZe",1150,740)
  474. pygame.display.flip()
  475. for event in pygame.event.get():
  476. if event.type == pygame.KEYDOWN:
  477. if event.key == pygame.K_ESCAPE:
  478. text1("Vous pouvez fermer",1130,0)
  479. text1("Au revoir et A bientot",1130,20)
  480. ecran_fin = 1
  481. pygame.quit()
  482.  
  483.  
  484. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement