From cddff5c2d9943eab747666d1e8b4bd59eeb72f43 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 10 Jan 2021 19:17:04 +0100 Subject: [PATCH 1/2] Fix linting --- squirrelbattle/enums.py | 4 ++-- squirrelbattle/tests/game_test.py | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/squirrelbattle/enums.py b/squirrelbattle/enums.py index 42bd643..b61f236 100644 --- a/squirrelbattle/enums.py +++ b/squirrelbattle/enums.py @@ -53,7 +53,8 @@ class KeyValues(Enum): DANCE = auto() @staticmethod - def translate_key(key: str, settings: Settings) -> Optional["KeyValues"]: + def translate_key(key: str, settings: Settings) \ + -> Optional["KeyValues"]: # noqa: C901 """ Translates the raw string key into an enum value that we can use. """ @@ -91,4 +92,3 @@ class KeyValues(Enum): return KeyValues.LAUNCH elif key == settings.KEY_DANCE: return KeyValues.DANCE - return None diff --git a/squirrelbattle/tests/game_test.py b/squirrelbattle/tests/game_test.py index a3c3a87..895af12 100644 --- a/squirrelbattle/tests/game_test.py +++ b/squirrelbattle/tests/game_test.py @@ -260,12 +260,10 @@ class TestGame(unittest.TestCase): self.game.handle_key_pressed(KeyValues.DANCE) self.assertEqual(rabbit.confused, 1) string = rabbit.hit(self.game.player) - self.assertEqual(string, - "{name} is confused, it can not hit {opponent}." - .format(name=_(rabbit.translated_name.capitalize() - ), opponent=_( - self.game.player.translated_name - ))) + self.assertEqual( + string, _("{name} is confused, it can not hit {opponent}.") + .format(name=rabbit.translated_name.capitalize(), + opponent=self.game.player.translated_name)) rabbit.confused = 0 self.game.player.charisma = 0 self.game.handle_key_pressed(KeyValues.DANCE) From 01ee49ddd44a12b0aa0bad39a6b01c76185b7b62 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 10 Jan 2021 19:25:12 +0100 Subject: [PATCH 2/2] Entities are updated after a bow shot, fixes #70 --- squirrelbattle/entities/items.py | 11 ++++++----- squirrelbattle/game.py | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/squirrelbattle/entities/items.py b/squirrelbattle/entities/items.py index 182c86b..ac5f74d 100644 --- a/squirrelbattle/entities/items.py +++ b/squirrelbattle/entities/items.py @@ -47,7 +47,7 @@ class Item(Entity): Indicates what should be done when the item is used. """ - def throw(self, direction: int) -> None: + def throw(self, direction: int) -> Any: """ Indicates what should be done when the item is thrown. """ @@ -555,7 +555,7 @@ class LongRangeWeapon(Weapon): self.held_by, self.damage + getattr(self.held_by, self.stat)) self.held_by.map.logs.add_message(line) - return (to_kill.x, to_kill.y) if to_kill else None + return (to_kill.y, to_kill.x) if to_kill else None def equip(self) -> None: """ @@ -621,17 +621,18 @@ class FireBallStaff(LongRangeWeapon): def string(self) -> str: return " is shot by a fire ball." - def throw(self, direction: int) -> None: + def throw(self, direction: int) -> Any: """ Adds an explosion animation when killing something. """ coord = super().throw(direction) if coord: - x = coord[0] - y = coord[1] + y = coord[0] + x = coord[1] explosion = Explosion(y=y, x=x) self.held_by.map.add_entity(explosion) + return y, x class Monocle(Item): diff --git a/squirrelbattle/game.py b/squirrelbattle/game.py index bde825f..83da5f3 100644 --- a/squirrelbattle/game.py +++ b/squirrelbattle/game.py @@ -292,7 +292,8 @@ class Game: return if self.player.equipped_main: - self.player.equipped_main.throw(direction) + if self.player.equipped_main.throw(direction): + self.map.tick(self.player) def handle_key_pressed_inventory(self, key: KeyValues) -> None: """