Linting
This commit is contained in:
parent
b24cc1877f
commit
57fab7db51
|
@ -73,15 +73,13 @@ class DisplayManager:
|
||||||
self.hbar.refresh(self.rows * 4 // 5, 0, 1, self.cols * 4 // 5)
|
self.hbar.refresh(self.rows * 4 // 5, 0, 1, self.cols * 4 // 5)
|
||||||
self.vbar.refresh(0, self.cols * 4 // 5, self.rows, 1)
|
self.vbar.refresh(0, self.cols * 4 // 5, self.rows, 1)
|
||||||
if self.game.state == GameMode.INVENTORY:
|
if self.game.state == GameMode.INVENTORY:
|
||||||
self.playerinventorydisplay.refresh(self.rows // 10,
|
self.playerinventorydisplay.refresh(
|
||||||
self.cols // 2,
|
self.rows // 10, self.cols // 2,
|
||||||
8 * self.rows // 10,
|
8 * self.rows // 10, 2 * self.cols // 5)
|
||||||
2 * self.cols // 5)
|
|
||||||
elif self.game.state == GameMode.STORE:
|
elif self.game.state == GameMode.STORE:
|
||||||
self.storeinventorydisplay.refresh(self.rows // 10,
|
self.storeinventorydisplay.refresh(
|
||||||
self.cols // 2,
|
self.rows // 10, self.cols // 2,
|
||||||
8 * self.rows // 10,
|
8 * self.rows // 10, 2 * self.cols // 5)
|
||||||
2 * self.cols // 5)
|
|
||||||
elif self.game.state == GameMode.MAINMENU:
|
elif self.game.state == GameMode.MAINMENU:
|
||||||
self.mainmenudisplay.refresh(0, 0, self.rows, self.cols)
|
self.mainmenudisplay.refresh(0, 0, self.rows, self.cols)
|
||||||
elif self.game.state == GameMode.SETTINGS:
|
elif self.game.state == GameMode.SETTINGS:
|
||||||
|
|
|
@ -111,9 +111,10 @@ 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(self.message)) // 2, self.message,
|
self.addstr(self.pad, 0, (self.width - len(self.message)) // 2,
|
||||||
curses.A_BOLD | curses.A_ITALIC)
|
self.message, 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()]
|
||||||
selection = f"[{rep}]" if i == self.menu.position else f" {rep} "
|
selection = f"[{rep}]" if i == self.menu.position else f" {rep} "
|
||||||
|
@ -128,8 +129,10 @@ class InventoryDisplay(MenuDisplay):
|
||||||
def trueheight(self) -> int:
|
def trueheight(self) -> int:
|
||||||
return 2 + super().trueheight
|
return 2 + super().trueheight
|
||||||
|
|
||||||
|
|
||||||
class PlayerInventoryDisplay(InventoryDisplay):
|
class PlayerInventoryDisplay(InventoryDisplay):
|
||||||
message = _("== INVENTORY ==")
|
message = _("== INVENTORY ==")
|
||||||
|
|
||||||
|
|
||||||
class StoreInventoryDisplay(InventoryDisplay):
|
class StoreInventoryDisplay(InventoryDisplay):
|
||||||
message = _("== STALL ==")
|
message = _("== STALL ==")
|
||||||
|
|
|
@ -34,6 +34,7 @@ class Merchant(FriendlyEntity) :
|
||||||
# TODO
|
# TODO
|
||||||
return _("I don't sell any squirrel")
|
return _("I don't sell any squirrel")
|
||||||
|
|
||||||
|
|
||||||
class Sunflower(FriendlyEntity):
|
class Sunflower(FriendlyEntity):
|
||||||
"""
|
"""
|
||||||
A friendly sunflower
|
A friendly sunflower
|
||||||
|
@ -42,5 +43,4 @@ class Sunflower(FriendlyEntity) :
|
||||||
|
|
||||||
def __init__(self, maxhealth: int = 15,
|
def __init__(self, maxhealth: int = 15,
|
||||||
*args, **kwargs) -> None:
|
*args, **kwargs) -> None:
|
||||||
super().__init__(name="sunflower",
|
super().__init__(name="sunflower", maxhealth=maxhealth, *args, **kwargs)
|
||||||
maxhealth=maxhealth, *args, **kwargs)
|
|
||||||
|
|
|
@ -148,6 +148,7 @@ class Bomb(Item):
|
||||||
d["damage"] = self.damage
|
d["damage"] = self.damage
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
class Weapon(Item):
|
class Weapon(Item):
|
||||||
"""
|
"""
|
||||||
Non-throwable items that improve player damage
|
Non-throwable items that improve player damage
|
||||||
|
@ -166,6 +167,7 @@ class Weapon(Item):
|
||||||
d["damage"] = self.damage
|
d["damage"] = self.damage
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
class Sword(Weapon):
|
class Sword(Weapon):
|
||||||
"""
|
"""
|
||||||
A basic weapon
|
A basic weapon
|
||||||
|
|
|
@ -118,6 +118,9 @@ class Game:
|
||||||
elif key == KeyValues.SPACE:
|
elif key == KeyValues.SPACE:
|
||||||
self.state = GameMode.MAINMENU
|
self.state = GameMode.MAINMENU
|
||||||
elif key == KeyValues.T:
|
elif key == KeyValues.T:
|
||||||
|
self.handle_friendly_entity_chat()
|
||||||
|
|
||||||
|
def handle_friendly_entity_chat(self) -> None:
|
||||||
keykey = self.screen.getkey()
|
keykey = self.screen.getkey()
|
||||||
keykey = KeyValues.translate_key(keykey, self.settings)
|
keykey = KeyValues.translate_key(keykey, self.settings)
|
||||||
if keykey == KeyValues.UP:
|
if keykey == KeyValues.UP:
|
||||||
|
@ -132,16 +135,18 @@ class Game:
|
||||||
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:
|
||||||
|
return
|
||||||
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:
|
||||||
msg = entity.talk_to(self.player)
|
msg = entity.talk_to(self.player)
|
||||||
self.logs.add_message(msg)
|
self.logs.add_message(msg)
|
||||||
if entity.is_merchant():
|
if entity.is_merchant():
|
||||||
self.state = GameMode.STORE
|
self.state = GameMode.STORE
|
||||||
self.store_menu.update_merchant(entity)
|
self.store_menu.update_merchant(entity)
|
||||||
|
|
||||||
|
|
||||||
def handle_key_pressed_inventory(self, key: KeyValues) -> None:
|
def handle_key_pressed_inventory(self, key: KeyValues) -> None:
|
||||||
"""
|
"""
|
||||||
In the inventory menu, we can interact with items or close the menu.
|
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())
|
self.player.add_to_inventory(self.store_menu.validate())
|
||||||
# Ensure that the cursor has a good position
|
# Ensure that the cursor has a good position
|
||||||
self.store_menu.position = min(self.store_menu.position,
|
self.store_menu.position = min(self.store_menu.position,
|
||||||
len(self.store_menu.values)
|
len(self.store_menu.values) - 1)
|
||||||
- 1)
|
|
||||||
|
|
||||||
def handle_key_pressed_main_menu(self, key: KeyValues) -> None:
|
def handle_key_pressed_main_menu(self, key: KeyValues) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -84,11 +84,12 @@ class Map:
|
||||||
|
|
||||||
def entity_is_present(self, y: int, x: int) -> bool:
|
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 \
|
return 0 <= y < self.height and 0 <= x < self.width and \
|
||||||
any(entity.x == x and entity.y == y and \
|
any(entity.x == x and entity.y == y and entity.is_friendly()
|
||||||
entity.is_friendly() for entity in self.entities)
|
for entity in self.entities)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load(filename: str) -> "Map":
|
def load(filename: str) -> "Map":
|
||||||
|
@ -349,7 +350,7 @@ class Entity:
|
||||||
from squirrelbattle.entities.monsters import Tiger, Hedgehog, \
|
from squirrelbattle.entities.monsters import Tiger, Hedgehog, \
|
||||||
Rabbit, TeddyBear
|
Rabbit, TeddyBear
|
||||||
from squirrelbattle.entities.friendly import Merchant, Sunflower
|
from squirrelbattle.entities.friendly import Merchant, Sunflower
|
||||||
return [BodySnatchPotion, Bomb, Heart, Hedgehog, Rabbit, TeddyBear, \
|
return [BodySnatchPotion, Bomb, Heart, Hedgehog, Rabbit, TeddyBear,
|
||||||
Sunflower, Tiger, Merchant]
|
Sunflower, Tiger, Merchant]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -462,6 +463,7 @@ class FightingEntity(Entity):
|
||||||
d[name] = getattr(self, name)
|
d[name] = getattr(self, name)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
class FriendlyEntity(FightingEntity):
|
class FriendlyEntity(FightingEntity):
|
||||||
"""
|
"""
|
||||||
Friendly entities are living entities which do not attack the player
|
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:
|
def talk_to(self, player: Any) -> str:
|
||||||
a = randint(0, len(self.dialogue_option) - 1)
|
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:
|
def keys(self) -> list:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -129,6 +129,7 @@ class InventoryMenu(Menu):
|
||||||
def values(self) -> list:
|
def values(self) -> list:
|
||||||
return self.player.inventory
|
return self.player.inventory
|
||||||
|
|
||||||
|
|
||||||
class StoreMenu(Menu):
|
class StoreMenu(Menu):
|
||||||
merchant: Merchant
|
merchant: Merchant
|
||||||
|
|
||||||
|
@ -138,4 +139,3 @@ class StoreMenu(Menu) :
|
||||||
@property
|
@property
|
||||||
def values(self) -> list:
|
def values(self) -> list:
|
||||||
return self.merchant.inventory
|
return self.merchant.inventory
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue