Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- 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():
- while True :
- print("~ PARTIE TERMINEE ~")
- print(" VOULEZ VOUS REJOUEZ ? ")
- rep= input(str(print (" OUI/NON ")))
- if rep == 'OUI':
- return menu()
- break
- elif rep == 'NON':
- print(Style.BRIGHT + Fore.GREEN +"Au revoir!\n")
- print(Style.RESET_ALL)
- sys.exit()
- elif rep != 'OUI' or 'NON':
- print("Erreur veuillez saisir une réponse valide")
- return fin()
- def menu ():
- for line in m:
- print(Style.BRIGHT + Fore.GREEN + line)
- print(Style.BRIGHT + Fore.YELLOW +"1 ― Lancer une partie ")
- print(Style.BRIGHT + Fore.RED +"2 ― Règles du jeu")
- print(Style.NORMAL + Fore.WHITE + "3 - Crédits")
- print(Style.BRIGHT + Fore.GREEN +"4 ― Quitter")
- 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
- bg [4][3] = 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,1]
- ft2 = [6,6]
- bg [ft1[0]][ft1[1]] = 4
- bg [ft2[0]][ft2[1]] = 4
- score = 0
- m= [
- " _________________________________________________ ",
- " | _ |",
- " | |\/| |_ |\| | | | |",
- " | | | |_ | | |_| . |" ,
- " |_________________________________________________|",
- ]
- game_over = [
- " _____ __ __ ______ ______ ________ _____ _ ",
- " / ____| /\ | \/ | ____| / __ \ \ / / ____| __ \ | | ",
- " | | __ / \ | \ / | |__ | | | \ \ / /| |__ | |__) | | | ",
- " | | |_ | / /\ \ | |\/| | __| | | | |\ \/ / | __| | _ / |_| ",
- " | |__| |/ ____ \| | | | |____ | |__| | \ / | |____| | \ \ _ ",
- " \_____/_/ \_\_| |_|______| \____/ \/ |______|_| \_\ |_| ",
- ]
- win = [
- "__ _ _ ____ _____ ____ _ _____ _____ _ ",
- "\ \ / | |/ __/__ __\ __ \| || __ \| ___| | |",
- " \ \ / /| | | | | | | | | || |__) || |__ | |",
- " \ \/ / | | | | | | | | | || _ / | __| |_|",
- " \ / | | |__ | | | |__| | || | \ \ | |___ _ ",
- " \/ |_| ___\ |_| \____/|_||_| \_\|_____| |_|",
- ]
- #Fonction pour Mouvement PACMAN
- def le_mouvement_est_valide(direction, position, grid):
- if (direction == "gauche" and grid[position[0]][position[1] - 1] != 1 and grid[position[0]][position[1] - 1] != 4 and grid[position[0]][position[1] - 1] != 2):
- return 0
- elif (direction == "droite" and grid[position[0]][position[1] + 1] != 1 and grid[position[0]][position[1] + 1] != 4 and grid[position[0]][position[1] + 1] != 2):
- return 0
- elif (direction == "bas" and grid[position[0]+1][ position[1]] != 1 and grid[position[0]+1][position[1]] != 4 and grid[position[0]+1][position[1]] != 2):
- return 0
- elif (direction == "haut" and grid[position[0]-1][position[1]] != 1 and grid[position[0]-1][position[1]] != 4 and grid[position[0]-1][position[1]] != 2):
- return 0
- else:
- if (direction == "gauche" and grid[position[0]][position[1] - 1] == 1) or (direction == "droite" and grid[position[0]][position[1] + 1] == 1) or (direction == "bas" and grid[position[0]+1][ position[1]] == 1) or (direction == "haut" and grid[position[0]-1][position[1]] != 1):
- return 1
- elif (direction == "droite" and grid[position[0]][position[1] + 1] == 2) or (direction == "gauche" and grid[position[0]][position[1] - 1] == 2 ) or (direction == "haut" and grid[position[0]-1][position[1]] ==2) or (direction == "bas" and grid[position[0]+1][ position[1]] == 2):
- return 2
- elif (direction == "droite" and grid[position[0]][position[1] + 1] == 4) or (direction == "gauche" and grid[position[0]][position[1] - 1] == 4 ) or (direction == "haut" and grid[position[0]-1][position[1]] ==4) or (direction == "bas" and grid[position[0]+1][ position[1]] == 4):
- return 4
- def choisir_direction_aleatoire1(direction,ft1):
- direction_ftm1 = choisir_direction_aleatoire1()
- nouvelle_position_ftm1 = goTo(direction_ftm1, ft1)
- direction = ["gauche", "droite", "haut", "bas"]
- return random.choice(direction)
- def choisir_direction_aleatoire2(direction,ft2):
- direction_ftm2 = choisir_direction_aleatoire2()
- nouvelle_position_ftm2 = goTo(direction_ftm2, ft2)
- direction = ["gauche", "droite", "haut", "bas"]
- return random.choice(direction)
- def goTo(direction, position):
- nouvelle_position = position.copy()
- 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
- main()
- joueur = input(Style.BRIGHT + Fore.LIGHTBLACK_EX +"Entre ton nom :")
- score = 0
- while (not is_ended):
- print("Partie de :", Style.BRIGHT + Fore.GREEN + joueur)
- print(Style.RESET_ALL)
- affichage(bg)
- command = input("Entrez votre déplacement :\nGauche : 4 ; Droite : 6 ; Haut : 8 ; Bas : 2\n")
- print("score =",score)
- """
- 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
- valide = le_mouvement_est_valide(direction, position, bg)
- if valide == 0:
- 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)
- elif valide == 2 :
- print("Déplacement possible...")
- bg[position[0]][position[1]] = 0
- position = goTo(direction, position)
- bg[position[0]][position[1]] = 3
- score = score + 1
- print("score = ", score)
- elif valide == 1 :
- print("Déplacement impossible... mur")
- elif valide == 4 :
- bg[position[0]][position[1]] = 0
- # position = goTo(direction, position)
- # bg[position[0]][position[1]] = 4
- print(joueur,"a perdu la partie")
- for line in game_over:
- print(Style.BRIGHT + Fore.RED + line)
- print(Style.RESET_ALL)
- fin()
- if score == 3 :
- print(joueur,"a gagné la partie")
- for line in win:
- print(Style.BRIGHT + Fore.YELLOW + line)
- print(Style.RESET_ALL)
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement