|
@ -1,7 +1,7 @@ |
|
|
from random import randint |
|
|
from random import randint |
|
|
from graphics.layers import Sprite |
|
|
from graphics.layers import Sprite |
|
|
|
|
|
|
|
|
import util.sqlite as sqlite |
|
|
from util.sqlite import Connection |
|
|
|
|
|
|
|
|
class Material: |
|
|
class Material: |
|
|
POTION = "POTION" |
|
|
POTION = "POTION" |
|
@ -10,38 +10,59 @@ class Material: |
|
|
DAGUE = "DAGUE" |
|
|
DAGUE = "DAGUE" |
|
|
ARC = "ARC" |
|
|
ARC = "ARC" |
|
|
|
|
|
|
|
|
|
|
|
#TODO: inventaire mysql |
|
|
|
|
|
class Inventaire: |
|
|
|
|
|
def __init__(self, id, item): |
|
|
|
|
|
self._id = id |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def append(self, item): |
|
|
|
|
|
conn = Connection() |
|
|
|
|
|
conn.db.execute("INSERT INTO inventaire (personnage_id, nom) VALUES (?, ?);", (self._id, item)) |
|
|
|
|
|
conn.db.execute("SELECT last_insert_rowid();") |
|
|
|
|
|
self._id = conn.db.fetchone()[0] |
|
|
|
|
|
conn.close() |
|
|
|
|
|
|
|
|
class Personnage: |
|
|
class Personnage: |
|
|
def __init__(self, nom, cat, personnage_type): |
|
|
def __init__(self, nom, cat, personnage_type): |
|
|
#self.nom = nom |
|
|
|
|
|
#self.__pdv = 20 |
|
|
|
|
|
#self.__exp = 1 |
|
|
|
|
|
#self.cat = cat |
|
|
|
|
|
expcoef = None |
|
|
expcoef = None |
|
|
|
|
|
item = None |
|
|
if cat == "Guerrier": |
|
|
if cat == "Guerrier": |
|
|
#self.inventaire = [Material.EPEE, Material.POTION] |
|
|
item = Material.EPEE |
|
|
expcoef = 10 |
|
|
expcoef = 10 |
|
|
elif cat == "Magicien": |
|
|
elif cat == "Magicien": |
|
|
#self.inventaire = [Material.BATON, Material.POTION] |
|
|
item = Material.BATON |
|
|
expcoef = 10 |
|
|
expcoef = 10 |
|
|
elif cat == "Voleur": |
|
|
elif cat == "Voleur": |
|
|
#self.inventaire = [Material.DAGUE, Material.POTION] |
|
|
item = Material.DAGUE |
|
|
expcoef = 3 |
|
|
expcoef = 3 |
|
|
elif cat == "Elfe": |
|
|
elif cat == "Elfe": |
|
|
#self.inventaire = [Material.ARC, Material.POTION] |
|
|
item = Material.ARC |
|
|
expcoef = 8 |
|
|
expcoef = 8 |
|
|
|
|
|
|
|
|
sqlite.db.execute( |
|
|
conn = Connection() |
|
|
"""INSERT INTO personnages (nom, pdv, exp, cat, expcoef) VALUES (?, ?, ?, ?, ?);""", |
|
|
conn.db.execute(f"INSERT INTO personnages (nom, pdv, exp, cat, expcoef) VALUES (?,?,?,?,?);", (nom, 20, 1, cat, expcoef)) |
|
|
(nom, 20, 1, cat, expcoef) |
|
|
conn.commit() |
|
|
) |
|
|
conn.db.execute("SELECT last_insert_rowid();") |
|
|
sqlite.db.execute("SELECT last_insert_rowid();") |
|
|
self._id = conn.db.fetchone()[0] |
|
|
self._id = sqlite.db.fetchone()[0] |
|
|
conn.close() |
|
|
|
|
|
|
|
|
|
|
|
self.inventaire = Inventaire(self._id, item) |
|
|
Sprite(3, cat, personnage_type) |
|
|
Sprite(3, cat, personnage_type) |
|
|
|
|
|
|
|
|
|
|
|
def db_erase(self): |
|
|
|
|
|
conn = Connection() |
|
|
|
|
|
conn.db.execute("DELETE FROM personnages WHERE id=?;", (self._id,)) |
|
|
|
|
|
conn.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __select_value(self, value): |
|
|
def __select_value(self, value): |
|
|
sqlite.db.execute("SELECT ? FROM personnages WHERE id=?", (value, self._id)) |
|
|
conn = Connection() |
|
|
return sqlite.db.fetchone() |
|
|
conn.db.execute("SELECT "+value+" FROM personnages WHERE id=?;", (self._id,)) |
|
|
|
|
|
value = conn.db.fetchone() |
|
|
|
|
|
conn.close() |
|
|
|
|
|
return value[0] if value is not None else None |
|
|
|
|
|
|
|
|
def get_nom(self): |
|
|
def get_nom(self): |
|
|
return self.__select_value("nom") |
|
|
return self.__select_value("nom") |
|
@ -55,27 +76,41 @@ class Personnage: |
|
|
return self.__select_value("expcoef") |
|
|
return self.__select_value("expcoef") |
|
|
|
|
|
|
|
|
def set_nom(self, v): |
|
|
def set_nom(self, v): |
|
|
Connection.db.execute(f"UPDATE personnages SET nom=? WHERE id={self.id}", v) |
|
|
conn = Connection() |
|
|
|
|
|
conn.db.execute("UPDATE personnages SET nom=? WHERE id=?;", (v, self._id)) |
|
|
|
|
|
conn.close() |
|
|
|
|
|
|
|
|
def change_pdv(self, 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}") |
|
|
conn = Connection() |
|
|
|
|
|
conn.db.execute("UPDATE personnages SET pdv = CASE WHEN pdv - ? <= 0 THEN 0 ELSE pdv - ? END WHERE id=?;", (v, v, self._id)) |
|
|
|
|
|
conn.close() |
|
|
|
|
|
|
|
|
def change_exp(self, v): |
|
|
def change_exp(self, v): |
|
|
|
|
|
conn = Connection() |
|
|
if v > 0: |
|
|
if v > 0: |
|
|
Connection.db.execute(f"UPDATE personnages SET exp=exp+? WHERE id={self.id}", v) |
|
|
conn.db.execute("UPDATE personnages SET exp=exp+? WHERE id=?;", (v, self._id)) |
|
|
else: |
|
|
else: |
|
|
raise ValueError("v attends un nombre positif") |
|
|
raise ValueError("v attends un nombre positif") |
|
|
|
|
|
conn.close() |
|
|
|
|
|
|
|
|
def set_cat(self, v): |
|
|
def set_cat(self, v): |
|
|
Connection.db.execute(f"UPDATE personnages SET cat=? WHERE id={self.id}", v) |
|
|
conn = Connection() |
|
|
|
|
|
conn.db.execute("UPDATE personnages SET cat=? WHERE id=?;", (v, self._id)) |
|
|
|
|
|
conn.close() |
|
|
|
|
|
|
|
|
def set_expcoef(self, v): |
|
|
def set_expcoef(self, v): |
|
|
Connection.db.execute(f"UPDATE personnages SET expcoef=? WHERE id={self.id}", v) |
|
|
conn = Connection() |
|
|
|
|
|
conn.db.execute("UPDATE personnages SET expcoef=? WHERE id=?;", (v, self._id)) |
|
|
|
|
|
conn.close() |
|
|
|
|
|
|
|
|
def jet_attaque(self): |
|
|
def jet_attaque(self): |
|
|
damage = randint(1, 20) |
|
|
damage = randint(1, 20) |
|
|
self.change_exp(self.get_expcoef() * self.get_exp()) |
|
|
self.change_exp(self.get_expcoef()) |
|
|
return damage |
|
|
return damage |
|
|
|
|
|
|
|
|
def jet_defense(self): |
|
|
def jet_defense(self): |
|
|
damage = randint(1, 20) |
|
|
damage = randint(1, 20) |
|
|
self.change_exp(self.get_expcoef() * self.get_exp()) |
|
|
self.change_exp(self.get_expcoef()) |
|
|
return damage |
|
|
return damage |
|
|
|
|
|
|
|
|
def affiche_caracteristiques(self): |
|
|
def affiche_caracteristiques(self): |
|
@ -87,4 +122,4 @@ class Personnage: |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
def affiche_inventaire(self): |
|
|
def affiche_inventaire(self): |
|
|
return ["- "+item for item in self.inventaire] |
|
|
return ["- "+item for item in self.inventaire] |
|
|