Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from colorama import Style, Fore
- def affichage(tab):
- for i in range(0,10):
- for j in range(0,10):
- if tab[i][j] == 1:
- print("\t",'■', end = '')
- elif tab[i][j] == 0:
- print("\t",'.', end = '')
- elif tab[i][j] == 3:
- print("\t",'ᗧ', end = '')
- elif tab[i][j] == 2:
- print("\t",'●', end = '')
- elif tab[i][j] == 4:
- print("\t",'👻', end = '')
- print("\n")
- print("\n")
- def fin():
- print("~ PARTIE TERMINEE ~")
- print(" VOULEZ VOUS REJOUEZ ? \n")
- rep= input(print (" OUI/NON "))
- if rep == 'OUI':
- main
- else :
- print(Style.BRIGHT + Fore.GREEN +"Au revoir!\n")
- print(Style.RESET_ALL)
- is_ended = True
- def menu ():
- print(Style.NORMAL + Fore.GREEN +"\n――――――― MENU ―――――――\n")
- print(Style.BRIGHT + Fore.MAGENTA +"1 ― Lancer une partie ")
- print(Style.BRIGHT + Fore.CYAN +"2 ― Afficher les règles")
- print((Style.BRIGHT + Fore.BLUE) +"3 ― Afficher les crédits")
- print(Style.BRIGHT + Fore.GREEN +"4 ― Quitter\n")
- print(Style.RESET_ALL)
- choix = input("Entrez le numéro de votre choix : ")
- return choix
- def rules():
- print(Style.NORMAL + Fore.CYAN +"\n―――――――――――――――――――― REGLES ――――――――――――――――――――\n")
- print(Style.RESET_ALL)
- print("Le Pac-man est un jeu où il faut accumuler des points pour gagner")
- print("Vous êtes le Pac-man, pour gagner vous devez collecter des super gommes.")
- print("Ces dernieres vous immunisent aux fantomes et vous permet de les manger. ")
- print("Attention si un fantome vous touche sans que vous soyer sous super vous perdez 1 vie ")
- print("Vous disposer d'un total de 3 vies")
- print("Bonne chance !!")
- def crédits():
- print(Style.BRIGHT + Fore.BLUE +"\n――――――――――――――――― CREDITS ―――――――――――――――――\n")
- print(Style.RESET_ALL)
- print("Développé par AMIOT Antoine et REFFAY Paul")
- def main():
- while True:
- choix = menu() # affichage du menu principal et récupération du choix de l'utilisateur
- if choix == '1':
- # grid()
- break
- if choix == '2':
- rules()
- main()
- if choix == '3':
- crédits()
- main()
- elif choix == '4':
- return fin()
- def grid():
- 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
- return bg
- bg = grid()
- 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
- ft1 = [8,8]
- ft2 = [6,6]
- bg [ft1[0]][ft1[1]] = 4
- bg [ft2[0]][ft2[1]] = 4
- score = 0
- #Fonction pour Mouvement PACMAN
- def le_mouvement_est_valide(direction, position, grid):
- if (direction == "gauche" and grid[position[0]][position[1] - 1] != 1):
- return True
- elif (direction == "droite" and grid[position[0]][position[1] + 1] != 1):
- return True
- elif (direction == "bas" and grid[position[0]+1][ position[1]] != 1):
- return True
- elif (direction == "haut" and grid[position[0]-1][position[1]] != 1):
- return True
- #Fonction pour interaction fantome
- def le_mvmt_est_invalide(direction, position,grid):
- if (direction == "gauche" and grid[position[0]][position[1] - 1] == 4):
- return True
- elif (direction == "droite" and grid[position[0]][position[1] + 1] ==4):
- return True
- elif (direction == "bas" and grid[position[0]+1][ position[1]] == 4):
- return True
- elif (direction == "haut" and grid[position[0]-1][position[1]] == 4):
- return True
- # def manger_super (direction,position,grid):
- # if (direction == "gauche" and grid[position[0]][position[1] - 1] == 2):
- # return True
- # elif (direction == "droite" and grid[position[0]][position[1] + 1] == 2):
- # return True
- # elif (direction == "bas" and grid[position[0]+1][ position[1]] == 2):
- # return True
- # elif (direction == "haut" and grid[position[0]-1][position[1]] == 2):
- # return True
- # fonction mouvement des fantomes en aléatoire
- # def choisir_direction_aleatoire1(direction,ft1):
- # nouvelle_position_ftm1 = goTo(direction_ftm1, ft1)
- # direction = ["gauche", "droite", "haut", "bas"]
- # return random.choice(direction)
- # def choisir_direction_aleatoire2(direction,ft2):
- # nouvelle_position_ftm2 = goTo(direction_ftm2, ft2)
- # direction = ["gauche", "droite", "haut", "bas"]
- # return random.choice(direction)
- def goTo(direction, position):
- nouvelle_position = position
- if (direction == "bas"):
- nouvelle_position[0] += 1
- elif (direction == "haut"):
- nouvelle_position[0] -= 1
- elif (direction == "gauche"):
- nouvelle_position[1] -= 1
- elif (direction == "droite"):
- nouvelle_position[1] += 1
- return nouvelle_position
- is_ended = False
- score = 0
- main()
- while (not is_ended):
- affichage(bg)
- command = input("Entrez votre déplacement :\nGauche : 4 ; Droite : 6 ; Haut : 8 ; Bas : 2\n")
- """
- Gestion des touches pour les directions
- """
- if (command == "4"):
- direction = "gauche"
- elif (command == "6"):
- direction = "droite"
- elif (command == "8"):
- direction = "haut"
- elif (command == "2"):
- direction = "bas"
- #Déplacement PACMAN
- if (le_mouvement_est_valide(direction, position, bg)):
- print("Déplacement possible...")
- bg[position[0]][position[1]] = 0
- position = goTo(direction, position)
- bg[position[0]][position[1]] = 3
- print("La nouvelle position est", position)
- else :
- print("Déplacement impossible...")
- # Interaction avec les fantômes
- if (le_mvmt_est_invalide(direction, position, bg)):
- bg[position[0]][position[1]] = 0
- position = goTo(direction, position)
- is_ended = True
- bg[position[0]][position[1]] = 4
- print("\n――――――――――――――――― TU AS PERDU ―――――――――――――――――\n")
- main()
- # mouvement des fantomes en aléatoire
- # if (le_mouvement_est_valide(direction_ftm1, ft1, bg)) and bg !=1:
- # direction_ftm1 = choisir_direction_aleatoire1()
- # bg[ft1[0]][ft1[1]] = 0
- # ft1 = nouvelle_position_ftm1
- # bg[ft1[0]][ft1[1]] = 4
- # if (le_mouvement_est_valide(direction_ftm2, ft2, bg)) and bg !=1:
- # direction_ftm2 = choisir_direction_aleatoire2()
- # bg[ft2[0]][ft2[1]] = 0
- # ft2 = nouvelle_position_ftm2
- # bg[ft2[0]][ft2[1]] = 4
- # if (manger_super(direction, position, grid)):
- # score = score +1
- # print("score =",score)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement