def test_sell(): player.move_south() assert player.do_action( text_adventure.Sell, objects.iron_shield ) == "You have sold Iron Shield for 500 Gold.\nYou now have 1500 Gold. The shop now has 500 Gold." player.do_action(text_adventure.Buy, objects.iron_shield) player.move_north()
def test_available_actions(): player.move_east() assert text_adventure.tile_exists( player.location_x, player.location_y).available_actions() == [ text_adventure.MoveEast, text_adventure.MoveWest, text_adventure.TakeInventory, text_adventure.Equip, text_adventure.Observe, text_adventure.Consume, text_adventure.LookAround, text_adventure.PickUp, text_adventure.Drop ] player.move_west() player.move_west() #assert text_adventure.tile_exists(player.location_x, player.location_y).available_actions() == [text_adventure.Attack, text_adventure.Flee, text_adventure.Observe] text_adventure.tile_exists(player.location_x, player.location_y).enemy.hp = -200 assert text_adventure.tile_exists( player.location_x, player.location_y).available_actions() == [ text_adventure.MoveEast, text_adventure.TakeInventory, text_adventure.Equip, text_adventure.Observe, text_adventure.Consume, text_adventure.LookAround, text_adventure.PickUp, text_adventure.Drop ] text_adventure.tile_exists(player.location_x, player.location_y).enemy.hp = 200 player.move_east() player.move_south() assert text_adventure.tile_exists( player.location_x, player.location_y).available_actions() == [ text_adventure.MoveNorth, text_adventure.TakeInventory, text_adventure.Equip, text_adventure.Observe, text_adventure.Consume, text_adventure.LookAround, text_adventure.Buy, text_adventure.Sell ] player.move_north()
def test_buy(): player.move_south() player.currency_amount = 1000 assert player.buy(objects.steel_shield) == "You have bought Steel Shield for 750 Gold.\nYou now have 250 Gold. The shop now has 1750 Gold." player.sell(objects.steel_shield) player.move_north() player.currency_amount = 100
def test_buy(): player.move_south() player.currency_amount = 1000 assert player.do_action( text_adventure.Buy, objects.steel_shield ) == "You have bought Steel Shield for 750 Gold.\nYou now have 250 Gold. The shop now has 1750 Gold." player.do_action(text_adventure.Sell, objects.steel_shield) player.move_north()
def test_sell(): player.move_south() player.inventory.append(objects.gold_necklace) text_adventure.tile_exists(player.location_x, player.location_y).shop_currency_amount = 1500 assert (player.sell(objects.gold_necklace)) == "You have sold Gold Necklace for 1000 Gold.\nYou now have 1100 Gold. The shop now has 500 Gold." player.buy(objects.gold_necklace) text_adventure.tile_exists(player.location_x, player.location_y).shop_currency_amount = 1000 player.inventory.remove(objects.gold_necklace) player.move_north()
def test_flee(): player.move_north() player.equip(objects.iron_sword) import random random.seed(0) assert (player.flee()) == "Bandit hits you for 25 damage!\nYou now have 75 HP.\nYou are in the starting room." text_adventure.tile_exists(-1,0).enemy.hp = 100 player.move_south() player.hp = 100 objects.iron_sword.equipped_as_weapon = False
def test_attack_weapon(): player.move_north() player.equip(objects.iron_sword) import random random.seed(0) assert (player.attack()) == "You hit Bandit with Iron Sword (equipped), dealing 37 damage!\nBandit now has 63 HP.\nBandit hits you for 25 damage!\nYou now have 75 HP." text_adventure.tile_exists(player.location_x, player.location_y).enemy.hp = 100 player.move_south() player.hp = 100 objects.iron_sword.equipped_as_weapon = False
def test_attack(): random.seed(0) player.equip(objects.iron_sword) player.move_north() assert player.do_action( text_adventure.Attack ) == "You hit Bandit with Iron Sword (equipped), dealing 37 damage!\nBandit now has 63 HP.\nBandit hits you for 25 damage!\nYou now have 75 HP." player.hp = 100 objects.bandit.hp = 100 objects.iron_sword.equipped_as_weapon = False player.move_south()
def test_view_tile_inventory(): player.move_east() assert text_adventure.tile_exists( player.location_x, player.location_y).view_tile_inventory() == ( "Gold Necklace\n1000 Gold") player.move_west() player.move_south() assert text_adventure.tile_exists( player.location_x, player.location_y ).view_tile_inventory() == ( "Stock:\nSteel Sword\nSteel Armour\nSteel Shield\nThis store has 1000 Gold." ) player.move_north()
def test_show_room_text(): assert text_adventure.tile_exists( player.location_x, player.location_y).show_room_text() == "You are in the starting room." player.move_north() assert text_adventure.tile_exists( player.location_x, player.location_y).show_room_text() == "This room has a bandit in it." text_adventure.tile_exists(player.location_x, player.location_y).enemy.hp = -100 assert text_adventure.tile_exists(player.location_x, player.location_y).show_room_text( ) == "This room has a dead bandit in it." text_adventure.tile_exists(player.location_x, player.location_y).enemy.hp = 100 player.move_south()
def test_buy_item(): player.move_south() player.currency_amount = 1000 assert text_adventure.tile_exists( player.location_x, player.location_y ).buy_item( player, objects.steel_sword ) == "You have bought Steel Sword for 750 Gold.\nYou now have 250 Gold. The shop now has 1750 Gold." text_adventure.tile_exists(player.location_x, player.location_y).sell_item( player, objects.steel_sword) player.currency_amount = 100 assert text_adventure.tile_exists( player.location_x, player.location_y).buy_item( player, objects.steel_sword) == "You can't afford that!" assert text_adventure.tile_exists( player.location_x, player.location_y).buy_item( player, objects.iron_sword ) == "The shop does not have Iron Sword in store." text_adventure.tile_exists(player.location_x, player.location_y).shop_currency_amount = 1000 player.move_north()
def test_sell_item(): player.move_south() player.currency_amount = 1000 text_adventure.tile_exists(player.location_x, player.location_y).buy_item( player, objects.steel_sword) assert text_adventure.tile_exists( player.location_x, player.location_y ).sell_item( player, objects.steel_sword ) == "You have sold Steel Sword for 750 Gold.\nYou now have 1000 Gold. The shop now has 1000 Gold." player.currency_amount = 100 text_adventure.tile_exists(player.location_x, player.location_y).shop_currency_amount = 0 assert text_adventure.tile_exists( player.location_x, player.location_y).sell_item( player, objects.iron_sword) == "The store can't afford that!" assert text_adventure.tile_exists( player.location_x, player.location_y).sell_item( player, objects.steel_armour) == "You have no Steel Armour to sell." text_adventure.tile_exists(player.location_x, player.location_y).shop_currency_amount = 1000 player.move_north()
def test_attack_noweapon(): player.move_north() assert (player.attack()) == "You need a weapon first!" player.move_south()
def test_observe(): player.move_north() assert (player.observe(objects.iron_sword)) == ("Iron Sword\n-----\nA sword made of iron.\nValue: 500\nDamage: 50") assert (player.observe(objects.bandit)) == ("Bandit\n-----\nA fearsome bandit.\nHealth: 100\nDamage: 25\nArmour: 25\nBlock: 25") player.move_south()