def fightRound(self, myPokemon, opponent): #Méthode qui permet de gérer un tour de combat global_var = getSessionInstance().get() whoStart = random.randint(1, 2) if whoStart == 1: #Le pokemon de l'utilisateur commence effective = self.typeFight(myPokemon.type, opponent.type) if effective == 1: effective = 1.5 elif effective == 0: effective = 1 opponent.hp -= int( (myPokemon.nbGame + int(myPokemon.maxHp / 2)) * (effective)) if opponent.hp <= 0: global_var['userTeam'][ '1'].nbGame += 1 #Quand on gagne le match on itère le nombre de match joué par le pokemon effective = self.typeFight(myPokemon.type, opponent.type) return opponent else: effective = self.typeFight(opponent.type, myPokemon.type) if effective == 1: effective = 1.5 elif effective == 0: effective = 1 myPokemon.hp -= int( (myPokemon.nbGame + int(myPokemon.maxHp / 2)) * (effective)) if myPokemon.hp < 0: global_var['userTeam']['1'].hp = 0 else: global_var['userTeam']['1'].hp -= ( myPokemon.nbGame + int(myPokemon.maxHp / 2)) * (effective) return myPokemon
def changePokemonPos(self): global_var = getSessionInstance().get() for pokemon in global_var['userTeam']: if global_var['userTeam'][pokemon].hp != 0: tampon = global_var['userTeam'][pokemon] global_var['userTeam'][pokemon] = global_var['userTeam']['1'] global_var['userTeam']['1'] = tampon break
def onClick(self, pos): if self.pokemons.origin == 'potion': obj = getObj(self.objs, pos) if obj != None: global_var = getSessionInstance().get() if str(obj[1]) in global_var['userTeam']: #S'il y a un pokemon dans le slot cliqué if global_var['userTeam'][str(obj[1])].hp == 0: #Si le pokemon a bien 0 hp global_var['userTeam'][str(obj[1])].doHeal(100000) #On simule un heal infinie from controller.fight.fightController import FightController self.next_ = FightController() else: obj = getObj(self.objs, pos) if obj != None: global_var = getSessionInstance().get() # nous obtenons la liste des pokémon du joueur pour les afficher if str(obj[1]) in global_var['userTeam']: if global_var['userTeam'][str(obj[1])].hp != 0: tampon = global_var['userTeam']["1"] global_var['userTeam']["1"] = global_var['userTeam'][str(obj[1])] global_var['userTeam'][str(obj[1])] = tampon from controller.fight.fightController import FightController self.next_ = FightController()
def __init__(self): self.objs = [] self.next_ = self self.session = getSessionInstance() self.nextFenetre_ = [Image("ressource/images/VueMenuPvp.jpg", 0, 0)] self.pvpModel = PvpModel() objs = [] # liste des options possibles AI = (Coord(160, 90, 470, 215), 'IA') # contre ordi multi = (Coord(160, 250, 470, 380), 'multi') # en ligne objs.append(AI) objs.append(multi) self.objs = objs
def isGameOver(self): global_var = getSessionInstance().get() if self.hp <= 0: countPokemon = len( global_var['userTeam'] ) #Nombre de pokemon que possède le joueur dans son équipe countPokemonKo = 0 #Gestion du game Over for pokemon in global_var['userTeam']: if global_var['userTeam'][pokemon].hp == 0: countPokemonKo += 1 if countPokemon == countPokemonKo: print("Game Over") else: return False else: return None
def getDatas(self, id): #Récupération des données de l'API global_var = getSessionInstance().get() url = 'https://pokeapi.co/api/v2/pokemon/' + str(id) data = getJSON(url) sprite = data['sprites']['front_default'] name = data['name'] hp = data['stats'][5]['base_stat'] hpMax = data['stats'][5]['base_stat'] pokemonType = data['types'] opponent = Pokemon(name=name, image=sprite, hp=hp, maxHp=hpMax, pokemonType=pokemonType) opponent.setPokemonHp(global_var['userTeam']['1'].nbGame) return opponent
def getMyPokemon(self): global_var = getSessionInstance().get() #Je prends le premier pokemon qui n'est pas KO found = False slot = 1 myPokemon = None try: while found != True: if global_var['userTeam'][str(slot)].hp != 0: myPokemon = self.getDatas( global_var['userTeam'][str(slot)].name) myPokemon.name = global_var['userTeam'][str(slot)].name myPokemon.hp = global_var['userTeam'][str( slot)].hp + global_var['userTeam'][str(slot)].nbGame myPokemon.maxHp = global_var['userTeam'][str( slot)].maxHp + global_var['userTeam'][str(slot)].nbGame myPokemon.image = global_var['userTeam'][str(slot)].image found = True slot += 1 except: pass return myPokemon
def __init__(self): self.pokemons = [] self.origin = 'menu' # permet de savoir si on vient du menu ou d'un combat global_var = getSessionInstance().get() for pokemon in global_var['userTeam']: self.pokemons.append(global_var['userTeam'][pokemon])
def __init__(self): #Je génère un pokemon aléatoirement pour l'utilisateur au début du jeu firstPokemon = self.getMyFirstPokemon() global_var = getSessionInstance().get() global_var['userTeam'] = {"1": firstPokemon}
def updatePokemon(self): global_var = getSessionInstance().get() for pokemon in global_var['userTeam']: if pokemon == str(self.id): global_var['userTeam'][pokemon] = self
def __init__(self, fenetre=None): self.fenetre = fenetre self.events = [] self.eventManager = EventManager(fenetre, self) self.continuer = 1 # condition de la boucle principale self.session_var = getSessionInstance()