You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.9 KiB
82 lines
2.9 KiB
11 months ago
|
import random
|
||
|
|
||
|
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)}")
|
||
|
|
||
|
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()
|
||
|
print()
|
||
|
|
||
|
gagnant = personnage1 if personnage1.pdv > 0 else personnage2
|
||
|
gagnant.change_exp(1)
|
||
|
print(f"{gagnant.nom} a gagné le combat et reçoit 1 point d'expérience!")
|
||
|
import sqlite3
|
||
|
conn = sqlite3.connect ("exemple.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),("voleur","dague","potion",20),("elfe","arc", "potion", 20 ),]
|
||
|
c.executemany("INSERT INTO notes VALUES ( ? , ? , ? , ? )",interros)
|
||
|
c.execute("SELECT*FROM notes")
|
||
|
print(c.fetchall())
|
||
|
conn.commit()
|
||
|
conn.close()
|