Test ladders
This commit is contained in:
parent
a48e6325fe
commit
41548504de
|
@ -144,11 +144,7 @@ class Map:
|
||||||
for ignored in range(count):
|
for ignored in range(count):
|
||||||
while True:
|
while True:
|
||||||
y, x = randint(0, self.height - 1), randint(0, self.width - 1)
|
y, x = randint(0, self.height - 1), randint(0, self.width - 1)
|
||||||
try:
|
|
||||||
tile = self.tiles[y][x]
|
tile = self.tiles[y][x]
|
||||||
except Exception as e:
|
|
||||||
raise Exception(y, x, len(self.tiles))
|
|
||||||
else:
|
|
||||||
if tile.can_walk():
|
if tile.can_walk():
|
||||||
break
|
break
|
||||||
entity = choice(Entity.get_all_entity_classes())()
|
entity = choice(Entity.get_all_entity_classes())()
|
||||||
|
|
|
@ -148,6 +148,9 @@ class TestGame(unittest.TestCase):
|
||||||
self.assertEqual(KeyValues.translate_key(
|
self.assertEqual(KeyValues.translate_key(
|
||||||
self.game.settings.KEY_WAIT, self.game.settings),
|
self.game.settings.KEY_WAIT, self.game.settings),
|
||||||
KeyValues.WAIT)
|
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),
|
self.assertEqual(KeyValues.translate_key(' ', self.game.settings),
|
||||||
KeyValues.SPACE)
|
KeyValues.SPACE)
|
||||||
self.assertEqual(KeyValues.translate_key('plop', self.game.settings),
|
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')
|
self.assertEqual(self.game.settings.KEY_LEFT_PRIMARY, 'a')
|
||||||
|
|
||||||
# Navigate to "texture pack"
|
# Navigate to "texture pack"
|
||||||
for ignored in range(11):
|
for ignored in range(12):
|
||||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
|
|
||||||
# Change texture pack
|
# Change texture pack
|
||||||
|
@ -609,3 +612,34 @@ class TestGame(unittest.TestCase):
|
||||||
# Exit the menu
|
# Exit the menu
|
||||||
self.game.handle_key_pressed(KeyValues.SPACE)
|
self.game.handle_key_pressed(KeyValues.SPACE)
|
||||||
self.assertEqual(self.game.state, GameMode.PLAY)
|
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