Dec-17-2019, 03:29 AM
That looks familiar, it's basically the second code bit in my text adventure tutorial. If you want an inventory system, there's one in the third piece of code in that same tutorial. It adds a 'contents' key to each room dictionary, with a list of words for the things in the room. Then there is an overall 'carrying' list to show what the player is carrying. It's pretty rudimentary, but it's a start.
If you want to add a combat system, you will probably want to start distinguishing things that can fight from things that can't. At that point, you would probably want to switch the items from just being strings to be dictionaries themselves, so they could contain different attributes (key/value pairs). What I would do is have the item dictionary be something like this:
You will note that I also gave each item a 'contents' key. If item['contents'] is None, it is not a container, and you can't put other things in it. Otherwise, you can put other items (like the bone) into the box. This is a common thing in interactive fiction.
This is just an off-the-top-of-my-head sketch of how things might work. But hopefully it gives you some ideas on how to set up your own systems.
If you want to add a combat system, you will probably want to start distinguishing things that can fight from things that can't. At that point, you would probably want to switch the items from just being strings to be dictionaries themselves, so they could contain different attributes (key/value pairs). What I would do is have the item dictionary be something like this:
items = {'bone': {'description': 'A long leg bone, good for hitting things with', 'contents': None, 'hp': None, 'attack': []}, 'box': {'description': 'A cardboard box.', 'contents': [], 'hp': None, 'attack': []} 'Bat Boy': {'description': 'A teenager with huge ears and fangs.', 'contents': None, 'hp': 18, 'attack': [1, 1, 2, 3]}}Now, the box and the bone both have 'hp' set to None and 'attack' set to an empty list. These could be used to determine that those items can't get into combat. 'Bat Boy', OTOH, has both, and they can be used for a combat system (the idea I'm going with here is that random.choice(items['Bat Boy']['attack']) would give you the damage of Bat Boy's attack).
You will note that I also gave each item a 'contents' key. If item['contents'] is None, it is not a container, and you can't put other things in it. Otherwise, you can put other items (like the bone) into the box. This is a common thing in interactive fiction.
This is just an off-the-top-of-my-head sketch of how things might work. But hopefully it gives you some ideas on how to set up your own systems.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures