Merchant inventory is working!

This commit is contained in:
Yohann D'ANELLO 2020-12-07 21:13:55 +01:00
parent 8540a8f354
commit b24cc1877f
6 changed files with 15 additions and 13 deletions

View File

@ -59,7 +59,7 @@ class DisplayManager:
def refresh(self) -> None: def refresh(self) -> None:
if self.game.state == GameMode.PLAY \ if self.game.state == GameMode.PLAY \
or self.game.state == GameMode.INVENTORY \ or self.game.state == GameMode.INVENTORY \
or self.game.state == GameMode.STORE : or self.game.state == GameMode.STORE:
# The map pad has already the good size # The map pad has already the good size
self.mapdisplay.refresh(0, 0, self.rows * 4 // 5, self.mapdisplay.refresh(0, 0, self.rows * 4 // 5,
self.mapdisplay.pack.tile_width self.mapdisplay.pack.tile_width

View File

@ -112,7 +112,7 @@ class MainMenuDisplay(Display):
class InventoryDisplay(MenuDisplay): class InventoryDisplay(MenuDisplay):
message : str message : str
def update_pad(self) -> None: def update_pad(self) -> None:
self.addstr(self.pad, 0, (self.width - len(message)) // 2, message, self.addstr(self.pad, 0, (self.width - len(self.message)) // 2, self.message,
curses.A_BOLD | curses.A_ITALIC) curses.A_BOLD | curses.A_ITALIC)
for i, item in enumerate(self.menu.values): for i, item in enumerate(self.menu.values):
rep = self.pack[item.name.upper()] rep = self.pack[item.name.upper()]

View File

@ -59,6 +59,7 @@ TexturePack.ASCII_PACK = TexturePack(
MERCHANT='M', MERCHANT='M',
SUNFLOWER='I', SUNFLOWER='I',
BODY_SNATCH_POTION='S', BODY_SNATCH_POTION='S',
SWORD='\u2020',
) )
TexturePack.SQUIRREL_PACK = TexturePack( TexturePack.SQUIRREL_PACK = TexturePack(
@ -81,4 +82,5 @@ TexturePack.SQUIRREL_PACK = TexturePack(
MERCHANT='🦜', MERCHANT='🦜',
SUNFLOWER='🌻', SUNFLOWER='🌻',
BODY_SNATCH_POTION='🔀', BODY_SNATCH_POTION='🔀',
SWORD='🗡️',
) )

View File

@ -18,12 +18,12 @@ class Merchant(FriendlyEntity) :
""" """
return ["maxhealth", "health", "inventory", "hazel"] return ["maxhealth", "health", "inventory", "hazel"]
def __init__(self, name : str = "merchant", hazel : int = 75): def __init__(self, name: str = "merchant", inventory: list = None,
super().__init__(name = name) hazel: int = 75, *args, **kwargs):
super().__init__(name=name, *args, **kwargs)
self.inventory = inventory or []
self.hazel = hazel self.hazel = hazel
self.name = name for i in range(5):
self.inventory = []
for i in range(5) :
self.inventory.append(choice(Item.get_all_items())()) self.inventory.append(choice(Item.get_all_items())())
def talk_to(self, player : Player) -> str: def talk_to(self, player : Player) -> str:
@ -32,6 +32,7 @@ class Merchant(FriendlyEntity) :
and allow the player to buy/sell objects and allow the player to buy/sell objects
""" """
# TODO # TODO
return _("I don't sell any squirrel")
class Sunflower(FriendlyEntity) : class Sunflower(FriendlyEntity) :
""" """

View File

@ -60,8 +60,9 @@ class Item(Entity):
d["held"] = self.held d["held"] = self.held
return d return d
@staticmethod
def get_all_items() -> list: def get_all_items() -> list:
return [BodySnatchPotion, Bomb, Heart, Weapon, Sword] return [BodySnatchPotion, Bomb, Heart, Sword]
class Heart(Item): class Heart(Item):

View File

@ -122,18 +122,16 @@ class Game:
keykey = KeyValues.translate_key(keykey, self.settings) keykey = KeyValues.translate_key(keykey, self.settings)
if keykey == KeyValues.UP: if keykey == KeyValues.UP:
xp = self.player.x xp = self.player.x
yp = self.player.y+1 yp = self.player.y-1
elif keykey == KeyValues.DOWN: elif keykey == KeyValues.DOWN:
xp = self.player.x xp = self.player.x
yp = self.player.y-1 yp = self.player.y+1
elif keykey == KeyValues.LEFT: elif keykey == KeyValues.LEFT:
xp = self.player.x-1 xp = self.player.x-1
yp = self.player.y yp = self.player.y
elif keykey == KeyValues.RIGHT: elif keykey == KeyValues.RIGHT:
xp = self.player.x+1 xp = self.player.x+1
yp = self.player.y yp = self.player.y
else :
raise Exception(keykey)
if self.map.entity_is_present(yp, xp) : if self.map.entity_is_present(yp, xp) :
for entity in self.map.entities : for entity in self.map.entities :
if entity.is_friendly() and entity.x == xp and entity.y == yp : if entity.is_friendly() and entity.x == xp and entity.y == yp :