|
@ -1,11 +1,7 @@ |
|
|
from random import randint |
|
|
from random import randint |
|
|
from graphics.layers import Sprite |
|
|
from graphics.layers import Sprite |
|
|
|
|
|
|
|
|
class Category: |
|
|
import util.sqlite as sqlite |
|
|
def __init__(self, nom, __expcoef, inventaire): |
|
|
|
|
|
self.nom = nom |
|
|
|
|
|
self.pdv = __expcoef |
|
|
|
|
|
self.inventaire = inventaire |
|
|
|
|
|
|
|
|
|
|
|
class Material: |
|
|
class Material: |
|
|
POTION = "POTION" |
|
|
POTION = "POTION" |
|
@ -16,57 +12,78 @@ class Material: |
|
|
|
|
|
|
|
|
class Personnage: |
|
|
class Personnage: |
|
|
def __init__(self, nom, cat, personnage_type): |
|
|
def __init__(self, nom, cat, personnage_type): |
|
|
self.nom = nom |
|
|
#self.nom = nom |
|
|
self.__pdv = 20 |
|
|
#self.__pdv = 20 |
|
|
self.__exp = 1 |
|
|
#self.__exp = 1 |
|
|
self.cat = cat |
|
|
#self.cat = cat |
|
|
|
|
|
expcoef = None |
|
|
if cat == "Guerrier": |
|
|
if cat == "Guerrier": |
|
|
self.inventaire = [Material.EPEE, Material.POTION] |
|
|
#self.inventaire = [Material.EPEE, Material.POTION] |
|
|
self.__expcoef = 10 |
|
|
expcoef = 10 |
|
|
elif cat == "Magicien": |
|
|
elif cat == "Magicien": |
|
|
self.inventaire = [Material.BATON, Material.POTION] |
|
|
#self.inventaire = [Material.BATON, Material.POTION] |
|
|
self.__expcoef = 10 |
|
|
expcoef = 10 |
|
|
elif cat == "Voleur": |
|
|
elif cat == "Voleur": |
|
|
self.inventaire = [Material.DAGUE, Material.POTION] |
|
|
#self.inventaire = [Material.DAGUE, Material.POTION] |
|
|
self.__expcoef = 3 |
|
|
expcoef = 3 |
|
|
elif cat == "Elfe": |
|
|
elif cat == "Elfe": |
|
|
self.inventaire = [Material.ARC, Material.POTION] |
|
|
#self.inventaire = [Material.ARC, Material.POTION] |
|
|
self.__expcoef = 8 |
|
|
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) |
|
|
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): |
|
|
def jet_attaque(self): |
|
|
damage = randint(1, 20) |
|
|
damage = randint(1, 20) |
|
|
self.change_exp(self.__expcoef * self.__exp) |
|
|
self.change_exp(self.get_expcoef() * self.get_exp()) |
|
|
return damage |
|
|
return damage |
|
|
|
|
|
|
|
|
def jet_defense(self): |
|
|
def jet_defense(self): |
|
|
damage = randint(1, 20) |
|
|
damage = randint(1, 20) |
|
|
self.change_exp(self.__expcoef * self.__exp) |
|
|
self.change_exp(self.get_expcoef() * self.get_exp()) |
|
|
return damage |
|
|
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): |
|
|
def affiche_caracteristiques(self): |
|
|
return (f"Nom: {self.nom}", |
|
|
return (f"Nom: {self.get_nom()}", |
|
|
f"Type de classe: {self.cat}", |
|
|
f"Type de classe: {self.get_cat()}", |
|
|
f"Vie: {self.__pdv}", |
|
|
f"Vie: {self.get_pdv()}", |
|
|
f"Expérience: {self.__exp}", |
|
|
f"Expérience: {self.get_exp()}", |
|
|
f"XPCOEF: {self.__expcoef}" |
|
|
f"XPCOEF: {self.get_expcoef()}" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
def affiche_inventaire(self): |
|
|
def affiche_inventaire(self): |
|
|