Part Two!
QUICK TIP
QUICK TIP
LISTING ROOM ITEMS
QUICK TIP
CORDING ACADEMY
Don’t miss next issue, subscribe on page 16!
OUR EXPERT
If you find following the code changes difficult, download the sample scripts first and run them to see how everything works. Find the repository here: https://github. com/azuregate/ lxfpython textadventure.
Sharp-eyed readers will notice that all the classes of items, such as Player, are now capitalised, whereas the items themselves are in lower case. This is good coding etiquette, enabling you to quickly tell the difference between the two. The code will still run if you don’t use capitalisation.
If you’ve been following the code in the main article, you’ll see that certain items aren’t always immediately visible. For instance, you need to inspect the dwarf skeleton to find he’s wearing armour. Similarly, smashing open the chest in the other test room reveals a large ruby.
If you’ve downloaded the new code samples, you’ll see there’s a new function dedicated to movement. If you want to add new directions, such as up and down, make sure to include these exits for individual rooms, then update ‘trytomove’ to bind keys, such as U and D.
MU
Nate Drake wants to dedicate this series to his dad, who once told him that no one was ever going to pay him to sit around and play video games.
As the code stands, if you choose to leave the room and return, there’s no record of these new items. That’s why many text adventure games specifically list available items in each room.
Credit: https://codewith.mu
To do this in Python, you must define a special function to list room items:
Part Two!
Don’t miss next issue, subscribe on page 16!