Linux Format

Text adventure combat mechanics

 Credit: https://github.com/azuregate

I fyou’ve been following the previous tutorials on creating your own Python text adventure you should now have a script capable of moving the player around any number of rooms and interacting with items.

This is fine but most dungeon crawlers usually involve some element of risk. Of course, as the code stands, it’s quite possible to create a room to trap a player by removing all the exit attributes, but most games usually give the hero a certain quantity of health or hit points, which they have to guard carefully.

Hit me up

In order to make our hero sufficiently mortal, we first need to update the Player class in order to introduce the hit points attribute:

class Player: def __init__(self, name, currentroom, keyring, hp, inventory): self.name = name self.currentroom = currentroom self.keyring = keyring self.hp = hp self.inventory = inventory

This also means we need to assign a certain number of hit points (hereafter known as HP) to our player at the start of the script: player = Player(player_name, room1, [], 10, [bread])

Note in this case we’ve decided to assign the player 10HP but feel free to change this according to how risky or easy you want to make your adventure.

Inheriting items

Our player now has a certain number of HP but we haven’t done anything particularly

You’re reading a preview, subscribe to read more.

More from Linux Format

Linux Format1 min read
Kaki Pi
Another Pi-like SBPC appears! From Yuridenk-Shokai in Japan, this packs a Renesas RZ/V2H Coretex-A55/R8/M33 MPU with 80 TOPS of AI. It’s aimed at robotics and has four CSI video inputs along with a PCIe 3 connection. Find out more in Japanese: www.ka
Linux Format11 min readInternet & Web
Ultra-smooth Home Game Streaming
Credit: https://moonlight-stream.org, https://github.com/LizardByte Michael Reed is a consummate Linux professional who has been moonlighting for us so that he can live in the sunshine. (are we actually paying for these gags?–Ed) You can install the
Linux Format1 min read
Nvidia Moves To Block ZLUDA
As more and more applications rely on the combination of Nvidia and CUDA, it was inevitable that third-parties would try to build on their success. There’s already examples of this, such as ZLUDA, a drop-in replacement for CUDA. The implications of

Related