Test player level up
This commit is contained in:
parent
0de11abfa8
commit
aeb43a0cec
@ -2,8 +2,11 @@ from ..interfaces import FightingEntity
|
||||
|
||||
|
||||
class Player(FightingEntity):
|
||||
maxhealth = 20
|
||||
strength = 5
|
||||
maxhealth: int = 20
|
||||
strength: int = 5
|
||||
level: int = 1
|
||||
current_xp: int = 0
|
||||
max_xp: int = 10
|
||||
|
||||
def move_up(self) -> bool:
|
||||
return self.check_move(self.y - 1, self.x, True)
|
||||
@ -17,13 +20,10 @@ class Player(FightingEntity):
|
||||
def move_right(self) -> bool:
|
||||
return self.check_move(self.y, self.x + 1, True)
|
||||
|
||||
current_xp: int
|
||||
max_xp: int
|
||||
|
||||
def level_up(self) -> None:
|
||||
if self.current_xp > self.max_xp:
|
||||
while self.current_xp > self.max_xp:
|
||||
self.level += 1
|
||||
self.current_xp = 0
|
||||
self.current_xp -= self.max_xp
|
||||
self.max_xp = self.level * 10
|
||||
|
||||
def add_xp(self, xp: int) -> None:
|
||||
|
@ -95,3 +95,8 @@ class TestEntities(unittest.TestCase):
|
||||
self.assertFalse(player.move_right())
|
||||
self.assertTrue(player.move_down())
|
||||
self.assertTrue(player.move_down())
|
||||
|
||||
player.add_xp(70)
|
||||
self.assertEqual(player.current_xp, 10)
|
||||
self.assertEqual(player.max_xp, 40)
|
||||
self.assertEqual(player.level, 4)
|
||||
|
@ -32,3 +32,4 @@ class TestInterfaces(unittest.TestCase):
|
||||
self.assertTrue(Tile.FLOOR.can_walk())
|
||||
self.assertFalse(Tile.WALL.can_walk())
|
||||
self.assertTrue(Tile.EMPTY.can_walk())
|
||||
self.assertRaises(ValueError, Tile.from_ascii_char, 'unknown')
|
||||
|
Loading…
Reference in New Issue
Block a user