Advertisement
Black_Albatros

Version presque finale

Jun 9th, 2023
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.62 KB | Gaming | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Jun 7 15:15:20 2023
  4.  
  5. @author: Utilisateur
  6. """
  7.  
  8. import random
  9.  
  10. from colorama import Style, Fore
  11.  
  12.  
  13.  
  14.  
  15. def affichage(tab):
  16.  
  17. for i in range(0,10):
  18.  
  19. for j in range(0,10):
  20.  
  21. if tab[i][j] == 1:
  22.  
  23. print("\t",'■', end = '')
  24.  
  25. elif tab[i][j] == 0:
  26.  
  27. print("\t",'.', end = '')
  28.  
  29. elif tab[i][j] == 3:
  30.  
  31. print("\t",'ᗧ', end = '')
  32.  
  33. elif tab[i][j] == 2:
  34.  
  35. print("\t",'●', end = '')
  36.  
  37. elif tab[i][j] == 4:
  38.  
  39. print("\t",'👻', end = '')
  40.  
  41. print("\n")
  42.  
  43.  
  44.  
  45. print("\n")
  46.  
  47.  
  48.  
  49.  
  50.  
  51. def fin():
  52.  
  53. print("~ PARTIE TERMINEE ~")
  54.  
  55. print(" VOULEZ VOUS REJOUEZ ? \n")
  56.  
  57. rep= input(print (" OUI/NON "))
  58.  
  59. if rep == 'OUI':
  60.  
  61. main
  62.  
  63. else :
  64.  
  65. print(Style.BRIGHT + Fore.GREEN +"Au revoir!\n")
  66.  
  67. print(Style.RESET_ALL)
  68.  
  69. is_ended = True
  70.  
  71.  
  72.  
  73. def menu ():
  74.  
  75. # print(Style.NORMAL + Fore.GREEN +"\n――――――― MENU ―――――――\n")
  76. for line in m:
  77. print(Style.BRIGHT + Fore.GREEN + line)
  78.  
  79. print(Style.BRIGHT + Fore.MAGENTA +"\n1 ― Lancer une partie ")
  80.  
  81. print(Style.BRIGHT + Fore.CYAN +"2 ― Afficher les règles")
  82.  
  83. print((Style.BRIGHT + Fore.BLUE) +"3 ― Afficher les crédits")
  84.  
  85. print(Style.BRIGHT + Fore.GREEN +"4 ― Quitter\n")
  86.  
  87. print(Style.RESET_ALL)
  88.  
  89. choix = input("Entrez le numéro de votre choix : ")
  90.  
  91. return choix
  92.  
  93.  
  94.  
  95. def rules():
  96.  
  97. print(Style.NORMAL + Fore.CYAN +"\n―――――――――――――――――――― REGLES ――――――――――――――――――――\n")
  98.  
  99. print(Style.RESET_ALL)
  100.  
  101. print("Le Pac-man est un jeu où il faut accumuler des points pour gagner")
  102.  
  103. print("Vous êtes le Pac-man, pour gagner vous devez collecter des super gommes.")
  104.  
  105. print("Ces dernieres vous immunisent aux fantomes et vous permet de les manger. ")
  106.  
  107. print("Attention si un fantome vous touche sans que vous soyer sous super vous perdez 1 vie ")
  108.  
  109. print("Vous disposer d'un total de 3 vies")
  110.  
  111. print("Bonne chance !!")
  112.  
  113. def crédits():
  114.  
  115. print(Style.BRIGHT + Fore.BLUE +"\n――――――――――――――――― CREDITS ―――――――――――――――――\n")
  116.  
  117. print(Style.RESET_ALL)
  118.  
  119. print("Développé par AMIOT Antoine et REFFAY Paul")
  120.  
  121.  
  122.  
  123. def main():
  124.  
  125. while True:
  126.  
  127. choix = menu() # affichage du menu principal et récupération du choix de l'utilisateur
  128.  
  129. if choix == '1':
  130.  
  131. # grid()
  132.  
  133. break
  134.  
  135. if choix == '2':
  136.  
  137. rules()
  138.  
  139. main()
  140.  
  141. if choix == '3':
  142.  
  143. crédits()
  144.  
  145. main()
  146.  
  147. elif choix == '4':
  148.  
  149. return fin()
  150.  
  151.  
  152.  
  153.  
  154.  
  155. def grid():
  156.  
  157. bg =[]
  158.  
  159. bg_size=[10,10]
  160.  
  161. for i in range(bg_size[0]):
  162.  
  163. line =[]
  164.  
  165. for j in range(bg_size[1]):
  166.  
  167. line.append('0')
  168.  
  169. bg.append(line)
  170.  
  171. for i in range(bg_size[0]):
  172.  
  173. for j in range(bg_size[1]):
  174.  
  175. if (i == 0 or i == 9 or j == 0 or j == 9):
  176.  
  177. bg[i][j] = 1
  178.  
  179. else:
  180.  
  181. bg[i][j] = 0
  182.  
  183.  
  184.  
  185. return bg
  186.  
  187.  
  188.  
  189.  
  190.  
  191. bg = grid()
  192.  
  193. bg [2][2] = 1
  194.  
  195. bg [2][3] = 1
  196.  
  197. bg [3][2] = 1
  198.  
  199. bg [4][2] = 1
  200.  
  201. bg [5][2] = 1
  202.  
  203. bg [2][5] = 1
  204.  
  205. bg [2][6] = 1
  206.  
  207. bg [2][7] = 1
  208.  
  209. bg [2][8] = 1
  210.  
  211. bg [4][4] = 1
  212.  
  213. bg [4][6] = 1
  214.  
  215. bg [4][7] = 1
  216.  
  217. bg [5][7] = 1
  218.  
  219. bg [7][2] = 1
  220.  
  221. bg [7][3] = 1
  222.  
  223. bg [7][4] = 1
  224.  
  225. bg [7][5] = 1
  226.  
  227. bg [7][7] = 1
  228.  
  229. bg [6][4] = 1
  230.  
  231. bg [6][5] = 1
  232.  
  233. bg [4][3] = 1
  234.  
  235. #pac gomme
  236.  
  237. bg [1][8] = 2
  238.  
  239. bg [8][2] = 2
  240.  
  241. bg [3][3] = 2
  242.  
  243.  
  244.  
  245. #pac man
  246.  
  247. position = [3, 1]
  248.  
  249. bg [position[0]][position[1]] = 3
  250.  
  251.  
  252.  
  253.  
  254.  
  255. #fantomes
  256.  
  257.  
  258.  
  259. ft1 = [8,8]
  260.  
  261. ft2 = [6,6]
  262.  
  263. bg [ft1[0]][ft1[1]] = 4
  264.  
  265. bg [ft2[0]][ft2[1]] = 4
  266.  
  267.  
  268.  
  269. score = 0
  270. m= [
  271. " _________________________________________________ ",
  272. " | _ |",
  273. " | |\/| |_ |\| | | | |",
  274. " | | | |_ | | |_| . |" ,
  275. " |_________________________________________________|",
  276. ]
  277. game_over = [
  278. " _____ __ __ ______ ______ ________ _____ _ ",
  279. " / ____| /\ | \/ | ____| / __ \ \ / / ____| __ \ | | ",
  280. " | | __ / \ | \ / | |__ | | | \ \ / /| |__ | |__) | | | ",
  281. " | | |_ | / /\ \ | |\/| | __| | | | |\ \/ / | __| | _ / |_| ",
  282. " | |__| |/ ____ \| | | | |____ | |__| | \ / | |____| | \ \ _ ",
  283. " \_____/_/ \_\_| |_|______| \____/ \/ |______|_| \_\ |_| ",
  284. ]
  285.  
  286. win = [
  287. "__ _ _ ____ _____ ____ _ _____ _____ _ ",
  288. "\ \ / | |/ __/__ __\ __ \| || __ \| ___| | |",
  289. " \ \ / /| | | | | | | | | || |__) || |__ | |",
  290. " \ \/ / | | | | | | | | | || _ / | __| |_|",
  291. " \ / | | |__ | | | |__| | || | \ \ | |___ _ ",
  292. " \/ |_| ___\ |_| \____/|_||_| \_\|_____| |_|",
  293. ]
  294.  
  295. #Fonction pour Mouvement PACMAN
  296.  
  297. def le_mouvement_est_valide(direction, position, grid):
  298. if (direction == "gauche" and grid[position[0]][position[1] - 1] != 1 and grid[position[0]][position[1] - 1] != 4 and grid[position[0]][position[1] - 1] != 2):
  299. return 0
  300. elif (direction == "droite" and grid[position[0]][position[1] + 1] != 1 and grid[position[0]][position[1] + 1] != 4 and grid[position[0]][position[1] + 1] != 2):
  301. return 0
  302. elif (direction == "bas" and grid[position[0]+1][ position[1]] != 1 and grid[position[0]+1][position[1]] != 4 and grid[position[0]+1][position[1]] != 2):
  303. return 0
  304. elif (direction == "haut" and grid[position[0]-1][position[1]] != 1 and grid[position[0]-1][position[1]] != 4 and grid[position[0]-1][position[1]] != 2):
  305. return 0
  306. else:
  307. if (direction == "gauche" and grid[position[0]][position[1] - 1] == 1) or (direction == "droite" and grid[position[0]][position[1] + 1] == 1) or (direction == "bas" and grid[position[0]+1][ position[1]] == 1) or (direction == "haut" and grid[position[0]-1][position[1]] != 1):
  308. return 1
  309. elif (direction == "droite" and grid[position[0]][position[1] + 1] == 2) or (direction == "gauche" and grid[position[0]][position[1] - 1] == 2 ) or (direction == "haut" and grid[position[0]-1][position[1]] ==2) or (direction == "bas" and grid[position[0]+1][ position[1]] == 2):
  310. return 2
  311. elif (direction == "droite" and grid[position[0]][position[1] + 1] == 4) or (direction == "gauche" and grid[position[0]][position[1] - 1] == 4 ) or (direction == "haut" and grid[position[0]-1][position[1]] ==4) or (direction == "bas" and grid[position[0]+1][ position[1]] == 4):
  312. return 4
  313.  
  314.  
  315.  
  316. def choisir_direction_aleatoire1(direction,ft1):
  317. direction_ftm1 = choisir_direction_aleatoire1()
  318. nouvelle_position_ftm1 = goTo(direction_ftm1, ft1)
  319. direction = ["gauche", "droite", "haut", "bas"]
  320. return random.choice(direction)
  321.  
  322.  
  323. def choisir_direction_aleatoire2(direction,ft2):
  324. direction_ftm2 = choisir_direction_aleatoire2()
  325. nouvelle_position_ftm2 = goTo(direction_ftm2, ft2)
  326. direction = ["gauche", "droite", "haut", "bas"]
  327. return random.choice(direction)
  328.  
  329.  
  330.  
  331. def goTo(direction, position):
  332.  
  333. nouvelle_position = position.copy()
  334.  
  335. if (direction == "bas"):
  336.  
  337. nouvelle_position[0] += 1
  338.  
  339. elif (direction == "haut"):
  340.  
  341. nouvelle_position[0] -= 1
  342.  
  343. elif (direction == "gauche"):
  344.  
  345. nouvelle_position[1] -= 1
  346.  
  347. elif (direction == "droite"):
  348.  
  349. nouvelle_position[1] += 1
  350.  
  351.  
  352.  
  353. return nouvelle_position
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361. is_ended = False
  362.  
  363.  
  364.  
  365. main()
  366. joueur = input("entre ton nom :")
  367. score = 0
  368.  
  369. while (not is_ended):
  370.  
  371.  
  372. print(joueur)
  373. affichage(bg)
  374.  
  375.  
  376.  
  377. command = input("Entrez votre déplacement :\nGauche : 4 ; Droite : 6 ; Haut : 8 ; Bas : 2\n")
  378. print("score =",score)
  379.  
  380.  
  381.  
  382.  
  383. """
  384.  
  385. Gestion des touches pour les directions
  386.  
  387. """
  388.  
  389. if (command == "4"):
  390.  
  391. direction = "gauche"
  392.  
  393. elif (command == "6"):
  394.  
  395. direction = "droite"
  396.  
  397. elif (command == "8"):
  398.  
  399. direction = "haut"
  400.  
  401. elif (command == "2"):
  402.  
  403. direction = "bas"
  404.  
  405.  
  406.  
  407. #Déplacement PACMAN
  408.  
  409. valide = le_mouvement_est_valide(direction, position, bg)
  410.  
  411. if valide == 0:
  412.  
  413. print("Déplacement possible...")
  414. bg[position[0]][position[1]] = 0
  415. position = goTo(direction, position)
  416. bg[position[0]][position[1]] = 3
  417. print("La nouvelle position est", position)
  418.  
  419.  
  420.  
  421. elif valide == 2 :
  422. print("Déplacement possible...")
  423. bg[position[0]][position[1]] = 0
  424. position = goTo(direction, position)
  425. bg[position[0]][position[1]] = 3
  426. score = score + 1
  427. print("score = ", score)
  428.  
  429.  
  430. elif valide == 1 :
  431. print("Déplacement impossible... mur")
  432.  
  433.  
  434. elif valide == 4 :
  435. bg[position[0]][position[1]] = 0
  436.  
  437. # position = goTo(direction, position)
  438.  
  439. # bg[position[0]][position[1]] = 4
  440.  
  441. print(joueur,"a perdu la partie")
  442.  
  443. for line in game_over:
  444. print(Style.BRIGHT + Fore.RED + line)
  445.  
  446. break
  447.  
  448. if score == 3 :
  449. print(joueur,"a gagné la partie")
  450. for line in win:
  451. print(Style.BRIGHT + Fore.YELLOW + line)
  452.  
  453. break
  454.  
  455.  
  456.  
  457.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement