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