|
|
@ -1,11 +1,7 @@ |
|
|
|
from random import randint |
|
|
|
from graphics.layers import Sprite |
|
|
|
|
|
|
|
class Category: |
|
|
|
def __init__(self, nom, __expcoef, inventaire): |
|
|
|
self.nom = nom |
|
|
|
self.pdv = __expcoef |
|
|
|
self.inventaire = inventaire |
|
|
|
import util.sqlite as sqlite |
|
|
|
|
|
|
|
class Material: |
|
|
|
POTION = "POTION" |
|
|
@ -16,57 +12,78 @@ class Material: |
|
|
|
|
|
|
|
class Personnage: |
|
|
|
def __init__(self, nom, cat, personnage_type): |
|
|
|
self.nom = nom |
|
|
|
self.__pdv = 20 |
|
|
|
self.__exp = 1 |
|
|
|
self.cat = cat |
|
|
|
#self.nom = nom |
|
|
|
#self.__pdv = 20 |
|
|
|
#self.__exp = 1 |
|
|
|
#self.cat = cat |
|
|
|
expcoef = None |
|
|
|
if cat == "Guerrier": |
|
|
|
self.inventaire = [Material.EPEE, Material.POTION] |
|
|
|
self.__expcoef = 10 |
|
|
|
#self.inventaire = [Material.EPEE, Material.POTION] |
|
|
|
expcoef = 10 |
|
|
|
elif cat == "Magicien": |
|
|
|
self.inventaire = [Material.BATON, Material.POTION] |
|
|
|
self.__expcoef = 10 |
|
|
|
#self.inventaire = [Material.BATON, Material.POTION] |
|
|
|
expcoef = 10 |
|
|
|
elif cat == "Voleur": |
|
|
|
self.inventaire = [Material.DAGUE, Material.POTION] |
|
|
|
self.__expcoef = 3 |
|
|
|
#self.inventaire = [Material.DAGUE, Material.POTION] |
|
|
|
expcoef = 3 |
|
|
|
elif cat == "Elfe": |
|
|
|
self.inventaire = [Material.ARC, Material.POTION] |
|
|
|
self.__expcoef = 8 |
|
|
|
#self.inventaire = [Material.ARC, Material.POTION] |
|
|
|
expcoef = 8 |
|
|
|
|
|
|
|
sqlite.db.execute( |
|
|
|
"""INSERT INTO personnages (nom, pdv, exp, cat, expcoef) VALUES (?, ?, ?, ?, ?);""", |
|
|
|
(nom, 20, 1, cat, expcoef) |
|
|
|
) |
|
|
|
sqlite.db.execute("SELECT last_insert_rowid();") |
|
|
|
self._id = sqlite.db.fetchone()[0] |
|
|
|
|
|
|
|
Sprite(3, cat, personnage_type) |
|
|
|
|
|
|
|
def __select_value(self, value): |
|
|
|
sqlite.db.execute("SELECT ? FROM personnages WHERE id=?", (value, self._id)) |
|
|
|
return sqlite.db.fetchone() |
|
|
|
|
|
|
|
def get_nom(self): |
|
|
|
return self.__select_value("nom") |
|
|
|
def get_pdv(self): |
|
|
|
return self.__select_value("pdv") |
|
|
|
def get_exp(self): |
|
|
|
return self.__select_value("exp") |
|
|
|
def get_cat(self): |
|
|
|
return self.__select_value("cat") |
|
|
|
def get_expcoef(self): |
|
|
|
return self.__select_value("expcoef") |
|
|
|
|
|
|
|
def set_nom(self, v): |
|
|
|
Connection.db.execute(f"UPDATE personnages SET nom=? WHERE id={self.id}", v) |
|
|
|
def change_pdv(self, v): |
|
|
|
Connection.db.execute(f"UPDATE personnages SET pdv = CASE WHEN pdv - {v} < 0 THEN 0 ELSE {v} END WHERE id={self.id}") |
|
|
|
def change_exp(self, v): |
|
|
|
if v > 0: |
|
|
|
Connection.db.execute(f"UPDATE personnages SET exp=exp+? WHERE id={self.id}", v) |
|
|
|
else: |
|
|
|
raise ValueError("v attends un nombre positif") |
|
|
|
def set_cat(self, v): |
|
|
|
Connection.db.execute(f"UPDATE personnages SET cat=? WHERE id={self.id}", v) |
|
|
|
def set_expcoef(self, v): |
|
|
|
Connection.db.execute(f"UPDATE personnages SET expcoef=? WHERE id={self.id}", v) |
|
|
|
|
|
|
|
def jet_attaque(self): |
|
|
|
damage = randint(1, 20) |
|
|
|
self.change_exp(self.__expcoef * self.__exp) |
|
|
|
self.change_exp(self.get_expcoef() * self.get_exp()) |
|
|
|
return damage |
|
|
|
|
|
|
|
def jet_defense(self): |
|
|
|
damage = randint(1, 20) |
|
|
|
self.change_exp(self.__expcoef * self.__exp) |
|
|
|
self.change_exp(self.get_expcoef() * self.get_exp()) |
|
|
|
return damage |
|
|
|
|
|
|
|
def get_pdv(self): |
|
|
|
return self.__pdv |
|
|
|
def change_pdv(self, nb_pdv): |
|
|
|
if self.__pdv - nb_pdv < 0: |
|
|
|
self.__pdv = 0 |
|
|
|
else: |
|
|
|
self.__pdv -= nb_pdv |
|
|
|
|
|
|
|
def get_xp(self): |
|
|
|
return self.__exp |
|
|
|
def change_exp(self, nb_exp): |
|
|
|
if nb_exp > 0: |
|
|
|
self.__exp += nb_exp |
|
|
|
else: |
|
|
|
raise ValueError("nb_exp attends un nombre positif") |
|
|
|
|
|
|
|
def affiche_caracteristiques(self): |
|
|
|
return (f"Nom: {self.nom}", |
|
|
|
f"Type de classe: {self.cat}", |
|
|
|
f"Vie: {self.__pdv}", |
|
|
|
f"Expérience: {self.__exp}", |
|
|
|
f"XPCOEF: {self.__expcoef}" |
|
|
|
return (f"Nom: {self.get_nom()}", |
|
|
|
f"Type de classe: {self.get_cat()}", |
|
|
|
f"Vie: {self.get_pdv()}", |
|
|
|
f"Expérience: {self.get_exp()}", |
|
|
|
f"XPCOEF: {self.get_expcoef()}" |
|
|
|
) |
|
|
|
|
|
|
|
def affiche_inventaire(self): |
|
|
|