Im working on a game. its a remake of the nes game spy vs spy.
when i print the self.items list its just giving me a memory loc. i made str method but im missing some thing. its hard to keep track of the player items without seeing the name and being able to update them.
it currently prints like this
ITEMS: <generator object Spy.__str__.<locals>.<genexpr> at 0x0000016C796456D0>
class Game():
def __init__(self):
pass
def move(self):
pass
class Room():
def __init__(self, exit_to_plane, furniture, doors):
self.exit_to_plane = False
self.furniture = []
self.doors = doors
class Spy():
def __init__(self):
self.health = 100
self.items = []
self.able_to_fly = False
def fly_airplane(self):
if key not in self.items:
self.able_to_fly = True
def pick_up_item(self, item):
self.items.append(item)
def remove_item(self, item):
self.items.remove(item)
def switch_weapons():
pass
def use_weapon(self, item):
item.item_quantity -= 1
def __str__(self):
return (
f'HEALTH: {self.health}\n'
f'ITEMS: {print(item) for item in self.items}\n'
f'ABLE TO FLY: {self.able_to_fly}\n'
)
class Item():
def __init__(self, name, type, damage_amount, quantity):
self.name = name
self.type = type
self.damage_amount = damage_amount
self.item_quantity = quantity
def __str__(self):
return (
f'NAME: {self.name}\n'
f'TYPE: {self.type}\n'
f'DAMAGE AMOUNT: {self.damage_amount}\n'
f'item_quantity: {self.item_quantity}\n'
)
# Items
knife = Item('knife', 'weapon', 2, None)
bomb = Item('bomb', 'weapon', 5, 2)
oil_can = Item('oil can', 'weapon', 3, 1)
key = Item('Key', 'key', 0, 1)
print('ITEMS:')
print(knife)
print(bomb)
print(oil_can)
print(key)
print()
# Spies
spy1 = Spy()
spy2 = Spy()
spy1.pick_up_item(Item('knife', 'weapon', 2, 1000))
spy1.pick_up_item(key)
spy1.fly_airplane()
print('SPIES:')
print('SPY 1')
print(spy1)
print('SPY 2')
print(spy2)
print()
spy1.remove_item(key)
spy1.fly_airplane()
print(spy1)
# Use an item
print(bomb)