This commit is contained in:
Yohann D'ANELLO 2020-12-07 21:22:06 +01:00
parent b24cc1877f
commit 57fab7db51
8 changed files with 80 additions and 70 deletions

View File

@ -73,15 +73,13 @@ class DisplayManager:
self.hbar.refresh(self.rows * 4 // 5, 0, 1, self.cols * 4 // 5)
self.vbar.refresh(0, self.cols * 4 // 5, self.rows, 1)
if self.game.state == GameMode.INVENTORY:
self.playerinventorydisplay.refresh(self.rows // 10,
self.cols // 2,
8 * self.rows // 10,
2 * self.cols // 5)
self.playerinventorydisplay.refresh(
self.rows // 10, self.cols // 2,
8 * self.rows // 10, 2 * self.cols // 5)
elif self.game.state == GameMode.STORE:
self.storeinventorydisplay.refresh(self.rows // 10,
self.cols // 2,
8 * self.rows // 10,
2 * self.cols // 5)
self.storeinventorydisplay.refresh(
self.rows // 10, self.cols // 2,
8 * self.rows // 10, 2 * self.cols // 5)
elif self.game.state == GameMode.MAINMENU:
self.mainmenudisplay.refresh(0, 0, self.rows, self.cols)
elif self.game.state == GameMode.SETTINGS:

View File

@ -111,9 +111,10 @@ class MainMenuDisplay(Display):
class InventoryDisplay(MenuDisplay):
message: str
def update_pad(self) -> None:
self.addstr(self.pad, 0, (self.width - len(self.message)) // 2, self.message,
curses.A_BOLD | curses.A_ITALIC)
self.addstr(self.pad, 0, (self.width - len(self.message)) // 2,
self.message, curses.A_BOLD | curses.A_ITALIC)
for i, item in enumerate(self.menu.values):
rep = self.pack[item.name.upper()]
selection = f"[{rep}]" if i == self.menu.position else f" {rep} "
@ -128,8 +129,10 @@ class InventoryDisplay(MenuDisplay):
def trueheight(self) -> int:
return 2 + super().trueheight
class PlayerInventoryDisplay(InventoryDisplay):
message = _("== INVENTORY ==")
class StoreInventoryDisplay(InventoryDisplay):
message = _("== STALL ==")

View File

@ -34,6 +34,7 @@ class Merchant(FriendlyEntity) :
# TODO
return _("I don't sell any squirrel")
class Sunflower(FriendlyEntity):
"""
A friendly sunflower
@ -42,5 +43,4 @@ class Sunflower(FriendlyEntity) :
def __init__(self, maxhealth: int = 15,
*args, **kwargs) -> None:
super().__init__(name="sunflower",
maxhealth=maxhealth, *args, **kwargs)
super().__init__(name="sunflower", maxhealth=maxhealth, *args, **kwargs)

View File

@ -148,6 +148,7 @@ class Bomb(Item):
d["damage"] = self.damage
return d
class Weapon(Item):
"""
Non-throwable items that improve player damage
@ -166,6 +167,7 @@ class Weapon(Item):
d["damage"] = self.damage
return d
class Sword(Weapon):
"""
A basic weapon

View File

@ -118,6 +118,9 @@ class Game:
elif key == KeyValues.SPACE:
self.state = GameMode.MAINMENU
elif key == KeyValues.T:
self.handle_friendly_entity_chat()
def handle_friendly_entity_chat(self) -> None:
keykey = self.screen.getkey()
keykey = KeyValues.translate_key(keykey, self.settings)
if keykey == KeyValues.UP:
@ -132,16 +135,18 @@ class Game:
elif keykey == KeyValues.RIGHT:
xp = self.player.x + 1
yp = self.player.y
else:
return
if self.map.entity_is_present(yp, xp):
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:
msg = entity.talk_to(self.player)
self.logs.add_message(msg)
if entity.is_merchant():
self.state = GameMode.STORE
self.store_menu.update_merchant(entity)
def handle_key_pressed_inventory(self, key: KeyValues) -> None:
"""
In the inventory menu, we can interact with items or close the menu.
@ -180,8 +185,7 @@ class Game:
self.player.add_to_inventory(self.store_menu.validate())
# Ensure that the cursor has a good position
self.store_menu.position = min(self.store_menu.position,
len(self.store_menu.values)
- 1)
len(self.store_menu.values) - 1)
def handle_key_pressed_main_menu(self, key: KeyValues) -> None:
"""

View File

@ -84,11 +84,12 @@ class Map:
def entity_is_present(self, y: int, x: int) -> bool:
"""
Indicates that the tile at the coordinates (y, x) contains a killable entity
Indicates that the tile at the coordinates (y, x) contains a killable
entity
"""
return 0 <= y < self.height and 0 <= x < self.width and \
any(entity.x == x and entity.y == y and \
entity.is_friendly() for entity in self.entities)
any(entity.x == x and entity.y == y and entity.is_friendly()
for entity in self.entities)
@staticmethod
def load(filename: str) -> "Map":
@ -349,7 +350,7 @@ class Entity:
from squirrelbattle.entities.monsters import Tiger, Hedgehog, \
Rabbit, TeddyBear
from squirrelbattle.entities.friendly import Merchant, Sunflower
return [BodySnatchPotion, Bomb, Heart, Hedgehog, Rabbit, TeddyBear, \
return [BodySnatchPotion, Bomb, Heart, Hedgehog, Rabbit, TeddyBear,
Sunflower, Tiger, Merchant]
@staticmethod
@ -462,6 +463,7 @@ class FightingEntity(Entity):
d[name] = getattr(self, name)
return d
class FriendlyEntity(FightingEntity):
"""
Friendly entities are living entities which do not attack the player
@ -470,7 +472,8 @@ class FriendlyEntity(FightingEntity):
def talk_to(self, player: Any) -> str:
a = randint(0, len(self.dialogue_option) - 1)
return "The "+self.name+" said : "+self.dialogue_option[a]
return "The " + self.translated_name \
+ " said : " + self.dialogue_option[a]
def keys(self) -> list:
"""

View File

@ -129,6 +129,7 @@ class InventoryMenu(Menu):
def values(self) -> list:
return self.player.inventory
class StoreMenu(Menu):
merchant: Merchant
@ -138,4 +139,3 @@ class StoreMenu(Menu) :
@property
def values(self) -> list:
return self.merchant.inventory