Advertisement
Black_Albatros

Untitled

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