fromkandinskyimport*fromionimport*fromtimeimportsleep# ---------------------------------------------------
# Données temporaires (à remplacer par pokemons.py)
# ---------------------------------------------------
pokemons=[{"nom":"Bulbizarre","name":"Bulbasaur","pv":45,"attaque":49,"defense":49,"as":65,"ds":65,"vitesse":45,"desc":"Un Pokémon graine qui utilise la lumière du soleil."},{"nom":"Salamèche","name":"Charmander","pv":39,"attaque":52,"defense":43,"as":60,"ds":50,"vitesse":65,"desc":"Sa queue brûle d'une flamme qui reflète sa santé."},{"nom":"Carapuce","name":"Squirtle","pv":44,"attaque":48,"defense":65,"as":50,"ds":64,"vitesse":43,"desc":"Il se cache dans sa carapace pour se protéger."},]# ---------------------------------------------------
# Variables d'état
# ---------------------------------------------------
index=0mode="liste"# "liste" ou "fiche"
# ---------------------------------------------------
# Affichage de la liste
# ---------------------------------------------------
defaffiche_liste():fill_rect(0,0,320,222,(255,255,255))draw_string("POKEDEX",100,5,(200,0,0),(255,255,255))foriinrange(len(pokemons)):y=40+i*20# Curseur
ifi==index:fill_rect(10,y-2,300,20,(180,200,255))draw_string(pokemons[i]["nom"],20,y,(0,0,0),(255,255,255))# ---------------------------------------------------
# Affichage d'une fiche Pokémon
# ---------------------------------------------------
defaffiche_fiche(p):fill_rect(0,0,320,222,(255,255,255))draw_string(p["nom"],10,10,(0,0,0))draw_string("Nom anglais : "+p["name"],10,40)draw_string("PV : "+str(p["pv"]),10,70)draw_string("Attaque : "+str(p["attaque"]),10,90)draw_string("Défense : "+str(p["defense"]),10,110)draw_string("Att. Spé : "+str(p["as"]),10,130)draw_string("Déf. Spé : "+str(p["ds"]),10,150)draw_string("Vitesse : "+str(p["vitesse"]),10,170)# Description (sur plusieurs lignes)
desc=p["desc"]draw_string(desc[:28],10,190)draw_string(desc[28:56],10,210)# ---------------------------------------------------
# Boucle principale
# ---------------------------------------------------
affiche_liste()whileTrue:sleep(0.1)ifmode=="liste":ifkeydown(KEY_UP)andindex>0:index-=1affiche_liste()ifkeydown(KEY_DOWN)andindex<len(pokemons)-1:index+=1affiche_liste()ifkeydown(KEY_EXE):mode="fiche"affiche_fiche(pokemons[index])elifmode=="fiche":ifkeydown(KEY_BACK):mode="liste"affiche_liste()fromkandinskyimport*fromionimport*fromtimeimportsleepfrompokemonsimport*# on suppose que tu gardes tes fonctions et classes
# ---------------------------------------------------
# Récupération des données depuis pokemons.py
# ---------------------------------------------------
# liste des noms de pokémon
liste_pokemons=recherche_pokemons()# doit renvoyer une liste de noms (str)
ifliste_pokemonsisNone:liste_pokemons=[]# nombre total
nb_pokemons=nombre_pokemons()# état global
index=0# index dans la liste principale
mode="liste"# "liste", "fiche", "evolutions"
curseur_evo=0# index dans la liste d'évolutions
liste_evolutions=[]pokemon_courant=None# ---------------------------------------------------
# Fonctions d'affichage
# ---------------------------------------------------
defefface_ecran():fill_rect(0,0,320,222,(255,255,255))defaffiche_entete(titre):fill_rect(0,0,320,20,(220,0,40))draw_string(titre,5,3,(255,255,255),(220,0,40))defaffiche_pied():txt="Total: "+str(nb_pokemons)draw_string(txt,5,205,(0,0,0),(255,255,255))defaffiche_liste():efface_ecran()affiche_entete("POKEDEX - LISTE")affiche_pied()ifnotliste_pokemons:draw_string("Aucun pokemon dans la base.",10,60,(0,0,0))return# on affiche jusqu'à 8 pokémon à partir de index-3 à index+4
start=max(0,index-3)end=min(len(liste_pokemons),start+8)y=30foriinrange(start,end):nom=liste_pokemons[i]ifi==index:fill_rect(5,y-2,310,18,(180,200,255))draw_string(nom,10,y,(0,0,0))y+=20defaffiche_fiche(p):efface_ecran()affiche_entete("POKEDEX - FICHE")affiche_pied()# Nom + nom anglais
draw_string("Nom : "+p.nom,10,30,(0,0,0))draw_string("Anglais : "+p.name,10,50,(0,0,0))# Stats
draw_string("PV : "+str(p.pv),10,75)draw_string("Att : "+str(p.attaque),10,95)draw_string("Def : "+str(p.defense),10,115)draw_string("Att. Spé : "+str(p.attaque_speciale),10,135)draw_string("Def. Spé : "+str(p.defense_speciale),10,155)draw_string("Vit : "+str(p.vitesse),10,175)# Evolution de
draw_string("Évolution de : "+str(p.evolution_de),10,195)# Types (en texte)
types=recherche_types(p.nom)iftypesisnotNoneandlen(types)>0:txt_types="Types : "+", ".join(types)draw_string(txt_types,10,215,(0,0,0))defaffiche_evolutions():efface_ecran()affiche_entete("POKEDEX - EVOLUTIONS")affiche_pied()ifnotliste_evolutions:draw_string("Ce pokemon n'a pas d'évolution.",10,60,(0,0,0))returndraw_string("Evolutions de : "+pokemon_courant.nom,10,30,(0,0,0))y=60fori,nominenumerate(liste_evolutions):ifi==curseur_evo:fill_rect(5,y-2,310,18,(180,200,255))draw_string(nom,10,y,(0,0,0))y+=20# ---------------------------------------------------
# Logique
# ---------------------------------------------------
defcharger_pokemon_courant():globalpokemon_courantifnotliste_pokemons:pokemon_courant=Nonereturnnom=liste_pokemons[index]pokemon_courant=recherche_attributs_pokemon(nom)defcharger_evolutions():globalliste_evolutions,curseur_evoliste_evolutions=[]curseur_evo=0ifpokemon_courantisNone:returnnom=pokemon_courant.nomliste=recherche_evolutions(nom)iflisteisNone:liste_evolutions=[]else:# on suppose que recherche_evolutions renvoie une liste de noms
liste_evolutions=liste# ---------------------------------------------------
# Initialisation
# ---------------------------------------------------
charger_pokemon_courant()affiche_liste()# ---------------------------------------------------
# Boucle principale
# ---------------------------------------------------
whileTrue:sleep(0.1)# MODE LISTE : navigation dans la liste principale
ifmode=="liste":ifkeydown(KEY_UP)andindex>0:index-=1charger_pokemon_courant()affiche_liste()ifkeydown(KEY_DOWN)andindex<len(liste_pokemons)-1:index+=1charger_pokemon_courant()affiche_liste()# EXE : ouvrir la fiche
ifkeydown(KEY_EXE):ifpokemon_courantisnotNone:affiche_fiche(pokemon_courant)mode="fiche"sleep(0.2)# MODE FICHE : voir les détails, accéder aux évolutions ou revenir
elifmode=="fiche":# BACK : retour à la liste
ifkeydown(KEY_BACK):mode="liste"affiche_liste()sleep(0.2)# RIGHT : voir les évolutions
ifkeydown(KEY_RIGHT):charger_evolutions()mode="evolutions"affiche_evolutions()sleep(0.2)# MODE EVOLUTIONS : parcourir les évolutions et les afficher
elifmode=="evolutions":# BACK : retour à la fiche
ifkeydown(KEY_BACK):mode="fiche"affiche_fiche(pokemon_courant)sleep(0.2)ifliste_evolutions:ifkeydown(KEY_UP)andcurseur_evo>0:curseur_evo-=1affiche_evolutions()sleep(0.1)ifkeydown(KEY_DOWN)andcurseur_evo<len(liste_evolutions)-1:curseur_evo+=1affiche_evolutions()sleep(0.1)# EXE : aller sur l'évolution choisie
ifkeydown(KEY_EXE):nom_evo=liste_evolutions[curseur_evo]# on remplace le pokémon courant par son évolution
ifnom_evoinliste_pokemons:# on se place sur lui dans la liste principale
index=liste_pokemons.index(nom_evo)charger_pokemon_courant()mode="fiche"affiche_fiche(pokemon_courant)sleep(0.2)
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.