MEUNIER Marvyn
12 months ago
2 changed files with 362 additions and 0 deletions
@ -0,0 +1,181 @@ |
|||
import random |
|||
import sqlite3 |
|||
|
|||
|
|||
class Personnage: |
|||
|
|||
def __init__(self, nom, cat): |
|||
|
|||
self.nom = nom |
|||
|
|||
self.pdv = 20 |
|||
|
|||
self.exp = 1 |
|||
|
|||
self.cat = cat |
|||
|
|||
self.inventaire = [] |
|||
|
|||
|
|||
|
|||
if cat == 'combattant': |
|||
|
|||
self.inventaire = ['épée', 'potion'] |
|||
|
|||
elif cat == 'sorcier': |
|||
|
|||
self.inventaire = ['bâton', 'potion'] |
|||
|
|||
elif cat == 'voleur': |
|||
|
|||
self.inventaire = ['dague', 'potion'] |
|||
|
|||
elif cat == 'elfe': |
|||
|
|||
self.inventaire = ['arc', 'potion'] |
|||
|
|||
|
|||
|
|||
def jet_attaque(self): |
|||
|
|||
de_a_20_faces = random.randint(1, 20) |
|||
|
|||
coefficient_classe = 10 if self.cat in ['combattant', 'sorcier'] else 3 if self.cat == 'voleur' else 8 |
|||
|
|||
return de_a_20_faces + self.exp * coefficient_classe |
|||
|
|||
|
|||
|
|||
def jet_defense(self): |
|||
|
|||
de_a_20_faces = random.randint(1, 20) |
|||
|
|||
coefficient_classe = 8 if self.cat == 'combattant' else 7 if self.cat == 'sorcier' else 9 if self.cat == 'voleur' else 10 |
|||
|
|||
return de_a_20_faces + self.exp * coefficient_classe |
|||
|
|||
|
|||
|
|||
def change_pdv(self, nb_pdv): |
|||
|
|||
self.pdv += nb_pdv |
|||
|
|||
|
|||
|
|||
def change_exp(self, nb_exp): |
|||
|
|||
if nb_exp > 0: |
|||
|
|||
self.exp += nb_exp |
|||
|
|||
|
|||
|
|||
def affiche_caracteristiques(self): |
|||
|
|||
print(f"Nom: {self.nom}") |
|||
|
|||
print(f"Catégorie: {self.cat}") |
|||
|
|||
print(f"Points de vie: {self.pdv}") |
|||
|
|||
print(f"Expérience: {self.exp}") |
|||
|
|||
|
|||
|
|||
def affiche_inventaire(self): |
|||
|
|||
print(f"Inventaire de {self.nom}: {', '.join(self.inventaire)}") |
|||
|
|||
|
|||
|
|||
def mettre_a_jour_personnage(conn, personnage): |
|||
|
|||
c = conn.cursor() |
|||
|
|||
c.execute("UPDATE notes SET pdv = ? WHERE personnage = ?", (personnage.pdv, personnage.nom)) |
|||
|
|||
conn.commit() |
|||
|
|||
|
|||
|
|||
# Création de la base de données |
|||
|
|||
conn = sqlite3.connect("perso.db") |
|||
|
|||
c = conn.cursor() |
|||
|
|||
c.execute("CREATE TABLE if not exists notes(personnage TEXT, arme TEXT, heal TEXT, pdv float)") |
|||
|
|||
interros = [("combattant", "épée", "potion", 20), ("sorcier", "bâton", "potion", 20)] |
|||
|
|||
c.executemany("INSERT INTO notes VALUES ( ? , ? , ? , ? )", interros) |
|||
|
|||
c.execute("SELECT*FROM notes") |
|||
|
|||
print(c.fetchall()) |
|||
|
|||
conn.commit() |
|||
|
|||
|
|||
|
|||
# Création des personnages |
|||
|
|||
personnage1 = Personnage("Combattant1", "combattant") |
|||
|
|||
personnage2 = Personnage("Sorcier1", "sorcier") |
|||
|
|||
|
|||
|
|||
while personnage1.pdv > 0 and personnage2.pdv > 0: |
|||
|
|||
attaquant = personnage1 if random.random() < 0.5 else personnage2 |
|||
|
|||
defenseur = personnage2 if attaquant == personnage1 else personnage1 |
|||
|
|||
|
|||
|
|||
print(f"{attaquant.nom} attaque {defenseur.nom}!") |
|||
|
|||
jet_attaque = attaquant.jet_attaque() |
|||
|
|||
jet_defense = defenseur.jet_defense() |
|||
|
|||
|
|||
|
|||
if jet_attaque > jet_defense: |
|||
|
|||
degats = random.randint(1, 8) |
|||
|
|||
defenseur.change_pdv(-degats) |
|||
|
|||
print(f"{defenseur.nom} perd {degats} points de vie.") |
|||
|
|||
else: |
|||
|
|||
degats = random.randint(1, 4) |
|||
|
|||
attaquant.change_pdv(-degats) |
|||
|
|||
print(f"{attaquant.nom} perd {degats} points de vie.") |
|||
|
|||
|
|||
|
|||
personnage1.affiche_caracteristiques() |
|||
|
|||
personnage2.affiche_caracteristiques() |
|||
|
|||
|
|||
|
|||
mettre_a_jour_personnage(conn, personnage1) |
|||
|
|||
mettre_a_jour_personnage(conn, personnage2) |
|||
|
|||
|
|||
|
|||
print() |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
conn.close() |
@ -0,0 +1,181 @@ |
|||
import random |
|||
import sqlite3 |
|||
|
|||
|
|||
class Personnage: |
|||
|
|||
def __init__(self, nom, cat): |
|||
|
|||
self.nom = nom |
|||
|
|||
self.pdv = 20 |
|||
|
|||
self.exp = 1 |
|||
|
|||
self.cat = cat |
|||
|
|||
self.inventaire = [] |
|||
|
|||
|
|||
|
|||
if cat == 'combattant': |
|||
|
|||
self.inventaire = ['épée', 'potion'] |
|||
|
|||
elif cat == 'sorcier': |
|||
|
|||
self.inventaire = ['bâton', 'potion'] |
|||
|
|||
elif cat == 'voleur': |
|||
|
|||
self.inventaire = ['dague', 'potion'] |
|||
|
|||
elif cat == 'elfe': |
|||
|
|||
self.inventaire = ['arc', 'potion'] |
|||
|
|||
|
|||
|
|||
def jet_attaque(self): |
|||
|
|||
de_a_20_faces = random.randint(1, 20) |
|||
|
|||
coefficient_classe = 10 if self.cat in ['combattant', 'sorcier'] else 3 if self.cat == 'voleur' else 8 |
|||
|
|||
return de_a_20_faces + self.exp * coefficient_classe |
|||
|
|||
|
|||
|
|||
def jet_defense(self): |
|||
|
|||
de_a_20_faces = random.randint(1, 20) |
|||
|
|||
coefficient_classe = 8 if self.cat == 'combattant' else 7 if self.cat == 'sorcier' else 9 if self.cat == 'voleur' else 10 |
|||
|
|||
return de_a_20_faces + self.exp * coefficient_classe |
|||
|
|||
|
|||
|
|||
def change_pdv(self, nb_pdv): |
|||
|
|||
self.pdv += nb_pdv |
|||
|
|||
|
|||
|
|||
def change_exp(self, nb_exp): |
|||
|
|||
if nb_exp > 0: |
|||
|
|||
self.exp += nb_exp |
|||
|
|||
|
|||
|
|||
def affiche_caracteristiques(self): |
|||
|
|||
print(f"Nom: {self.nom}") |
|||
|
|||
print(f"Catégorie: {self.cat}") |
|||
|
|||
print(f"Points de vie: {self.pdv}") |
|||
|
|||
print(f"Expérience: {self.exp}") |
|||
|
|||
|
|||
|
|||
def affiche_inventaire(self): |
|||
|
|||
print(f"Inventaire de {self.nom}: {', '.join(self.inventaire)}") |
|||
|
|||
|
|||
|
|||
def mettre_a_jour_personnage(conn, personnage): |
|||
|
|||
c = conn.cursor() |
|||
|
|||
c.execute("UPDATE notes SET pdv = ? WHERE personnage = ?", (personnage.pdv, personnage.nom)) |
|||
|
|||
conn.commit() |
|||
|
|||
|
|||
|
|||
# Création de la base de données |
|||
|
|||
conn = sqlite3.connect("perso.db") |
|||
|
|||
c = conn.cursor() |
|||
|
|||
c.execute("CREATE TABLE if not exists notes(personnage TEXT, arme TEXT, heal TEXT, pdv float)") |
|||
|
|||
interros = [("combattant", "épée", "potion", 20), ("sorcier", "bâton", "potion", 20)] |
|||
|
|||
c.executemany("INSERT INTO notes VALUES ( ? , ? , ? , ? )", interros) |
|||
|
|||
c.execute("SELECT*FROM notes") |
|||
|
|||
print(c.fetchall()) |
|||
|
|||
conn.commit() |
|||
|
|||
|
|||
|
|||
# Création des personnages |
|||
|
|||
personnage1 = Personnage("Combattant1", "combattant") |
|||
|
|||
personnage2 = Personnage("Sorcier1", "sorcier") |
|||
|
|||
|
|||
|
|||
while personnage1.pdv > 0 and personnage2.pdv > 0: |
|||
|
|||
attaquant = personnage1 if random.random() < 0.5 else personnage2 |
|||
|
|||
defenseur = personnage2 if attaquant == personnage1 else personnage1 |
|||
|
|||
|
|||
|
|||
print(f"{attaquant.nom} attaque {defenseur.nom}!") |
|||
|
|||
jet_attaque = attaquant.jet_attaque() |
|||
|
|||
jet_defense = defenseur.jet_defense() |
|||
|
|||
|
|||
|
|||
if jet_attaque > jet_defense: |
|||
|
|||
degats = random.randint(1, 8) |
|||
|
|||
defenseur.change_pdv(-degats) |
|||
|
|||
print(f"{defenseur.nom} perd {degats} points de vie.") |
|||
|
|||
else: |
|||
|
|||
degats = random.randint(1, 4) |
|||
|
|||
attaquant.change_pdv(-degats) |
|||
|
|||
print(f"{attaquant.nom} perd {degats} points de vie.") |
|||
|
|||
|
|||
|
|||
personnage1.affiche_caracteristiques() |
|||
|
|||
personnage2.affiche_caracteristiques() |
|||
|
|||
|
|||
|
|||
mettre_a_jour_personnage(conn, personnage1) |
|||
|
|||
mettre_a_jour_personnage(conn, personnage2) |
|||
|
|||
|
|||
|
|||
print() |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
conn.close() |
Loading…
Reference in new issue