pokedex2.py

Created by huriel-mercier

Created on January 16, 2026

9.06 KB


from kandinsky import *
from ion import *
from time import sleep

# ---------------------------------------------------
# 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 = 0
mode = "liste"  # "liste" ou "fiche"

# ---------------------------------------------------
# Affichage de la liste
# ---------------------------------------------------
def affiche_liste():
    fill_rect(0, 0, 320, 222, (255, 255, 255))
    draw_string("POKEDEX", 100, 5, (200, 0, 0), (255, 255, 255))

    for i in range(len(pokemons)):
        y = 40 + i * 20

        # Curseur
        if i == 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
# ---------------------------------------------------
def affiche_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()

while True:
    sleep(0.1)

    if mode == "liste":
        if keydown(KEY_UP) and index > 0:
            index -= 1
            affiche_liste()

        if keydown(KEY_DOWN) and index < len(pokemons) - 1:
            index += 1
            affiche_liste()

        if keydown(KEY_EXE):
            mode = "fiche"
            affiche_fiche(pokemons[index])

    elif mode == "fiche":
        if keydown(KEY_BACK):
            mode = "liste"
            affiche_liste()
    from kandinsky import *
from ion import *
from time import sleep
from pokemons import *  # 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)
if liste_pokemons is None:
    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
# ---------------------------------------------------

def efface_ecran():
    fill_rect(0, 0, 320, 222, (255, 255, 255))

def affiche_entete(titre):
    fill_rect(0, 0, 320, 20, (220, 0, 40))
    draw_string(titre, 5, 3, (255, 255, 255), (220, 0, 40))

def affiche_pied():
    txt = "Total: " + str(nb_pokemons)
    draw_string(txt, 5, 205, (0, 0, 0), (255, 255, 255))

def affiche_liste():
    efface_ecran()
    affiche_entete("POKEDEX - LISTE")
    affiche_pied()

    if not liste_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 = 30
    for i in range(start, end):
        nom = liste_pokemons[i]
        if i == index:
            fill_rect(5, y - 2, 310, 18, (180, 200, 255))
        draw_string(nom, 10, y, (0, 0, 0))
        y += 20

def affiche_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)
    if types is not None and len(types) > 0:
        txt_types = "Types : " + ", ".join(types)
        draw_string(txt_types, 10, 215, (0, 0, 0))

def affiche_evolutions():
    efface_ecran()
    affiche_entete("POKEDEX - EVOLUTIONS")
    affiche_pied()

    if not liste_evolutions:
        draw_string("Ce pokemon n'a pas d'évolution.", 10, 60, (0, 0, 0))
        return

    draw_string("Evolutions de : " + pokemon_courant.nom, 10, 30, (0, 0, 0))

    y = 60
    for i, nom in enumerate(liste_evolutions):
        if i == curseur_evo:
            fill_rect(5, y - 2, 310, 18, (180, 200, 255))
        draw_string(nom, 10, y, (0, 0, 0))
        y += 20

# ---------------------------------------------------
# Logique
# ---------------------------------------------------

def charger_pokemon_courant():
    global pokemon_courant
    if not liste_pokemons:
        pokemon_courant = None
        return
    nom = liste_pokemons[index]
    pokemon_courant = recherche_attributs_pokemon(nom)

def charger_evolutions():
    global liste_evolutions, curseur_evo
    liste_evolutions = []
    curseur_evo = 0
    if pokemon_courant is None:
        return
    nom = pokemon_courant.nom
    liste = recherche_evolutions(nom)
    if liste is None:
        liste_evolutions = []
    else:
        # on suppose que recherche_evolutions renvoie une liste de noms
        liste_evolutions = liste

# ---------------------------------------------------
# Initialisation
# ---------------------------------------------------

charger_pokemon_courant()
affiche_liste()

# ---------------------------------------------------
# Boucle principale
# ---------------------------------------------------

while True:
    sleep(0.1)

    # MODE LISTE : navigation dans la liste principale
    if mode == "liste":
        if keydown(KEY_UP) and index > 0:
            index -= 1
            charger_pokemon_courant()
            affiche_liste()

        if keydown(KEY_DOWN) and index < len(liste_pokemons) - 1:
            index += 1
            charger_pokemon_courant()
            affiche_liste()

        # EXE : ouvrir la fiche
        if keydown(KEY_EXE):
            if pokemon_courant is not None:
                affiche_fiche(pokemon_courant)
                mode = "fiche"
                sleep(0.2)

    # MODE FICHE : voir les détails, accéder aux évolutions ou revenir
    elif mode == "fiche":
        # BACK : retour à la liste
        if keydown(KEY_BACK):
            mode = "liste"
            affiche_liste()
            sleep(0.2)

        # RIGHT : voir les évolutions
        if keydown(KEY_RIGHT):
            charger_evolutions()
            mode = "evolutions"
            affiche_evolutions()
            sleep(0.2)

    # MODE EVOLUTIONS : parcourir les évolutions et les afficher
    elif mode == "evolutions":
        # BACK : retour à la fiche
        if keydown(KEY_BACK):
            mode = "fiche"
            affiche_fiche(pokemon_courant)
            sleep(0.2)

        if liste_evolutions:
            if keydown(KEY_UP) and curseur_evo > 0:
                curseur_evo -= 1
                affiche_evolutions()
                sleep(0.1)

            if keydown(KEY_DOWN) and curseur_evo < len(liste_evolutions) - 1:
                curseur_evo += 1
                affiche_evolutions()
                sleep(0.1)

            # EXE : aller sur l'évolution choisie
            if keydown(KEY_EXE):
                nom_evo = liste_evolutions[curseur_evo]
                # on remplace le pokémon courant par son évolution
                if nom_evo in liste_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:

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.