Monsters are hedgehogs 🦔
This commit is contained in:
parent
3f374d2558
commit
3f4c809db6
@ -17,7 +17,7 @@ class MapDisplay(Display):
|
||||
def update_pad(self) -> None:
|
||||
self.pad.addstr(0, 0, self.map.draw_string(self.pack))
|
||||
for e in self.map.entities:
|
||||
self.pad.addstr(e.y, e.x, self.pack.PLAYER)
|
||||
self.pad.addstr(e.y, e.x, self.pack[e.name.upper()])
|
||||
|
||||
def display(self) -> None:
|
||||
y, x = self.map.currenty, self.map.currentx
|
||||
|
@ -15,6 +15,9 @@ class TexturePack:
|
||||
self.__dict__.update(**kwargs)
|
||||
TexturePack._packs[name] = self
|
||||
|
||||
def __getitem__(self, item):
|
||||
return self.__dict__[item]
|
||||
|
||||
@classmethod
|
||||
def get_pack(cls, name: str) -> "TexturePack":
|
||||
return cls._packs[name.lower()]
|
||||
@ -26,6 +29,7 @@ TexturePack.ASCII_PACK = TexturePack(
|
||||
WALL='#',
|
||||
FLOOR='.',
|
||||
PLAYER='@',
|
||||
HEDGEHOG='*',
|
||||
)
|
||||
|
||||
TexturePack.SQUIRREL_PACK = TexturePack(
|
||||
@ -34,4 +38,5 @@ TexturePack.SQUIRREL_PACK = TexturePack(
|
||||
WALL='█',
|
||||
FLOOR='.',
|
||||
PLAYER='🐿️',
|
||||
HEDGEHOG='🦔',
|
||||
)
|
||||
|
@ -17,6 +17,7 @@ class Item(Entity):
|
||||
|
||||
|
||||
class Bomb(Item):
|
||||
name = "bomb"
|
||||
damage: int = 5
|
||||
exploding: bool
|
||||
|
||||
|
@ -6,6 +6,7 @@ class Monster(FightingEntity):
|
||||
pass
|
||||
|
||||
|
||||
class Squirrel(Monster):
|
||||
class Hedgehog(Monster):
|
||||
name = "hedgehog"
|
||||
maxhealth = 10
|
||||
strength = 3
|
||||
|
@ -2,6 +2,7 @@ from ..interfaces import FightingEntity
|
||||
|
||||
|
||||
class Player(FightingEntity):
|
||||
name = "player"
|
||||
maxhealth: int = 20
|
||||
strength: int = 5
|
||||
intelligence: int = 1
|
||||
|
@ -14,6 +14,7 @@ class Map:
|
||||
width: int
|
||||
height: int
|
||||
tiles: List[List["Tile"]]
|
||||
entities: List["Entity"]
|
||||
# coordinates of the point that should be
|
||||
# on the topleft corner of the screen
|
||||
currentx: int
|
||||
@ -73,7 +74,7 @@ class Map:
|
||||
|
||||
def spawn_random_entities(self, count: int) -> None:
|
||||
"""
|
||||
Put randomly {count} squirrels on the map, where it is available.
|
||||
Put randomly {count} hedgehogs on the map, where it is available.
|
||||
"""
|
||||
for _ in range(count):
|
||||
y, x = 0, 0
|
||||
@ -82,10 +83,10 @@ class Map:
|
||||
tile = self.tiles[y][x]
|
||||
if tile.can_walk():
|
||||
break
|
||||
from dungeonbattle.entities.monsters import Squirrel
|
||||
squirrel = Squirrel()
|
||||
squirrel.move(y, x)
|
||||
self.add_entity(squirrel)
|
||||
from dungeonbattle.entities.monsters import Hedgehog
|
||||
hedgehog = Hedgehog()
|
||||
hedgehog.move(y, x)
|
||||
self.add_entity(hedgehog)
|
||||
|
||||
|
||||
class Tile(Enum):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import unittest
|
||||
|
||||
from dungeonbattle.entities.items import Bomb, Item
|
||||
from dungeonbattle.entities.monsters import Squirrel
|
||||
from dungeonbattle.entities.monsters import Hedgehog
|
||||
from dungeonbattle.entities.player import Player
|
||||
from dungeonbattle.interfaces import Entity, Map
|
||||
|
||||
@ -27,7 +27,7 @@ class TestEntities(unittest.TestCase):
|
||||
"""
|
||||
Test some random stuff with fighting entities.
|
||||
"""
|
||||
entity = Squirrel()
|
||||
entity = Hedgehog()
|
||||
self.assertIsNone(entity.act(self.map))
|
||||
self.assertEqual(entity.maxhealth, 10)
|
||||
self.assertEqual(entity.maxhealth, entity.health)
|
||||
@ -58,18 +58,18 @@ class TestEntities(unittest.TestCase):
|
||||
Test some random stuff with bombs.
|
||||
"""
|
||||
item = Bomb()
|
||||
squirrel = Squirrel()
|
||||
hedgehog = Hedgehog()
|
||||
self.map.add_entity(item)
|
||||
self.map.add_entity(squirrel)
|
||||
squirrel.health = 2
|
||||
squirrel.move(41, 42)
|
||||
self.map.add_entity(hedgehog)
|
||||
hedgehog.health = 2
|
||||
hedgehog.move(41, 42)
|
||||
item.act(self.map)
|
||||
self.assertFalse(squirrel.dead)
|
||||
self.assertFalse(hedgehog.dead)
|
||||
item.drop(42, 42)
|
||||
self.assertEqual(item.y, 42)
|
||||
self.assertEqual(item.x, 42)
|
||||
item.act(self.map)
|
||||
self.assertTrue(squirrel.dead)
|
||||
self.assertTrue(hedgehog.dead)
|
||||
|
||||
def test_players(self) -> None:
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user