Need advice for an Inventory system
Hey everyone! I'm pretty new to coding and replit as a community and I was curious about how to implement an inventory system in a text-based adventure game. I'm using Python and I can't seem to figure it out. The inventory system needs to be able to:
-Track the stats of weapons and armor
-Track how many of an Item there is
-Display the inventory list in the console for the player to see
-Add items when collected
-Subtract Items when it's dropped or used by the player
I would appreciate it if someone could give an example of an inv system or if someone could at least give me a general idea of how to make one in Python.
Thanks and I'm glad to join the repl.it community!
An inventory system, eh?
Personally, I'd use classes a bunch for this. There'd be a class for every item, a class for the inventory itself, and maybe even an intermediate class of which each item is a subclass of.
Item class holds information about the item, such as the name, who owns it, etc. You can then make each item in your game a subclass of this class (like an
Armor class would implement the class as well as hold stats about durability, weight, etc.)
Inventory class can hold a large dictionary of
Item-Number pairs. Pretty self explanatory, the number is how many of each item is in the inventory.
This is just a loose description of how I'd do it, your implementation might look a little different.