Advertisement
Black_Albatros

pacman

Jun 7th, 2023
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.72 KB | None | 0 0
  1. def affichage(tab):
  2.     for i in range(0,10):
  3.         for j in range(0,10):
  4.             if tab[i][j] == 1:
  5.                 print("\t",'■', end = '')
  6.             elif tab[i][j] == 0:
  7.                 print("\t",'.', end = '')
  8.             elif tab[i][j] == 3:
  9.                 print("\t",'ᗧ', end = '')
  10.             elif tab[i][j] == 2:
  11.                 print("\t",'●', end = '')
  12.             elif tab[i][j] == 4:
  13.                 print("\t",'👻', end = '')
  14.  
  15.         print("\n")
  16.  
  17.    
  18.  
  19. bg =[]
  20. bg_size=[10,10]
  21. for i in range(bg_size[0]):
  22.     line =[]
  23.     for j in range(bg_size[1]):
  24.         line.append('0')
  25.     bg.append(line)
  26.  
  27. for i in range(bg_size[0]):
  28.     for j in range(bg_size[1]):
  29.         if (i == 0 or i == 9 or j == 0 or j == 9):
  30.             bg[i][j] = 1
  31.         else:
  32.             bg[i][j] = 0
  33.  
  34.  
  35.    
  36. bg [2][2] = 1
  37. bg [2][3] = 1
  38. bg [3][2] = 1
  39. bg [4][2] = 1
  40. bg [5][2] = 1
  41. bg [2][5] = 1
  42. bg [2][6] = 1
  43. bg [2][7] = 1
  44. bg [2][8] = 1
  45. bg [4][4] = 1
  46. bg [4][6] = 1
  47. bg [4][7] = 1
  48. bg [5][7] = 1
  49. bg [7][2] = 1
  50. bg [7][3] = 1
  51. bg [7][4] = 1
  52. bg [7][5] = 1
  53. bg [7][7] = 1
  54. bg [6][4] = 1
  55. bg [6][5] = 1
  56.  
  57. #pac gomme
  58. bg [1][8] = 2
  59. bg [8][2] = 2
  60. bg [3][3] = 2
  61.  
  62. #pac man
  63. position = [3, 1]
  64. bg [position[0]][position[1]] = 3
  65.  
  66.  
  67. #fantomes
  68. ftm1 = [8,8]
  69. ftm2 = [6,6]
  70. bg [ftm1[0]][ftm1[1]] = 4
  71. bg [ftm2[0]][ftm2[1]] = 4
  72.  
  73.  
  74. score = 0
  75.            
  76. is_ended = False
  77.  
  78. affichage(bg)
  79.  
  80. while (not is_ended):
  81.    
  82.    
  83.    
  84.     command = input("Entrez votre déplacement :\nGauche : 4 ; Droite : 6 ; Haut : 8 ; Bas : 2\n")
  85.    
  86.     if ((command == '4')
  87.         and (bg[position[0]][position[1] - 1] != 1)):
  88.         print("Déplacement possible...")
  89.         bg[position[0]][position[1]] = 0
  90.         position[1] = position[1]-1
  91.         bg[position[0]][position[1]] = 3
  92.         print(position)
  93.        
  94.     elif ((command == '8')
  95.         and (bg[position[0]-1][position[1]] != 1)):
  96.         print("Déplacement possible...")
  97.         bg[position[0]][position[1]] = 0
  98.         position[0] = position[0] -1
  99.         bg[position[0]][position[1]] = 3
  100.         print(position)
  101.        
  102.     elif ((command == '2')
  103.         and (bg[position[0]+1][ position[1]] != 1)):
  104.         print("Déplacement possible...")
  105.         bg[position[0]][position[1]] = 0
  106.         position[0] = position[0] +1
  107.         bg[position[0]][position[1]] = 3
  108.         print(position)
  109.        
  110.     elif ((command == '6')
  111.         and (bg[position[0]][position[1] + 1] != 1)):
  112.         print("Déplacement possible...")
  113.         bg[position[0]][position[1]] = 0
  114.         position[1] = position[1] +1
  115.         bg[position[0]][position[1]] = 3
  116.         print(position)
  117.     else :
  118.         print ("deplacement impossible")
  119.  
  120.    
  121.  
  122.     if ((command == '4')
  123.         and (bg[position[0]][position[1] - 1] == 2)):
  124.         bg[position[0]][position[1]] = 0
  125.         position[1] = position[1]-1
  126.         bg[position[0]][position[1]] = 3
  127.         score = score +1
  128.        
  129.     elif ((command == '8')
  130.         and (bg[position[0]-1][position[1]] == 2)):
  131.         bg[position[0]][position[1]] = 0
  132.         position[0] = position[0] -1
  133.         bg[position[0]][position[1]] = 3
  134.         score = score +1
  135.        
  136.     elif ((command == '2')
  137.         and (bg[position[0]+1][ position[1]] == 2)):
  138.         bg[position[0]][position[1]] = 0
  139.         position[0] = position[0] +1
  140.         bg[position[0]][position[1]] = 3
  141.         score = score +1
  142.        
  143.     elif ((command == '6')
  144.         and (bg[position[0]][position[1] + 1] == 2)):
  145.         bg[position[0]][position[1]] = 0
  146.         position[1] = position[1] +1
  147.         bg[position[0]][position[1]] = 3
  148.         score = score +1
  149.      
  150.    
  151.        
  152.        
  153.     if ((command == '4')
  154.       and (bg[position[0]][position[1] - 1] == 4)):
  155.            
  156.       # bg[position[0]][position[1]] = 0
  157.       position[1] = position[1]-1
  158.       bg[position[0]][position[1]] = 4
  159.       print ("tu as perdu")
  160.       is_ended = True
  161.    
  162.     elif ((command == '8')
  163.       and (bg[position[0]-1][position[1]] == 4)):
  164.       # bg[position[0]][position[1]] = 0
  165.       position[0] = position[0] -1
  166.       bg[position[0]][position[1]] = 4
  167.       print ("tu as perdu")
  168.       is_ended = True
  169.     elif ((command == '2')
  170.      and (bg[position[0]+1][position[1]] == 4)):
  171.      # bg[position[0]][position[1]] = 0
  172.      position[0] = position[0] +1
  173.      bg[position[0]][position[1]] = 4
  174.      print ("tu as perdu")
  175.      is_ended = True
  176.     elif ((command == '6')
  177.      and (bg[position[0]][position[1] + 1] == 4)):
  178.      # bg[position[0]][position[1]] = 0
  179.      position[1] = position[1] +1
  180.      bg[position[0]][position[1]] = 4
  181.      print ("tu as perdu")
  182.      is_ended = True
  183.  
  184.    
  185.     affichage(bg)
  186.     print("score =",score)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement