Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def jeu(tab):
- for i in range (10):
- for j in range (10):
- print ("\t", tab[i][j],end='')
- print()
- bg =[]
- bg_size=[10,10]
- for i in range(bg_size[0]):
- line =[]
- for j in range(bg_size[1]):
- line.append(0)
- bg.append(line)
- for i in range(bg_size[0]):
- for j in range(bg_size[1]):
- if (i == 0 or i == 9 or j == 0 or j == 9):
- bg[i][j] = 1
- else:
- bg[i][j] = 0
- bg [2][2] = 1
- bg [2][3] = 1
- bg [3][2] = 1
- bg [4][2] = 1
- bg [5][2] = 1
- bg [2][5] = 1
- bg [2][6] = 1
- bg [2][7] = 1
- bg [2][8] = 1
- bg [4][4] = 1
- bg [4][6] = 1
- bg [4][7] = 1
- bg [5][7] = 1
- bg [7][2] = 1
- bg [7][3] = 1
- bg [7][4] = 1
- bg [7][5] = 1
- bg [7][7] = 1
- bg [6][4] = 1
- bg [6][5] = 1
- #pac gomme
- bg [1][8] = 2
- bg [8][2] = 2
- bg [3][3] = 2
- #pac man
- position = [3, 1]
- bg [position[0]][position[1]] = 3
- #fantomes
- bg [8][8] = 4
- bg [6][6] = 4
- is_ended = False
- jeu(bg)
- while (not is_ended):
- score = 0
- command = input("Entrez votre déplacement :\nGauche : 4 ; Droite : 6 ; Haut : 8 ; Bas : 2\n")
- if ((command == '4')
- and (bg[position[0]][position[1] - 1] != 1)
- and (bg[position[0]][position[1] - 1] != 4)):
- print("Déplacement possible...")
- bg[position[0]][position[1]] = 0
- position[1] = position[1]-1
- bg[position[0]][position[1]] = 3
- print(position)
- elif ((command == '8')
- and (bg[position[0]-1][position[1]] != 1)
- and (bg[position[0]-1][position[1]] != 4)):
- print("Déplacement possible...")
- bg[position[0]][position[1]] = 0
- position[0] = position[0] -1
- bg[position[0]][position[1]] = 3
- print(position)
- elif ((command == '2')
- and (bg[position[0]+1][ position[1]] != 1)
- and (bg[position[0]+1][ position[1]] != 4)):
- print("Déplacement possible...")
- bg[position[0]][position[1]] = 0
- position[0] = position[0] +1
- bg[position[0]][position[1]] = 3
- print(position)
- elif ((command == '6')
- and (bg[position[0]][position[1] + 1] != 1)
- and (bg[position[0]][position[1] + 1] != 4)):
- print("Déplacement possible...")
- bg[position[0]][position[1]] = 0
- position[1] = position[1] +1
- bg[position[0]][position[1]] = 3
- print(position)
- else :
- print ("deplacement impossible")
- if ((command == '4')
- and (bg[position[0]][position[1] - 1] == 4)):
- bg[position[0]][position[1]] = 0
- position[1] = position[1]-1
- bg[position[0]][position[1]] = 4
- print ("tu as perdu")
- is_ended = True
- elif ((command == '8')
- and (bg[position[0]-1][position[1]] == 4)):
- bg[position[0]][position[1]] = 0
- position[0] = position[0] -1
- bg[position[0]][position[1]] = 4
- print ("tu as perdu")
- is_ended = True
- elif ((command == '2')
- and (bg[position[0]+1][ position[1]] == 4)):
- bg[position[0]][position[1]] = 0
- position[0] = position[0] +1
- bg[position[0]][position[1]] = 4
- print ("tu as perdu")
- is_ended = True
- elif ((command == '6')
- and (bg[position[0]][position[1] + 1] == 4)):
- bg[position[0]][position[1]] = 0
- position[1] = position[1] +1
- bg[position[0]][position[1]] = 4
- print ("tu as perdu")
- is_ended = True
- if ((command == '4')
- and (bg[position[0]][position[1] - 1] == 2)):
- score = score +1
- bg[position[0]][position[1]] = 0
- position[1] = position[1]-1
- bg[position[0]][position[1]] = 3
- elif ((command == '8')
- and (bg[position[0]-1][position[1]] == 2)):
- score = score +1
- bg[position[0]][position[1]] = 0
- position[0] = position[0] -1
- bg[position[0]][position[1]] = 3
- elif ((command == '2')
- and (bg[position[0]+1][ position[1]] == 2)):
- score = score +1
- bg[position[0]][position[1]] = 0
- position[0] = position[0] +1
- bg[position[0]][position[1]] = 3
- elif ((command == '6')
- and (bg[position[0]][position[1] + 1] == 2)):
- score = score +1
- bg[position[0]][position[1]] = 0
- position[1] = position[1] +1
- bg[position[0]][position[1]] = 3
- print("score =",score)
- jeu(bg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement