Interface graphique pokemon
Bonjour, bonjour !
(débutant)
Voila j'ai un code python qui permet donc d'avoir une sorte de Battle Pokemon, sauf que ca se passe dans le terminal, et c'est pas ce que je veux. J'aimerais avoir une interface graphique dans laquelle l'utilisateur choisi son pokémon et puis que la bataille commence :!! :)
Problème : je ne sais pas comment faire, et c'est assez urgent (très urgent)
J'avais commencé avec pygame mais j'ai du mal a continuer pour creer une interface graphique
import pygame pygame.init() pygame.display.set_caption("Pokemon fight") #a changer ecran = pygame.display.set_mode((1340,650)) fond = pygame.image.load("Fond.jfif") #fermeture de la fenetre for event in pygame.even.get(): if event.type == pygame.QUIT: running = False pygame.quit() print("Fermeture du jeu") #code
un exemple a proposer ?
Merciiiiiiiiiiiiiiiiiiiiiii
Seb
import random class Pokemon: def __init__(self, name, type1, type2, hp, atk, df, spatk, spdf, spd, move1, move2, move3, move4): self.name = name self.type1 = type1 self.type2 = type2 self.hp = hp self.atk = atk self.df = df self.spatk = spatk self.spdf= spdf self.spd = spd self.move1 = move1 self.move2 = move2 self.move3 = move3 self.move4 = move4 class Move: def __init__(self, name, form, typ, pwr): self.name = name self.form = form self.typ = typ self.pwr = pwr Flamethrower = Move("Flamethrower", "Special", "Fire", 90) Slash = Move("Slash", "Physical", "Normal", 70) Air_Slash = Move("Air Slash", "Special", "Flying", 75) Fire_Fang = Move("Fire Fang", "Physical","Fire", 65) Aqua_Tail = Move("Aqua Tail", "Physical", "Water", 90) Water_Pulse = Move("Water Pulse", "Special", "Water", 60) Bite = Move("Bite", "Physical","Dark", 60) Rapid_Spin = Move("Rapid Spin", "Physical", "Normal", 50) Seed_Bomb = Move("Seed Bomb","Physical","Grass",60) Sludge_Bomb = Move("Sludge Bomb", "Special","Poison", 90) Razor_Leaf = Move("Razor Leaf", "Physical","Grass", 55) Double_Edge = Move("Double Edge","Physical","Normal", 120) Pok1 = Pokemon("Charizard", "Fire", "Flying", 185, 149, 143, 177, 150, 167, Flamethrower, Air_Slash, Fire_Fang, Slash) Pok2 = Pokemon("Blastoise", "Water", None, 186, 148, 167, 150, 172, 143, Water_Pulse, Aqua_Tail, Bite, Rapid_Spin) Pok3 = Pokemon("Venusaur", "Grass", "Poison", 187, 147, 148, 167, 167, 145, Seed_Bomb, Sludge_Bomb, Double_Edge, Razor_Leaf) def PokAttack(pok1, pok2, move): critChance = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5] randDamage = [85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] STABdmg = 1 gamestate = 0 # if gamestate = 1, Pokemon is fainted and game is over if move.typ == pok1.type1: STABdmg = 1.5 elif move.typ == pok1.type2: STABdmg = 1.5 else: pass dmg = move.pwr # changes formula so moves use the correct attack stat if move.form == "Physical" : damage = (((22 * dmg * (pok1.atk / pok2.df)) / 50) + 2) * random.choice (critChance) * (random. choice (randDamage)) * STABdmg else: damage = (((22 * dmg * (pok1.spatk / pok2.spdf)) / 50) + 2) * random.choice (critChance) * (random .choice (randDamage)) * STABdmg if move.typ == "Fire" and pok2.type1 == "Water": # all the type combinations. probably better to use a dictionary or array in the future damage *= 0.5 if move.typ == "Fire" and pok2.type1 == "Grass": damage *= 1.8 if move.typ == "Fire" and pok2.type1 == "Fire": damage *= 0.5 if move.typ == "Grass" and pok2.type1 == "Water": damage *= 1.8 if move.typ == "Grass" and pok2.type1 == "Flying": damage *= 0.5 if move.typ == "Grass" and pok2.type1 == "Grass": damage *= 0.5 if move.typ == "Grass" and pok2.type1 == "Fire": damage *= 0.5 if move.typ == "Water" and pok2.type1 == "Water": damage *= 0.5 if move.typ == "Water" and pok2.type1 == "Grass": damage *= 0.5 if move.typ == "Water" and pok2.type1== "Fire": damage *= 1.8 if move.typ == "Flying" and pok2.type1 == "Grass": damage *= 1.8 damage = round(damage,0) damage = int(damage/100) print(f'{pok1.name} used {move.name}') pok2.hp -= damage print(f"{pok2.name} takes {damage} damage !") if pok2.hp <= 0: gamestate = 1 pok2.hp = 0 print(f'{pok2.name} has {pok2.hp} HP left. \n') return gamestate party = [] pokedex = [Pok1, Pok2, Pok3] print(f'Please choose a Pokemon to use: (1) {Pok1.name} (2) {Pok2.name} (3) {Pok3.name} ') pokemonChoice = int (input ()) if pokemonChoice == 1: party.append (Pok1) print (f"You have chosen {Pok1.name}.") elif pokemonChoice == 2: party.append (Pok2) print(f"You have chosen {Pok2.name}.") elif pokemonChoice == 3: party.append (Pok3) print (f"You have chosen {Pok3.name}.") else: choicelol = random.choice (pokedex) party.append(choicelol) print (f'Invalid input. Random Pokemon chosen... {choicelol.name}.\n') print(f'Please choose a Pokemon to battle against: (1) {Pok1.name} (2) {Pok2.name} (3) {Pok3.name} ') pokemonChoice2 = int (input ()) if pokemonChoice2 == 1: party.append (Pok1) print (f"You have chosen to battle {Pok1.name}.") elif pokemonChoice2 == 2: party.append (Pok2) print(f"You have chosen to battle {Pok2.name}.") elif pokemonChoice2 == 3: party.append (Pok3) print (f"You have chosen to battle {Pok3.name}.") else: choicelol = random.choice (pokedex) party.append(choicelol) print (f'Invalid input. Random Pokemon chosen... {choicelol.name}.\n') gamestate = 0 while gamestate == 0: if party[0].spd >= party [1].spd: print(f"Choose a move: (1) {party[0].move1.name} (2) {party[0].move2.name } (3) {party[0].move3.name} (4) {party[0].move4.name}") moveChoice1 = int(input()) if moveChoice1 == 1: if PokAttack(party[0], party[1], party[0].move1) == 1: gamestate = 1 elif moveChoice1 == 2: if PokAttack(party[0], party [1], party[0].move2) == 1: gamestate = 1 elif moveChoice1 == 3: if PokAttack (party[0], party[1], party [0] .move3) == 1: gamestate = 1 elif moveChoice1 == 4: if PokAttack(party[0], party[1], party[0].move4) == 1: gamestate = 1 if gamestate != 1: randMove = random.randint(1,4) if randMove == 1: if PokAttack (party[1], party[0], party [1] .move1) == 1: gamestate = 2 elif randMove == 2: if PokAttack (party[1], party[0], party [1] .move2) == 1: gamestate = 2 elif randMove == 3: if PokAttack (party[1], party[0], party [1] .move3) == 1: gamestate = 2 elif randMove == 4: if PokAttack (party[1], party[0], party [1] .move4) == 1: gamestate = 2 else: randMove = random.randint(1,4) if randMove == 1: if PokAttack (party[1], party[0], party [1] .move1) == 1: gamestate = 2 elif randMove == 2: if PokAttack (party[1], party[0], party [1] .move2) == 1: gamestate = 2 elif randMove == 3: if PokAttack (party[1], party[0], party [1] .move3) == 1: gamestate = 2 elif randMove == 4: if PokAttack (party[1], party[0], party [1] .move4) == 1: gamestate = 2 if gamestate != 2: print(f"Choose a move: (1) {party[0].move1.name} (2) {party[0].move2.name } (3) {party[0].move3.name} (4) {party[0].move4.name}") moveChoice2 = int(input()) if moveChoice2 == 1: if PokAttack(party[0], party[1], party[0].move1) == 1: gamestate = 1 elif moveChoice2 == 2: if PokAttack(party[0], party [1], party[0].move2) == 1: gamestate = 1 elif moveChoice2 == 3: if PokAttack (party[0], party[1], party [0] .move3) == 1: gamestate = 1 elif moveChoice2 == 4: if PokAttack(party[0], party[1], party[0].move4) == 1: gamestate = 1 if gamestate == 1: print("ta gagné! c fini") elif gamestate == 2: print("t nul! C fini")
Windows / Chrome 109.0.0.0
- Interface graphique pokemon
- Pokemon sur telephone - Guide
- Changer carte graphique - Guide
- Graphique sparkline - Guide
- Graphique camembert excel - Guide
- Common interface 5v only - Forum TV & Vidéo
1 réponse
Bonjour,
Vu où tu en es rendu, je pense que l'idéal serait pour toi de regarder un tutoriel pygame (il y en a plein, par exemple celui-ci) puis tenter de l'adapter à ton cas. Car en l'état le code est trop peu avancé pour identifier un problème précis ou comprendre ce qui te bloque. Il vaut mieux, quand tu poses une question sur un forum, avoir un problème très précis à formuler.
Bonne chance