Browse Source

inv apparance

master
Kalyax 2 years ago
parent
commit
821eb2d4a4
  1. 38
      game/personnage.py
  2. BIN
      jeu.db
  3. 5
      main.py

38
game/personnage.py

@ -12,17 +12,45 @@ class Material:
#TODO: inventaire mysql #TODO: inventaire mysql
class Inventaire: class Inventaire:
def __init__(self, id, item): def __init__(self, id, item=None):
self._id = id self._id = id
self._slots = []
self.append(item)
self.append(Material.POTION)
def append(self, item_type):
def append(self, item):
conn = Connection() conn = Connection()
conn.db.execute("INSERT INTO inventaire (personnage_id, nom) VALUES (?, ?);", (self._id, item)) conn.db.execute("INSERT INTO inventaire (personnage_id, item_type) VALUES (?, ?);", (self._id, item_type))
conn.commit()
conn.db.execute("SELECT last_insert_rowid();") conn.db.execute("SELECT last_insert_rowid();")
self._slots.append(conn.db.fetchone()[0])
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] self._id = conn.db.fetchone()[0]
conn.close() conn.close()
def has(self, item_type):
conn = Connection()
conn.db.execute("SELECT slot FROM inventaire WHERE personnage_id=? AND item_type=?", (self._id, item_type))
conn.commit()
l = len(conn.db.fetchall())
conn.close()
return False if l == 0 else True
def get_items(self):
conn = Connection()
conn.db.execute("SELECT item_type FROM inventaire WHERE personnage_id=?;", (self._id,))
values = conn.db.fetchall()
conn.close()
return values
def __len__(self):
return len(self.get_items())
class Personnage: class Personnage:
def __init__(self, nom, cat, personnage_type): def __init__(self, nom, cat, personnage_type):
expcoef = None expcoef = None
@ -122,4 +150,4 @@ class Personnage:
) )
def affiche_inventaire(self): def affiche_inventaire(self):
return ["- "+item for item in self.inventaire] return ["- "+item[0] for item in self.inventaire.get_items()]

BIN
jeu.db

Binary file not shown.

5
main.py

@ -23,10 +23,11 @@ if __name__ == "__main__":
conn.db.execute( conn.db.execute(
"""CREATE TABLE IF NOT EXISTS inventaire ( """CREATE TABLE IF NOT EXISTS inventaire (
personnage_id INTEGER PRIMARY KEY, personnage_id INTEGER,
slot INTEGER PRIMARY KEY AUTOINCREMENT, slot INTEGER PRIMARY KEY AUTOINCREMENT,
nom VARCHAR(50) NOT NULL, item_type VARCHAR(50) NOT NULL,
FOREIGN KEY (personnage_id) REFERENCES personnages(id) FOREIGN KEY (personnage_id) REFERENCES personnages(id)
UNIQUE (personnage_id, slot)
)""") )""")
conn.close() conn.close()

Loading…
Cancel
Save