Test selling items
This commit is contained in:
parent
c55a7451e7
commit
b8d32b29c8
|
@ -54,7 +54,6 @@ class DisplayManager:
|
|||
self.mapdisplay.update_map(self.game.map)
|
||||
self.statsdisplay.update_player(self.game.player)
|
||||
self.game.inventory_menu.update_player(self.game.player)
|
||||
self.game.store_menu.update_merchant(self.game.player)
|
||||
self.playerinventorydisplay.update_menu(self.game.inventory_menu)
|
||||
self.storeinventorydisplay.update_menu(self.game.store_menu)
|
||||
self.settingsmenudisplay.update_menu(self.game.settings_menu)
|
||||
|
|
|
@ -132,11 +132,11 @@ class InventoryMenu(Menu):
|
|||
|
||||
|
||||
class StoreMenu(Menu):
|
||||
merchant: Merchant
|
||||
merchant: Merchant = None
|
||||
|
||||
def update_merchant(self, merchant: Merchant) -> None:
|
||||
self.merchant = merchant
|
||||
|
||||
@property
|
||||
def values(self) -> list:
|
||||
return self.merchant.inventory
|
||||
return self.merchant.inventory if self.merchant else []
|
||||
|
|
|
@ -12,6 +12,7 @@ from ..entities.items import Bomb, Heart, Sword, Explosion
|
|||
from ..entities.player import Player
|
||||
from ..enums import DisplayActions
|
||||
from ..game import Game, KeyValues, GameMode
|
||||
from ..interfaces import Map
|
||||
from ..menus import MainMenuValues
|
||||
from ..resources import ResourceManager
|
||||
from ..settings import Settings
|
||||
|
@ -25,6 +26,10 @@ class TestGame(unittest.TestCase):
|
|||
"""
|
||||
self.game = Game()
|
||||
self.game.new_game()
|
||||
self.game.map = Map.load(
|
||||
ResourceManager.get_asset_path("example_map.txt"))
|
||||
self.game.map.add_entity(self.game.player)
|
||||
self.game.player.move(self.game.map.start_y, self.game.map.start_x)
|
||||
self.game.logs.add_message("Hello World !")
|
||||
display = DisplayManager(None, self.game)
|
||||
self.game.display_actions = display.handle_display_action
|
||||
|
@ -556,12 +561,11 @@ class TestGame(unittest.TestCase):
|
|||
self.game.player.hazel = 0x7ffff42ff
|
||||
|
||||
# The second item is not a heart
|
||||
merchant.inventory[1] = Sword()
|
||||
merchant.inventory[1] = sword = Sword()
|
||||
# Buy the second item by clicking on it
|
||||
item = self.game.store_menu.validate()
|
||||
self.assertIn(item, merchant.inventory)
|
||||
self.game.display_actions(DisplayActions.MOUSE, 7, 25)
|
||||
self.game.handle_key_pressed(KeyValues.ENTER)
|
||||
self.assertIn(item, self.game.player.inventory)
|
||||
self.assertNotIn(item, merchant.inventory)
|
||||
|
||||
|
@ -587,6 +591,20 @@ class TestGame(unittest.TestCase):
|
|||
_("The buyer does not have enough money"))
|
||||
self.game.handle_key_pressed(KeyValues.ENTER)
|
||||
|
||||
# Sell an item
|
||||
self.game.inventory_menu.position = len(self.game.player.inventory) - 1
|
||||
self.game.handle_key_pressed(KeyValues.LEFT)
|
||||
self.assertFalse(self.game.is_in_store_menu)
|
||||
self.assertIn(sword, self.game.player.inventory)
|
||||
self.assertEqual(self.game.inventory_menu.validate(), sword)
|
||||
old_player_money, old_merchant_money = self.game.player.hazel,\
|
||||
merchant.hazel
|
||||
self.game.handle_key_pressed(KeyValues.ENTER)
|
||||
self.assertNotIn(sword, self.game.player.inventory)
|
||||
self.assertIn(sword, merchant.inventory)
|
||||
self.assertEqual(self.game.player.hazel, old_player_money + sword.price)
|
||||
self.assertEqual(merchant.hazel, old_merchant_money - sword.price)
|
||||
|
||||
# Exit the menu
|
||||
self.game.handle_key_pressed(KeyValues.SPACE)
|
||||
self.assertEqual(self.game.state, GameMode.PLAY)
|
||||
|
|
Loading…
Reference in New Issue