Added chests, they are immortal and contain objects the player can take for free.

This commit is contained in:
eichhornchen
2021-01-08 23:15:48 +01:00
parent 175706b1e4
commit bdbf214d8d
9 changed files with 178 additions and 13 deletions

View File

@ -10,7 +10,8 @@ from squirrelbattle.display.mapdisplay import MapDisplay
from squirrelbattle.display.messagedisplay import MessageDisplay
from squirrelbattle.display.statsdisplay import StatsDisplay
from squirrelbattle.display.menudisplay import MainMenuDisplay, \
PlayerInventoryDisplay, StoreInventoryDisplay, SettingsMenuDisplay
PlayerInventoryDisplay, StoreInventoryDisplay, SettingsMenuDisplay, \
ChestInventoryDisplay
from squirrelbattle.display.logsdisplay import LogsDisplay
from squirrelbattle.display.texturepack import TexturePack
from typing import Any, List
@ -29,6 +30,7 @@ class DisplayManager:
self.logsdisplay = LogsDisplay(screen, pack)
self.playerinventorydisplay = PlayerInventoryDisplay(screen, pack)
self.storeinventorydisplay = StoreInventoryDisplay(screen, pack)
self.chestinventorydisplay = ChestInventoryDisplay(screen, pack)
self.mainmenudisplay = MainMenuDisplay(self.game.main_menu,
screen, pack)
self.settingsmenudisplay = SettingsMenuDisplay(screen, pack)
@ -40,7 +42,8 @@ class DisplayManager:
self.mainmenudisplay, self.settingsmenudisplay,
self.logsdisplay, self.messagedisplay,
self.playerinventorydisplay,
self.storeinventorydisplay, self.creditsdisplay]
self.storeinventorydisplay, self.creditsdisplay,
self.chestinventorydisplay]
self.update_game_components()
def handle_display_action(self, action: DisplayActions, *params) -> None:
@ -87,7 +90,8 @@ class DisplayManager:
if self.game.state == GameMode.PLAY \
or self.game.state == GameMode.INVENTORY \
or self.game.state == GameMode.STORE:
or self.game.state == GameMode.STORE\
or self.game.state == GameMode.CHEST:
# The map pad has already the good size
self.mapdisplay.refresh(0, 0, self.rows * 4 // 5,
self.mapdisplay.pack.tile_width
@ -124,6 +128,19 @@ class DisplayManager:
pack.tile_width * (2 * self.cols // (5 * pack.tile_width)))
displays.append(self.storeinventorydisplay)
displays.append(self.playerinventorydisplay)
elif self.game.state == GameMode.CHEST:
self.chestinventorydisplay.refresh(
self.rows // 10,
pack.tile_width * (self.cols // (2 * pack.tile_width)),
8 * self.rows // 10,
pack.tile_width * (2 * self.cols // (5 * pack.tile_width)))
self.playerinventorydisplay.refresh(
self.rows // 10,
pack.tile_width * (self.cols // (10 * pack.tile_width)),
8 * self.rows // 10,
pack.tile_width * (2 * self.cols // (5 * pack.tile_width)))
displays.append(self.chestinventorydisplay)
displays.append(self.playerinventorydisplay)
elif self.game.state == GameMode.MAINMENU:
self.mainmenudisplay.refresh(0, 0, self.rows, self.cols)
displays.append(self.mainmenudisplay)

View File

@ -5,7 +5,8 @@ import curses
from random import randint
from typing import List
from squirrelbattle.menus import Menu, MainMenu, SettingsMenu, StoreMenu
from squirrelbattle.menus import Menu, MainMenu, SettingsMenu, StoreMenu,\
ChestMenu
from .display import Box, Display
from ..entities.player import Player
from ..enums import KeyValues, GameMode
@ -156,13 +157,16 @@ class PlayerInventoryDisplay(MenuDisplay):
player: Player = None
selected: bool = True
store_mode: bool = False
chest_mode: bool = False
def update(self, game: Game) -> None:
self.player = game.player
self.update_menu(game.inventory_menu)
self.store_mode = game.state == GameMode.STORE
self.chest_mode = game.state == GameMode.CHEST
self.selected = game.state == GameMode.INVENTORY \
or (self.store_mode and not game.is_in_store_menu)
or (self.store_mode and not game.is_in_store_menu)\
or (self.chest_mode and not game.is_in_chest_menu)
def update_pad(self) -> None:
self.menubox.update_title(_("INVENTORY"))
@ -239,3 +243,39 @@ class StoreInventoryDisplay(MenuDisplay):
self.menu.position = max(0, min(len(self.menu.values) - 1, y - 2))
game.is_in_store_menu = True
game.handle_key_pressed(KeyValues.ENTER)
class ChestInventoryDisplay(MenuDisplay):
"""
A class to handle the display of a merchant's inventory.
"""
menu: ChestMenu
selected: bool = False
def update(self, game: Game) -> None:
self.update_menu(game.chest_menu)
self.selected = game.is_in_chest_menu
def update_pad(self) -> None:
self.menubox.update_title(_("CHEST"))
for i, item in enumerate(self.menu.values):
rep = self.pack[item.name.upper()]
selection = f"[{rep}]" if i == self.menu.position \
and self.selected else f" {rep} "
self.addstr(self.pad, i + 1, 0, selection
+ " " + item.translated_name.capitalize())
@property
def truewidth(self) -> int:
return max(1, self.height if hasattr(self, "height") else 10)
@property
def trueheight(self) -> int:
return 2 + super().trueheight
def handle_click(self, y: int, x: int, game: Game) -> None:
"""
We can select a menu item with the mouse.
"""
self.menu.position = max(0, min(len(self.menu.values) - 1, y - 2))
game.is_in_chest_menu = True
game.handle_key_pressed(KeyValues.ENTER)

View File

@ -22,6 +22,7 @@ class TexturePack:
BODY_SNATCH_POTION: str
BOMB: str
BOW: str
CHEST: str
CHESTPLATE: str
EAGLE: str
EMPTY: str
@ -79,6 +80,7 @@ TexturePack.ASCII_PACK = TexturePack(
BODY_SNATCH_POTION='S',
BOMB='ç',
BOW=')',
CHEST='',
CHESTPLATE='(',
EAGLE='µ',
EMPTY=' ',
@ -119,6 +121,7 @@ TexturePack.SQUIRREL_PACK = TexturePack(
BODY_SNATCH_POTION='🔀',
BOMB='💣',
BOW='🏹',
CHEST='🧰',
CHESTPLATE='🦺',
EAGLE='🦅',
EMPTY=' ',