Test ladders
This commit is contained in:
parent
a48e6325fe
commit
41548504de
@ -144,13 +144,9 @@ class Map:
|
||||
for ignored in range(count):
|
||||
while True:
|
||||
y, x = randint(0, self.height - 1), randint(0, self.width - 1)
|
||||
try:
|
||||
tile = self.tiles[y][x]
|
||||
except Exception as e:
|
||||
raise Exception(y, x, len(self.tiles))
|
||||
else:
|
||||
if tile.can_walk():
|
||||
break
|
||||
tile = self.tiles[y][x]
|
||||
if tile.can_walk():
|
||||
break
|
||||
entity = choice(Entity.get_all_entity_classes())()
|
||||
entity.move(y, x)
|
||||
self.add_entity(entity)
|
||||
|
@ -148,6 +148,9 @@ class TestGame(unittest.TestCase):
|
||||
self.assertEqual(KeyValues.translate_key(
|
||||
self.game.settings.KEY_WAIT, self.game.settings),
|
||||
KeyValues.WAIT)
|
||||
self.assertEqual(KeyValues.translate_key(
|
||||
self.game.settings.KEY_LADDER, self.game.settings),
|
||||
KeyValues.LADDER)
|
||||
self.assertEqual(KeyValues.translate_key(' ', self.game.settings),
|
||||
KeyValues.SPACE)
|
||||
self.assertEqual(KeyValues.translate_key('plop', self.game.settings),
|
||||
@ -338,7 +341,7 @@ class TestGame(unittest.TestCase):
|
||||
self.assertEqual(self.game.settings.KEY_LEFT_PRIMARY, 'a')
|
||||
|
||||
# Navigate to "texture pack"
|
||||
for ignored in range(11):
|
||||
for ignored in range(12):
|
||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||
|
||||
# Change texture pack
|
||||
@ -609,3 +612,34 @@ class TestGame(unittest.TestCase):
|
||||
# Exit the menu
|
||||
self.game.handle_key_pressed(KeyValues.SPACE)
|
||||
self.assertEqual(self.game.state, GameMode.PLAY)
|
||||
|
||||
def test_ladders(self) -> None:
|
||||
"""
|
||||
Ensure that the player can climb on ladders.
|
||||
"""
|
||||
self.game.state = GameMode.PLAY
|
||||
|
||||
self.assertEqual(self.game.player.map.floor, 0)
|
||||
self.game.handle_key_pressed(KeyValues.LADDER)
|
||||
self.assertEqual(self.game.player.map.floor, 0)
|
||||
|
||||
# Move nowhere
|
||||
self.game.player.move(10, 10)
|
||||
self.game.handle_key_pressed(KeyValues.LADDER)
|
||||
self.assertEqual(self.game.player.map.floor, 0)
|
||||
|
||||
# Move down
|
||||
self.game.player.move(3, 40) # Move on a ladder
|
||||
self.game.handle_key_pressed(KeyValues.LADDER)
|
||||
self.assertEqual(self.game.map_index, 1)
|
||||
self.assertEqual(self.game.player.map.floor, 1)
|
||||
self.assertEqual(self.game.player.y, 1)
|
||||
self.assertEqual(self.game.player.x, 17)
|
||||
self.game.display_actions(DisplayActions.UPDATE)
|
||||
|
||||
# Move up
|
||||
self.game.handle_key_pressed(KeyValues.LADDER)
|
||||
self.assertEqual(self.game.player.map.floor, 0)
|
||||
self.assertEqual(self.game.player.y, 3)
|
||||
self.assertEqual(self.game.player.x, 40)
|
||||
self.game.display_actions(DisplayActions.UPDATE)
|
||||
|
Loading…
Reference in New Issue
Block a user