Advertisement
Black_Albatros

Untitled

Jun 5th, 2023
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.67 KB | Gaming | 0 0
  1.  
  2.  
  3. from colorama import Style, Fore
  4.  
  5.  
  6. def affichage(tab):
  7.     for i in range(0,10):
  8.         for j in range(0,10):
  9.             if tab[i][j] == 1:
  10.                 print("\t",'■', end = '')
  11.             elif tab[i][j] == 0:
  12.                 print("\t",'.', end = '')
  13.             elif tab[i][j] == 3:
  14.                 print("\t",'ᗧ', end = '')
  15.             elif tab[i][j] == 2:
  16.                 print("\t",'●', end = '')
  17.             elif tab[i][j] == 4:
  18.                 print("\t",'👻', end = '')
  19.  
  20.         print("\n")
  21.    
  22.     print("\n")
  23.  
  24.  
  25. def fin():
  26.     print("~      PARTIE TERMINEE      ~/n Voulez vous rejouer ? ")
  27.        
  28. def menu ():
  29.     print(Style.NORMAL + Fore.GREEN +"\n――――――― MENU ―――――――\n")
  30.     print(Style.BRIGHT + Fore.MAGENTA +"1 ― Lancer une partie ")
  31.     print(Style.BRIGHT + Fore.CYAN +"2 ― Afficher les règles")
  32.     print((Style.BRIGHT + Fore.BLUE) +"3 ― Afficher les crédits")
  33.     print(Style.BRIGHT + Fore.GREEN +"4 ― Quitter\n")
  34.     print(Style.RESET_ALL)
  35.     choix = input("Entrez le numéro de votre choix : ")
  36.     return choix
  37.  
  38.  
  39. def rules():
  40.     print(Style.NORMAL + Fore.CYAN +"\n―――――――――――――――――――― REGLES ――――――――――――――――――――\n")
  41.     print(Style.RESET_ALL)
  42.     print("Le Pac-man est un jeu où il faut accumuler des points pour gagner")
  43.     print("Vous êtes le Pac-man, pour gagner vous devez collecter des super gommes.")
  44.     print("Ces dernieres vous immunisent aux fantomes et vous permet de les manger. ")
  45.     print("Attention si un fantome vous touche sans que vous soyer sous super vous perdez 1 vie ")
  46.     print("Vous disposer d'un total de 3 vies")
  47.     print("Bonne chance !!")
  48.  
  49. def crédits():
  50.     print(Style.BRIGHT + Fore.BLUE +"\n――――――――――――――――― CREDITS ―――――――――――――――――\n")
  51.     print(Style.RESET_ALL)
  52.     print("Développé par AMIOT Antoine et REFFAY Paul")
  53.  
  54.  
  55. def main():
  56.     while True:
  57.         choix = menu()  # affichage du menu principal et récupération du choix de l'utilisateur
  58.         if choix == '1':
  59.             # grid()
  60.             break
  61.         if choix == '2':
  62.             rules()
  63.             main()
  64.         if choix == '3':
  65.             crédits()
  66.             main()
  67.         elif choix == '4':
  68.             print(Style.BRIGHT + Fore.GREEN +"Au revoir!\n")
  69.             print(Style.RESET_ALL)
  70.             return fin()
  71.            
  72.    
  73. def grid():
  74.     bg =[]
  75.     bg_size=[10,10]
  76.     for i in range(bg_size[0]):
  77.         line =[]
  78.         for j in range(bg_size[1]):
  79.             line.append('0')
  80.         bg.append(line)
  81.  
  82.     for i in range(bg_size[0]):
  83.         for j in range(bg_size[1]):
  84.             if (i == 0 or i == 9 or j == 0 or j == 9):
  85.                 bg[i][j] = 1
  86.             else:
  87.                 bg[i][j] = 0
  88.    
  89.     return bg
  90.  
  91.  
  92. bg = grid()
  93.  
  94. bg [2][2] = 1
  95. bg [2][3] = 1
  96. bg [3][2] = 1
  97. bg [4][2] = 1
  98. bg [5][2] = 1
  99. bg [2][5] = 1
  100. bg [2][6] = 1
  101. bg [2][7] = 1
  102. bg [2][8] = 1
  103. bg [4][4] = 1
  104. bg [4][6] = 1
  105. bg [4][7] = 1
  106. bg [5][7] = 1
  107. bg [7][2] = 1
  108. bg [7][3] = 1
  109. bg [7][4] = 1
  110. bg [7][5] = 1
  111. bg [7][7] = 1
  112. bg [6][4] = 1
  113. bg [6][5] = 1
  114.  
  115. #pac gomme
  116. bg [1][8] = 2
  117. bg [8][2] = 2
  118. bg [3][3] = 2
  119.  
  120. #pac man
  121. position = [3, 1]
  122. bg [position[0]][position[1]] = 3
  123.  
  124.  
  125. #fantomes
  126.  
  127. ft1 = [8,8]
  128. ft2 = [6,6]
  129. bg [ft1[0]][ft1[1]] = 4
  130. bg [ft2[0]][ft2[1]] = 4
  131.  
  132. score = 0
  133.  
  134.  
  135. def le_mouvement_est_valide(direction, position, grid):
  136.     if (direction == "gauche" and grid[position[0]][position[1] - 1] != 1):
  137.         return True
  138.     elif (direction == "droite" and grid[position[0]][position[1] + 1] != 1):
  139.         return True
  140.     elif (direction == "bas" and grid[position[0]+1][ position[1]] != 1):
  141.         return True
  142.     elif (direction == "haut" and grid[position[0]-1][position[1]] != 1):
  143.         return True
  144.    
  145.  
  146.  
  147.  
  148.  
  149.  
  150. # def mouvement_fantome :
  151.    
  152.    
  153.    
  154.    
  155.    
  156. # def fantome_en_face(direction, position, grid):
  157. #     if (direction == "gauche" and grid[position[0]][position[1] - 1] == 4):
  158. #         return True
  159. #     elif (direction == "droite" and grid[position[0]][position[1] + 1] == 4):
  160. #         return True
  161. #     elif (direction == "bas" and grid[position[0]+1][ position[1]] == 4):
  162. #         return True
  163. #     elif (direction == "haut" and grid[position[0]-1][position[1]] == 4):
  164. #         return True
  165.  
  166.  
  167. # def super_en_face (direction, position,grid):
  168. #     if (direction == "gauche" and grid[position[0]][position[1] - 1] == 2):
  169. #         return True
  170. #     elif (direction == "droite" and grid[position[0]][position[1] + 1] == 2):
  171. #         return True
  172. #     elif (direction == "bas" and grid[position[0]+1][ position[1]] == 2):
  173. #         return True
  174. #     elif (direction == "haut" and grid[position[0]-1][position[1]] == 2):
  175. #         return True
  176.  
  177.  
  178.  
  179. def goTo(direction, position):
  180.     nouvelle_position = position
  181.     if (direction == "bas"):
  182.         nouvelle_position[0] += 1
  183.     elif (direction == "haut"):
  184.         nouvelle_position[0] -= 1
  185.     elif (direction == "gauche"):
  186.         nouvelle_position[1] -= 1
  187.     elif (direction == "droite"):
  188.         nouvelle_position[1] += 1
  189.    
  190.     return nouvelle_position
  191.  
  192. # def gotoftm
  193.  
  194. is_ended = False
  195.  
  196.  
  197.  
  198.  
  199. while (not is_ended):
  200.     # main()
  201.     affichage(bg)
  202.  
  203.     command = input("Entrez votre déplacement :\nGauche : 4 ; Droite : 6 ; Haut : 8 ; Bas : 2\n")
  204.    
  205.  
  206.     """
  207.    Gestion des touches pour les directions
  208.    """
  209.     if (command == "4"):
  210.         direction = "gauche"
  211.     elif (command == "6"):
  212.         direction = "droite"
  213.     elif (command == "8"):
  214.         direction = "haut"
  215.     elif (command == "2"):
  216.         direction = "bas"
  217.  
  218.    
  219.     if (le_mouvement_est_valide(direction, position, bg)): # Si le déplacement est valide / possible
  220.         print("Déplacement possible...")
  221.         bg[position[0]][position[1]] = 0 # Le pacman n'est plus à l'ancienne position
  222.         position = goTo(direction, position) # J'actualise la position
  223.         bg[position[0]][position[1]] = 3 # Je mets à jour la grid
  224.         print("La nouvelle position est", position)
  225.     else :
  226.         print("Déplacement impossible...")
  227.  
  228.  
  229.     # if (fantome_en_face(direction, position, grid)):
  230.     #     print("Tu as perdu")
  231.     #     bg[position[0]][position[1]] = 0
  232.     #     position = goTo(direction, position)
  233.     #     bg[position[0]][position[1]] = 4
  234.     #     fin()
  235.        
  236.        
  237.     # if (super_en_face(direction, position, grid)):
  238.     #     bg[position[0]][position[1]] = 0
  239.     #     position = goTo(direction, position)
  240.     #     bg[position[0]][position[1]] = 3
  241.     #     score = score + 1
  242.  
  243.     # if ((command == '4')
  244.     #       and (bg[position[0]][position[1] - 1] == 4)):
  245.     #       gauche()
  246.     #       print ("tu as perdu")
  247.     #       bg[position[0]][position[1]] = 4
  248.     #       is_ended = True
  249.     #       fin ()
  250.          
  251.     # elif ((command == '8')
  252.     #       and (bg[position[0]-1][position[1]] == 4)):
  253.     #       haut()
  254.     #       print ("tu as perdu")
  255.     #       bg[position[0]][position[1]] = 4
  256.     #       is_ended = True
  257.     #       fin ()
  258.          
  259.     # elif ((command == '2')
  260.     #       and (bg[position[0]+1][ position[1]] == 4)):
  261.     #       bas()
  262.     #       print ("tu as perdu")
  263.     #       bg[position[0]][position[1]] = 4
  264.     #       is_ended = True
  265.     #       fin ()
  266.     # elif ((command == '6')
  267.     #       and (bg[position[0]][position[1] + 1] == 4)):
  268.     #       droite()
  269.     #       print ("tu as perdu")
  270.     #       bg[position[0]][position[1]] = 4
  271.     #       is_ended = True
  272.     #       fin ()  
  273.  
  274.    
  275.        
  276. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement