Browse Source

sql inventaire marche

master
Kalyax 2 years ago
parent
commit
c482a38ce8
  1. 16
      game/personnage.py
  2. 10
      graphics/layers.py
  3. BIN
      jeu.db

16
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))

10
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):

BIN
jeu.db

Binary file not shown.
Loading…
Cancel
Save