Merge branch 'equipment-in-inventory' into 'master'

Resolve "Display equipment in inventory"

Closes #75

See merge request ynerant/squirrel-battle!71
This commit is contained in:
nicomarg
2021-01-10 22:45:04 +01:00
7 changed files with 57 additions and 85 deletions

View File

@ -155,9 +155,9 @@ class TestEntities(unittest.TestCase):
"""
item = Item()
self.map.add_entity(item)
self.assertFalse(item.held)
self.assertIsNone(item.held_by)
item.hold(self.player)
self.assertTrue(item.held)
self.assertEqual(item.held_by, self.player)
item.drop()
self.assertEqual(item.y, 1)
self.assertEqual(item.x, 6)
@ -165,7 +165,6 @@ class TestEntities(unittest.TestCase):
# Pick up item
self.player.move_left()
self.player.move_right()
self.assertTrue(item.held)
self.assertEqual(item.held_by, self.player)
self.assertIn(item, self.player.inventory)
self.assertNotIn(item, self.map.entities)
@ -208,7 +207,7 @@ class TestEntities(unittest.TestCase):
# The player can't hold the explosion
explosion.hold(self.player)
self.assertNotIn(explosion, self.player.inventory)
self.assertFalse(explosion.held)
self.assertIsNone(explosion.held_by)
# The explosion disappears after one tick
explosion.act(self.map)

View File

@ -49,6 +49,7 @@ class TestGame(unittest.TestCase):
# Add items in the inventory to check that it is well loaded
bomb.hold(self.game.player)
sword.hold(self.game.player)
sword.equip()
# Ensure that merchants can be saved
merchant = Merchant()
@ -491,10 +492,8 @@ class TestGame(unittest.TestCase):
# Drop an item
bomb = self.game.player.inventory[-1]
self.assertEqual(self.game.inventory_menu.validate(), bomb)
self.assertTrue(bomb.held)
self.assertEqual(bomb.held_by, self.game.player)
self.game.handle_key_pressed(KeyValues.DROP)
self.assertFalse(bomb.held)
self.assertIsNone(bomb.held_by)
self.assertIsNone(bomb.owner)
self.assertFalse(bomb.exploding)
@ -504,10 +503,8 @@ class TestGame(unittest.TestCase):
# Use the bomb
bomb = self.game.player.inventory[-1]
self.assertEqual(self.game.inventory_menu.validate(), bomb)
self.assertTrue(bomb.held)
self.assertEqual(bomb.held_by, self.game.player)
self.game.handle_key_pressed(KeyValues.USE)
self.assertFalse(bomb.held)
self.assertIsNone(bomb.held_by)
self.assertEqual(bomb.owner, self.game.player)
self.assertTrue(bomb.exploding)
@ -660,42 +657,37 @@ class TestGame(unittest.TestCase):
sword.hold(self.game.player)
self.game.handle_key_pressed(KeyValues.EQUIP)
self.assertEqual(self.game.player.equipped_main, sword)
self.assertFalse(self.game.player.inventory)
# shield goes into the secondary equipment slot
shield = Shield()
shield.hold(self.game.player)
self.game.handle_key_pressed(KeyValues.EQUIP)
shield.equip()
self.assertEqual(self.game.player.equipped_secondary, shield)
self.assertFalse(self.game.player.inventory)
# helmet goes into the helmet slot
helmet = Helmet()
helmet.hold(self.game.player)
self.game.handle_key_pressed(KeyValues.EQUIP)
helmet.equip()
self.assertEqual(self.game.player.equipped_helmet, helmet)
self.assertFalse(self.game.player.inventory)
# helmet goes into the armor slot
chestplate = Chestplate()
chestplate.hold(self.game.player)
self.game.handle_key_pressed(KeyValues.EQUIP)
chestplate.equip()
self.assertEqual(self.game.player.equipped_armor, chestplate)
self.assertFalse(self.game.player.inventory)
# Use bomb
bomb = Bomb()
bomb.hold(self.game.player)
self.game.handle_key_pressed(KeyValues.EQUIP)
bomb.equip()
self.assertEqual(self.game.player.equipped_secondary, bomb)
self.assertIn(shield, self.game.player.inventory)
self.assertFalse(shield.equipped)
self.game.state = GameMode.PLAY
self.game.handle_key_pressed(KeyValues.USE)
self.assertIsNone(self.game.player.equipped_secondary)
self.game.state = GameMode.INVENTORY
self.game.handle_key_pressed(KeyValues.EQUIP)
shield.equip()
self.assertEqual(self.game.player.equipped_secondary, shield)
self.assertFalse(self.game.player.inventory)
# Reequip, which is useless but covers code
sword.equip()
@ -717,6 +709,7 @@ class TestGame(unittest.TestCase):
self.assertIn(shield, self.game.player.inventory)
self.assertIn(helmet, self.game.player.inventory)
self.assertIn(chestplate, self.game.player.inventory)
self.game.display_actions(DisplayActions.REFRESH)
# Test rings
self.game.player.inventory.clear()