diff --git a/game/personnage.py b/game/personnage.py index 2e8a165..e378f25 100644 --- a/game/personnage.py +++ b/game/personnage.py @@ -14,7 +14,7 @@ class Material: class Inventaire: def __init__(self, id, item=None): self._id = id - self._slots = [] + self._potions = [] self.append(item) self.append(Material.POTION) @@ -22,17 +22,25 @@ class Inventaire: conn = Connection() conn.db.execute("INSERT INTO inventaire (personnage_id, item_type) VALUES (?, ?);", (self._id, item_type)) conn.commit() - conn.db.execute("SELECT last_insert_rowid();") - self._slots.append(conn.db.fetchone()[0]) + if item_type == "POTION": + conn.db.execute("SELECT last_insert_rowid();") + slot = conn.db.fetchone()[0] + self._potions.append(slot) conn.close() def remove(self, slot): conn = Connection() conn.db.execute("DELETE FROM inventaire WHERE personnage_id=? AND slot=?", (self._id, slot)) conn.commit() - self._id = conn.db.fetchone()[0] conn.close() + def pop_potion(self): + if len(self._potions) == 0: + return None + v = self._potions[0] + del self._potions[0] + return v + def has(self, item_type): conn = Connection() conn.db.execute("SELECT slot FROM inventaire WHERE personnage_id=? AND item_type=?", (self._id, item_type)) diff --git a/graphics/layers.py b/graphics/layers.py index 258e94a..3a781a6 100644 --- a/graphics/layers.py +++ b/graphics/layers.py @@ -71,12 +71,10 @@ class GUI(Layer): self.__buttons = ["Attaquer", "Inventaire"] elif self.__current == 1: perso = Screen.instance.game.personnage - for item in range(len(perso.inventaire)): - if perso.inventaire[item] == "POTION": - perso.change_pdv(-10) - del perso.inventaire[item] - break - + inv = perso.inventaire + if inv.has("POTION"): + perso.change_pdv(-10) + inv.remove(inv.pop_potion()) class StartPopUp(Layer): diff --git a/jeu.db b/jeu.db deleted file mode 100644 index 40e81ab..0000000 Binary files a/jeu.db and /dev/null differ