From 16e21e4ebe15824593a31a5ff0126992683b9298 Mon Sep 17 00:00:00 2001 From: Alexi Forestier Date: Mon, 25 Sep 2023 00:05:40 +0200 Subject: [PATCH 1/3] =?UTF-8?q?petite=20am=C3=A9lioration=20sur=20le=20com?= =?UTF-8?q?mencement=20de=20la=20simulation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jdr.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/jdr.py b/jdr.py index b70e717..2bf9075 100644 --- a/jdr.py +++ b/jdr.py @@ -71,9 +71,13 @@ def combat(Perso1, Perso2): roleDef = Perso2 while Perso1.nombre_pdv() > 0 and Perso2.nombre_pdv() > 0: if roleAtk.jet_attaque() > roleDef.jet_defense(): - roleDef.change_pdv(-randint(1, 8)) + degats1 = -randint(1, 8) + roleDef.change_pdv(degats1) + print(roleAtk.nom, "a infligé", degats1*-1, "de dégats à", roleDef.nom) elif roleAtk.jet_attaque() < roleDef.jet_defense(): - roleAtk.change_pdv(-randint(1, 4)) + degats2 = -randint(1, 4) + roleAtk.change_pdv(degats2) + print(roleDef.nom, "a infligé", degats2*-1, "de dégats à", roleAtk.nom) elif roleAtk.jet_attaque() == roleDef.jet_defense(): roleAtk.change_pdv(-9999999999) roleDef.change_pdv(-9999999999) @@ -91,12 +95,16 @@ def combat(Perso1, Perso2): Perso1.regen_pdv() Perso2.regen_pdv() - -Squeezie = Personnage("Squeezie", choice(["Déesee", "Démon", "Géant", "Fée"])) -TiboInShape = Personnage("TiboInShape", choice(["Déesee", "Démon", "Géant", "Fée"])) +def commencer(nom1, nom2): + Classe1 = input("Bien, veuillez choisir la classe du premier combattant (Choix entre Démon ; Fée ; Déesee ; Géant)") + nom1 = Personnage(nom1, Classe1) + Classe2 = input("Bien, veuillez choisir la classe du second combattant (Choix entre Démon ; Fée ; Déesee ; Géant)") + nom2 = Personnage(nom2, Classe2) + combat(nom1, nom2) + + -# commande utile à copier : -# - combat(Squeezie, TiboInShape) + From 1fe65dfdfc54e8019e4647cedeeb6c51a0c46790 Mon Sep 17 00:00:00 2001 From: FORESTIER Alexi Date: Wed, 27 Sep 2023 11:45:13 +0200 Subject: [PATCH 2/3] correction orthographique --- jdr.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jdr.py b/jdr.py index 89a9ba1..5c80b57 100644 --- a/jdr.py +++ b/jdr.py @@ -18,7 +18,7 @@ class Personnage: self.inventaire = ["épée malveillante", "Potion"] self.coefAtk = 8 self.coefDef = 8 - elif self.cat == "Déesee": + elif self.cat == "Déesse": self.inventaire = ["Bâton miraculeux", "Potion"] self.coefAtk = 7 self.coefDef = 9 @@ -97,15 +97,15 @@ def combat(Perso1, Perso2): <<<<<<< HEAD def commencer(nom1, nom2): - Classe1 = input("Bien, veuillez choisir la classe du premier combattant (Choix entre Démon ; Fée ; Déesee ; Géant)") + Classe1 = input("Bien, veuillez choisir la classe du premier combattant (Choix entre Démon ; Fée ; Déesse ; Géant)") nom1 = Personnage(nom1, Classe1) - Classe2 = input("Bien, veuillez choisir la classe du second combattant (Choix entre Démon ; Fée ; Déesee ; Géant)") + Classe2 = input("Bien, veuillez choisir la classe du second combattant (Choix entre Démon ; Fée ; Déesse ; Géant)") nom2 = Personnage(nom2, Classe2) combat(nom1, nom2) ======= -Squeezie = Personnage("Squeezie", "Déesee") +Squeezie = Personnage("Squeezie", "Déesse") TiboInShape = Personnage("TiboInShape", "Fée") >>>>>>> 7cabaa14cab561789e3df22193b924c4b131dbfa From 4f1d0edabc77636ee4561b9ef78070c60651ad32 Mon Sep 17 00:00:00 2001 From: Alexi Forestier Date: Mon, 27 Nov 2023 18:45:28 +0100 Subject: [PATCH 3/3] =?UTF-8?q?ajout=20base=20de=20donn=C3=A9e=20avec=20in?= =?UTF-8?q?teraction=20au=20jeu=20de=20role?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jdr.py | 77 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 20 deletions(-) diff --git a/jdr.py b/jdr.py index 89a9ba1..277acf2 100644 --- a/jdr.py +++ b/jdr.py @@ -1,4 +1,5 @@ from random import* +import sqlite3 class Personnage: def __init__(self, nom, cat): self.nom = nom @@ -33,6 +34,14 @@ class Personnage: defPoints = randint(1, 20) return defPoints + self.exp*self.coefDef*0.1 + def affiche_coefatk(self): + """renvoie le coef atk du personnage""" + return self.coefAtk + + def affiche_coefdef(self): + """renvoie le coef def du personnage""" + return self.coefDef + def change_pdv(self, nb_pdv): """modifie le nombre de points de vie""" self.pdv = self.pdv + nb_pdv @@ -52,6 +61,14 @@ class Personnage: def affiche_nom(self): """renvoie le nom du personnage""" return self.nom + + def affiche_cat(self): + """renvoie la catégorie du personnage""" + return self.cat + + def affiche_xp(self): + """renvoie l'xp du personnage""" + return self.exp def affiche_caracteristiques(self): """affiche les caractéristiques du personnage (nom, catégorie, pdv, pts d'exp)""" @@ -64,26 +81,51 @@ class Personnage: def affiche_inventaire(self): """affiche le contenu de l'inventaire du personnage""" print("Contenu de l'inventaire de", self.nom, ":",self.inventaire) + + def affiche_inventaireSQL(self): + """affiche le contenu de l'inventaire du personnage (pour SQL)""" + return self.inventaire + + def combat(Perso1, Perso2): """simule un combat jusqu'à ce qu'un personnage n'a plus de points de vie puis donne un point d'expérience au survivant""" + + conn = sqlite3.connect("Personnage.db") + c = conn.cursor() + c.execute('''CREATE TABLE if not exists Personnage(nom VARCHAR(255), catégorie VARCHAR(255), pdv INT, xp INT, ObjetN°1 TEXT, ObjetN°2 TEXT, CoefAtk INT, CoefDef INT)''') + Per1 = (Perso1.affiche_nom(), Perso1.affiche_cat(), Perso1.nombre_pdv(), Perso1.affiche_xp(), Perso1.affiche_inventaireSQL()[0],Perso1.affiche_inventaireSQL()[1], Perso1.affiche_coefatk(), Perso1.affiche_coefdef(),) + c.execute("INSERT INTO Personnage VALUES (?, ?, ?, ?, ?, ?, ?, ?)", Per1) + Per2 = (Perso2.affiche_nom(), Perso2.affiche_cat(), Perso2.nombre_pdv(), Perso2.affiche_xp(), Perso2.affiche_inventaireSQL()[0],Perso2.affiche_inventaireSQL()[1], Perso2.affiche_coefatk(), Perso2.affiche_coefdef(),) + c.execute("INSERT INTO Personnage VALUES (?, ?, ?, ?, ?, ?, ?, ?)", Per2) + c.execute("SELECT * FROM Personnage") + print(c.fetchall()) + conn.commit() + + roleAtk = Perso1 roleDef = Perso2 while Perso1.nombre_pdv() > 0 and Perso2.nombre_pdv() > 0: if roleAtk.jet_attaque() > roleDef.jet_defense(): - degats1 = -randint(1, 8) - roleDef.change_pdv(degats1) - print(roleAtk.nom, "a infligé", degats1*-1, "de dégats à", roleDef.nom) + roleDef.change_pdv(-randint(1, 8)) elif roleAtk.jet_attaque() < roleDef.jet_defense(): - degats2 = -randint(1, 4) - roleAtk.change_pdv(degats2) - print(roleDef.nom, "a infligé", degats2*-1, "de dégats à", roleAtk.nom) + roleAtk.change_pdv(-randint(1, 4)) elif roleAtk.jet_attaque() == roleDef.jet_defense(): roleAtk.change_pdv(-9999999999) roleDef.change_pdv(-9999999999) Perso1.affiche_caracteristiques() Perso2.affiche_caracteristiques() roleAtk, roleDef = roleDef, roleAtk + + Per1 = (Perso1.affiche_nom(), Perso1.affiche_cat(), Perso1.nombre_pdv(), Perso1.affiche_xp(), Perso1.affiche_inventaireSQL()[0],Perso1.affiche_inventaireSQL()[1], Perso1.affiche_coefatk(), Perso1.affiche_coefdef(),) + c.execute("INSERT INTO Personnage VALUES (?, ?, ?, ?, ?, ?, ?, ?)", Per1) + Per2 = (Perso2.affiche_nom(), Perso2.affiche_cat(), Perso2.nombre_pdv(), Perso2.affiche_xp(), Perso2.affiche_inventaireSQL()[0],Perso2.affiche_inventaireSQL()[1], Perso2.affiche_coefatk(), Perso2.affiche_coefdef(),) + c.execute("INSERT INTO Personnage VALUES (?, ?, ?, ?, ?, ?, ?, ?)", Per2) + c.execute("SELECT * FROM Personnage") + print(c.fetchall()) + conn.commit() + + if Perso1.nombre_pdv() > 0: print(Perso2.affiche_nom(), "a succombé, la victoire revient à ",Perso1.affiche_nom(), "qui remporte un point d'expérience !") Perso1.change_exp(1) @@ -94,26 +136,22 @@ def combat(Perso1, Perso2): print("Le jet d'attaque et le jet de défense fuent de force égale ce qui a provoqué par une raison inexpliquable, une onde de choc et a alarmé la Corée du Nord ! Pris de panique, Kim jong-un lance une bombe atomique sur votre position !", Perso1.affiche_nom(), "et", Perso2.affiche_nom(), "ont tous deux succombés ! Match nul mais allez jouer au Loto!") Perso1.regen_pdv() Perso2.regen_pdv() - -<<<<<<< HEAD -def commencer(nom1, nom2): - Classe1 = input("Bien, veuillez choisir la classe du premier combattant (Choix entre Démon ; Fée ; Déesee ; Géant)") - nom1 = Personnage(nom1, Classe1) - Classe2 = input("Bien, veuillez choisir la classe du second combattant (Choix entre Démon ; Fée ; Déesee ; Géant)") - nom2 = Personnage(nom2, Classe2) - combat(nom1, nom2) - -======= + conn.close() + + + + + + Squeezie = Personnage("Squeezie", "Déesee") TiboInShape = Personnage("TiboInShape", "Fée") ->>>>>>> 7cabaa14cab561789e3df22193b924c4b131dbfa - +# commande utile à copier : +# - combat(Squeezie, TiboInShape) - @@ -122,5 +160,4 @@ TiboInShape = Personnage("TiboInShape", "Fée") - \ No newline at end of file