Advertisement
Black_Albatros

python pacman test

May 30th, 2023
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.13 KB | Gaming | 0 0
  1. from colorama import Style, Fore
  2.  
  3.  
  4. def affichage(tab):
  5.     for i in range(0,10):
  6.         for j in range(0,10):
  7.             if tab[i][j] == 1:
  8.                 print("\t",'■', end = '')
  9.             elif tab[i][j] == 0:
  10.                 print("\t",'.', end = '')
  11.             elif tab[i][j] == 3:
  12.                 print("\t",'ᗧ', end = '')
  13.             elif tab[i][j] == 2:
  14.                 print("\t",'●', end = '')
  15.             elif tab[i][j] == 4:
  16.                 print("\t",'👻', end = '')
  17.  
  18.         print()
  19.        
  20. def affich(tab):
  21.     for i in range (10):
  22.         for j in range (10):
  23.             print ("\t", tab[i][j],end='')
  24.         print()
  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 au 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.             jeu()  # lancement d'une partie de puissance 4
  60.             main()
  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.             break
  71. def jeu():
  72.     bg =[]
  73.     bg_size=[10,10]
  74.     for i in range(bg_size[0]):
  75.         line =[]
  76.         for j in range(bg_size[1]):
  77.             line.append('0')
  78.         bg.append(line)
  79.  
  80.     for i in range(bg_size[0]):
  81.         for j in range(bg_size[1]):
  82.             if (i == 0 or i == 9 or j == 0 or j == 9):
  83.                 bg[i][j] = 1
  84.             else:
  85.                 bg[i][j] = 0
  86.  
  87.  
  88.     bg [2][2] = 1
  89.     bg [2][3] = 1
  90.     bg [3][2] = 1
  91.     bg [4][2] = 1
  92.     bg [5][2] = 1
  93.     bg [2][5] = 1
  94.     bg [2][6] = 1
  95.     bg [2][7] = 1
  96.     bg [2][8] = 1
  97.     bg [4][4] = 1
  98.     bg [4][6] = 1
  99.     bg [4][7] = 1
  100.     bg [5][7] = 1
  101.     bg [7][2] = 1
  102.     bg [7][3] = 1
  103.     bg [7][4] = 1
  104.     bg [7][5] = 1
  105.     bg [7][7] = 1
  106.     bg [6][4] = 1
  107.     bg [6][5] = 1
  108.  
  109.     #pac gomme
  110.     bg [1][8] = 2
  111.     bg [8][2] = 2
  112.     bg [3][3] = 2
  113.  
  114.     #pac man
  115.     position = [3, 1]
  116.     bg [position[0]][position[1]] = 3
  117.  
  118.  
  119.     #fantomes
  120.  
  121.     ft1 = [8,8]
  122.     ft2 = [6,6]
  123.     bg [ft1[0]][ft1[1]] = 4
  124.     bg [ft2[0]][ft2[1]] = 4
  125.    
  126.     affich(bg)
  127.     affichage(bg)
  128.     def droite():
  129.        
  130.         print("Déplacement possible...")
  131.         bg[position[0]][position[1]] = 0
  132.         position[1] = position[1]-1
  133.         bg[position[0]][position[1]] = 3
  134.         print(position)
  135.  
  136.          
  137.     def haut():
  138.         print("Déplacement possible...")
  139.         bg[position[0]][position[1]] = 0
  140.         position[0] = position[0] -1
  141.         bg[position[0]][position[1]] = 3
  142.         print(position)
  143.  
  144.     def bas():
  145.         print("Déplacement possible...")
  146.         bg[position[0]][position[1]] = 0
  147.         position[0] = position[0] +1
  148.         bg[position[0]][position[1]] = 3
  149.         print(position)
  150.        
  151.     def gauche():
  152.         print("Déplacement possible...")
  153.         bg[position[0]][position[1]] = 0
  154.         position[1] = position[1] +1
  155.         bg[position[0]][position[1]] = 3
  156.         print(position)
  157.         jeu()
  158. is_ended = False
  159.  
  160.  
  161.  
  162.  
  163. while (not is_ended):
  164.    
  165.    
  166.     jeu()
  167.     command = input("Entrez votre déplacement :\nGauche : 4 ; Droite : 6 ; Haut : 8 ; Bas : 2\n")
  168.    
  169.     if ((command == '4')
  170.         and (bg[position[0]][position[1] - 1] != 1)):
  171.         gauche()
  172.        
  173.     elif ((command == '8')
  174.         and (bg[position[0]-1][position[1]] != 1)):
  175.         haut()
  176.        
  177.     elif ((command == '2')
  178.         and (bg[position[0]+1][ position[1]] != 1)):
  179.         bas()
  180.        
  181.     elif ((command == '6')
  182.         and (bg[position[0]][position[1] + 1] != 1)):
  183.         droite()
  184.     else :
  185.         print ("deplacement impossible")
  186.  
  187.    
  188.  
  189.  
  190.     if ((command == '4')
  191.           and (bg[position[0]][position[1] - 1] == 4)):
  192.           gauche()
  193.           print ("tu as perdu")
  194.           bg[position[0]][position[1]] = 4
  195.           is_ended = True
  196.           fin ()
  197.          
  198.     elif ((command == '8')
  199.           and (bg[position[0]-1][position[1]] == 4)):
  200.           haut()
  201.           print ("tu as perdu")
  202.           bg[position[0]][position[1]] = 4
  203.           is_ended = True
  204.           fin ()
  205.          
  206.     elif ((command == '2')
  207.           and (bg[position[0]+1][ position[1]] == 4)):
  208.           bas()
  209.           print ("tu as perdu")
  210.           bg[position[0]][position[1]] = 4
  211.           is_ended = True
  212.           fin ()
  213.     elif ((command == '6')
  214.           and (bg[position[0]][position[1] + 1] == 4)):
  215.           droite()
  216.           print ("tu as perdu")
  217.           bg[position[0]][position[1]] = 4
  218.           is_ended = True
  219.           fin ()  
  220.  
  221.    
  222.        
  223. main()
Tags: aled
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement