Merge branch 'map_generation' into 'master'
Map generation Closes #5 See merge request ynerant/squirrel-battle!35
This commit is contained in:
@ -16,7 +16,7 @@ from ..entities.monsters import GiantSeaEagle, Rabbit
|
||||
from ..entities.player import Player
|
||||
from ..enums import DisplayActions, GameMode, KeyValues
|
||||
from ..game import Game
|
||||
from ..interfaces import Map
|
||||
from ..interfaces import Map, Tile
|
||||
from ..menus import MainMenuValues
|
||||
from ..resources import ResourceManager
|
||||
from ..settings import Settings
|
||||
@ -224,6 +224,12 @@ class TestGame(unittest.TestCase):
|
||||
self.game.map.remove_entity(entity)
|
||||
|
||||
y, x = self.game.player.y, self.game.player.x
|
||||
|
||||
# Ensure that the neighborhood is walkable
|
||||
for dx in [-1, 0, 1]:
|
||||
for dy in [-1, 0, 1]:
|
||||
self.game.map.tiles[y + dy][x + dx] = Tile.FLOOR
|
||||
|
||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||
new_y, new_x = self.game.player.y, self.game.player.x
|
||||
self.assertEqual(new_y, y + 1)
|
||||
@ -518,7 +524,7 @@ class TestGame(unittest.TestCase):
|
||||
self.game.state = GameMode.PLAY
|
||||
|
||||
sunflower = Sunflower()
|
||||
sunflower.move(2, 6)
|
||||
sunflower.move(self.game.player.y + 1, self.game.player.x)
|
||||
self.game.map.add_entity(sunflower)
|
||||
|
||||
# Does nothing
|
||||
@ -549,15 +555,15 @@ class TestGame(unittest.TestCase):
|
||||
for msg in Sunflower().dialogue_option))
|
||||
|
||||
# Test all directions to detect the friendly entity
|
||||
self.game.player.move(3, 6)
|
||||
self.game.player.move(sunflower.y + 1, sunflower.x)
|
||||
self.game.handle_key_pressed(KeyValues.CHAT)
|
||||
self.game.handle_key_pressed(KeyValues.UP)
|
||||
self.assertEqual(len(self.game.logs.messages), 3)
|
||||
self.game.player.move(2, 7)
|
||||
self.game.player.move(sunflower.y, sunflower.x + 1)
|
||||
self.game.handle_key_pressed(KeyValues.CHAT)
|
||||
self.game.handle_key_pressed(KeyValues.LEFT)
|
||||
self.assertEqual(len(self.game.logs.messages), 4)
|
||||
self.game.player.move(2, 5)
|
||||
self.game.player.move(sunflower.y, sunflower.x - 1)
|
||||
self.game.handle_key_pressed(KeyValues.CHAT)
|
||||
self.game.handle_key_pressed(KeyValues.RIGHT)
|
||||
self.assertEqual(len(self.game.logs.messages), 5)
|
||||
@ -569,7 +575,7 @@ class TestGame(unittest.TestCase):
|
||||
self.game.state = GameMode.PLAY
|
||||
|
||||
merchant = Merchant()
|
||||
merchant.move(2, 6)
|
||||
merchant.move(self.game.player.y + 1, self.game.player.x)
|
||||
self.game.map.add_entity(merchant)
|
||||
|
||||
# Does nothing
|
||||
@ -715,6 +721,7 @@ class TestGame(unittest.TestCase):
|
||||
self.game.player.inventory.clear()
|
||||
ring = RingCritical()
|
||||
ring.hold(self.game.player)
|
||||
self.game.display_actions(DisplayActions.REFRESH)
|
||||
old_critical = self.game.player.critical
|
||||
self.game.handle_key_pressed(KeyValues.EQUIP)
|
||||
self.assertEqual(self.game.player.critical,
|
||||
@ -758,8 +765,6 @@ class TestGame(unittest.TestCase):
|
||||
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
|
||||
@ -940,3 +945,18 @@ class TestGame(unittest.TestCase):
|
||||
# Exit the menu
|
||||
self.game.handle_key_pressed(KeyValues.SPACE)
|
||||
self.assertEqual(self.game.state, GameMode.PLAY)
|
||||
|
||||
def test_doors(self) -> None:
|
||||
"""
|
||||
Check that the user can open doors.
|
||||
"""
|
||||
self.game.state = GameMode.PLAY
|
||||
|
||||
self.game.player.move(9, 8)
|
||||
self.assertEqual(self.game.map.tiles[10][8], Tile.DOOR)
|
||||
# Open door
|
||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||
self.assertEqual(self.game.map.tiles[10][8], Tile.FLOOR)
|
||||
self.assertEqual(self.game.player.y, 10)
|
||||
self.assertEqual(self.game.player.x, 8)
|
||||
self.game.display_actions(DisplayActions.REFRESH)
|
||||
|
Reference in New Issue
Block a user