From c482a38ce83a54c16d0ae8625f89691ecb22e0e7 Mon Sep 17 00:00:00 2001 From: Kalyax Date: Mon, 5 Dec 2022 17:23:40 +0100 Subject: [PATCH] sql inventaire marche --- game/personnage.py | 16 ++++++++++++---- graphics/layers.py | 10 ++++------ jeu.db | Bin 20480 -> 0 bytes 3 files changed, 16 insertions(+), 10 deletions(-) delete mode 100644 jeu.db 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 40e81ab13177e4369ec348edf01e0b03b34e7046..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI3O>EO<7{~3zP2wbepM2N}p)EMHl!S(6sAJk;VgxW*w>B*yMd~)G%32piOOukO zh)HOg5SLBthO`SiOmJk<4jiV9BN{s(AsClQXzYN5v~k!0jY->K?}zIo1vCyIq3MYf z{r!CX{rdO12dBxA!;`hPZ7wxi%hk3yE=43+miC#ZBuTgEyN|xtUmkj(tOr!(uH&a2 z-jc@N{8=N*lA?Jea*eEM9`gFrnlXM zyIuXDZr2(o>_)p7Aj^XUp^Lk5+8+XrX-ItwK4o z=asBkny#3o*~!V?-b2%6Yob`72<{-f7H^E52kgElah=qJ47pc%3eCzPi?K@_4?3XnuF+m_1Ae*k;ane96&Kd5!~j zhF9(5Yj$J7-Vl0w&~GSa8r5YxM<=tVUz7dGp&|LqIQQ(jzOF-0k5^Y=!#;L4?^(B~ z(OiCp%~@GI;qE=VZJxY^_Q{oJ=vtsp>;HW_P_Koiz2y3>pV8g$tVS+K5t8@9w{RbB z!j~`ypMU{-$xZSX`J7xPC&@f{o8({Y-ypgp0VIF~kN^@u0!RP}AOR$R1dzZ>Mj(~& zOM|jHC>N`(WAx#>t{2zrR;y;Wf^owyMOmq8callnFQsMGkoVW>b+cG)+pD@&U$O)7 z_!GMI2usS$BDU8xCikUi4~G62Hy!LYb-Q)V_0ViL3!@u7;Bk+s>ap5F&29wspzA@3 z9gn6I?^%Z=rNZ1L)xDCV&APqT^6GxqBa(GJ==_FjQ6FE2+nw?~-ClO>gNNM#YOgD9 zA^e_ONP4-GAs?)^J~WS37n?1y4;uU-dEkZwH{jO|7l$DdKmter2_OL^fCP{L5~BTL_i^r$nWGA@)P-id`G?}Uy*a1 zd6nlQEFW-;fCkBcSSw)#zcZk*0Y4uIv%Jq42(ba5ICGE{`kaEw3VoswUPPa^t`Hc{y_g|izmEdo92oK;M+=1J0 z9j?L^xD1!zBAkbFa2C$MDQH6-7U6xUz$6@mH{eys!7vPf4q^JKz#Vd%TqpmKhvWgd zN3N19^tS_-$VGCVem-#a`P}5_f&`EN5ld`Ml7v zF|Nk0T|#p?uKMVx(49NE#YL8U8fq035`a% z1|kum09^fq2-P&MzHnG*D8#id7!<0iT$MmTsNc`k>+=ci>*MNC6ro