def menuStarter(username): starter1 = Pokemon(43) # Starter Mystherbe starter2 = Pokemon(147) # Starter MiniDraco starter3 = Pokemon(60) # Starter Ptitard starterArray = [starter1, starter2, starter3] print("╔══════════════════════════════╗") print("╠═══════ CHOIX STARTER ════════╣") print("╠══════════════════════════════╣") print("║ ║") for i in range(len(starterArray)): print("║" + " " * 4 + str(i + 1) + " - " + starterArray[i].nom + " " * (22 - len(str(starterArray[i].nom))) + "║") print("║ ║") print("╚══════════════════════════════╝\n") pokeChoose = False while not pokeChoose: try: starterChoice = int(input("Quel pokémon voulez vous choisir : ")) if starterChoice > 3 or starterChoice <= 0: raise Exception() else: pokeChoose = True except: print("\nVeuillez choisir un pokémon valide") print("\nSuper ! tu as choisis " + starterArray[starterChoice - 1].nom + " prend en soin !\n") player = Player(username) player.addPokeList(starterArray[starterChoice - 1]) player.addPokedex(starterArray[starterChoice - 1]) return player
def attack(poke_atk: Pokemon, poke_def: Pokemon, comp: Competence): print(poke_atk.nom + " utilise " + comp.name + " sur " + poke_def.nom) degats = poke_atk.getDmg(comp) print("il lui inflige " + str(degats) + " de dégats") if degats >= poke_def.hp: poke_def.hp = 0 else: poke_def.hp -= degats return poke_def.hp == 0
def getRandomPokemonByZone(self): with open(JSON_ZONE_PATH) as jsonFile: data = json.load(jsonFile) nbPokemonZone = len(data["zones"][self.id]["list_pokemon_id"]) rand = random.randrange(nbPokemonZone) randomPoke = data["zones"][self.id]["list_pokemon_id"][rand] pokemon = Pokemon(randomPoke) return pokemon
def getRandomDresseurByZone(self): with open(JSON_ZONE_PATH) as jsonFile: data = json.load(jsonFile) nbDresseurZone = len(data["zones"][self.id]["dresseurs"]) rand = random.randrange(nbDresseurZone) randomDresseur = data["zones"][self.id]["dresseurs"][rand] dresseur = Trainer(randomDresseur["name"]) for poke in randomDresseur["list_pokemon_dresseur"]: dresseur.addPokeEquipe(Pokemon(poke)) return dresseur
def chooseAtk(poke_atk: Pokemon): comp1 = poke_atk.competence[0] comp2 = poke_atk.competence[1] comp3 = poke_atk.competence[2] comp4 = poke_atk.competence[3] comp1_info = "1 - " + comp1.name + " (" + str( poke_atk.getDmg(comp1)) + ") " comp2_info = "2 - " + comp2.name + " (" + str( poke_atk.getDmg(comp2)) + ") " comp3_info = "3 - " + comp3.name + " (" + str( poke_atk.getDmg(comp3)) + ") " comp4_info = "4 - " + comp4.name + " (" + str( poke_atk.getDmg(comp4)) + ") " length = 0 if len(comp1_info + comp2_info) > len(comp3_info + comp4_info): length = len(comp1_info + comp2_info) else: length = len(comp3_info + comp4_info) length += 3 print("╔" + "═" * length + "╗") print("║ " + comp1_info + "║ " + comp2_info + "║") print("╠" + "═" * length + "╣") print("║ " + comp3_info + "║ " + comp4_info + "║") print("╠" + "═" * length + "╣") print("║ 0- Retour" + " " * (length - 11) + "║") print("╚" + "═" * length + "╝\n") opt = -1 opt_correct = False while not opt_correct: try: opt = int(input("Choisir une attaque : ")) if opt > 4 or opt < 0: raise Exception() else: opt_correct = True except: print("Veuillez choisir une attaque valide") return opt
def loadPlayer(): with open("./json/user.json") as json_file: data = json.load(json_file) player = Player(data["username"]) pokelist = data["poke_list"] # list d'id des pokemons du player pokedex = data["pokedex"] # list d'id du pokedex inventaire = data['item_list'] for pokemon in pokelist: poke_add = Pokemon(pokemon['id']) poke_add.addLevel(pokemon['level']) poke_add.xp = pokemon['xp'] poke_add.evolution = pokemon['evolution'] poke_add.hp = pokemon['hp'] player.addPokeList(poke_add) for poke_id in pokedex: poke_add = Pokemon(poke_id, False) player.addPokedex(poke_add) for item in inventaire: player.addInventaire(Item(item)) print("Bonjour", player.username) return player
def menuInventaireCombat(player: Player, pokemon: Pokemon, adversaire: Pokemon, use_pokeball=True): captured = False print("\n╔══════════════════════════════╗") print("╠═════════ INVENTAIRE ═════════╣") print("╠══════════════════════════════╣") print("║ ║") i = 0 for item in player.getInventaire(): print("║ " + str(i + 1) + " - " + item.name + " ") i += 1 print("║ ║") print("║ 1 - Utiliser un objet ║") print("║ 2 - Quitter ║") print("║ ║") print("╚══════════════════════════════╝\n") # L'utilisateur fait un choix choose = False while not choose: try: inputChoice = int(input("Votre choix: ")) if inputChoice == 1 or inputChoice == 2: choose = True else: raise Exception() except: print("Veuillez faire un choix valide") if inputChoice == 1: # L'utilisateur choisi quel item utiliser chooseItem = False while not chooseItem: try: chooseItemId = int(input("Veuillez choisir un item : ")) except: print("La saisie n'est pas valide !") chooseItemId = -1 # Si l'item est bien dans l'inventaire if player.existInventaire(chooseItemId): chooseItem = True inventaire = player.getInventaire() item = player.item_list[chooseItemId - 1] # Si l'item est de type pokeball if item.type == 1 and not use_pokeball: print( "Vous ne pouvez pas capturer les pokémons de votre adversaire !" ) return False if item.type == 1: rnd = random.randint(0, 100) # Test si la capture du pokémon est efficace if rnd <= item.effect: # Réussite print("Votre " + item.name + " est très éfficace !") print("Vous venez de capturer " + adversaire.nom) player.addPokeList(adversaire) captured = True else: # Echec print("Votre " + item.name + " n'est très pas éfficace...") # Passe le tour du joueur en cours # Si l'item est de type potion elif item.type == 2: print("Vous utilisez " + item.name + "...") oldhp = pokemon.hp if (pokemon.hp + item.effect) >= 100: pokemon.hp = 100 else: pokemon.heal(item.effect) print("Votre pokémon vient de gagné " + str(pokemon.hp - oldhp) + "hp grâce à " + item.name) # On retire 1 à la quantité de l'item utilisé player.useInventaire(chooseItemId - 1) if captured: return "captured" else: print("Erreur ! L'item demandé n'existe pas !")