Skip to main content

A minimal library for writing text adventure games in Python 3, now with rich text!

Project description

RicherAdventureLib

adventurelib provides basic functionality for writing text-based adventure games, with the aim of making it easy enough for young teenagers to do.

- @lordmauve

richeradventurelib expands upon this by allowing programmers to implement colours and styles into their games using the rich library

Use bbcode-like syntax in your games ([bold italic orange3 on blue]You are in the bedroom[/]) and even add emojis (:fire: You cast fireball :fire:)!

Furthermore, richeradventurelib places the entire story interface inside a rich terminal layout, allowing the user to view the status of the game and their inventory, with many more configurable possibilities!

Screenshot of demo gameplay

The foundation of adventurelib is the ability to define functions that are called in response to commands. For example, you could write a function to be called when the user types commands like "take hat":

@when('take THING')
def take(thing):
	print(f'You take the {thing}.')
	inventory.append(thing)

It also includes the foundations needed to write games involving rooms, items, characters and more... but users will have to implement these features for themselves as they explore Python programming concepts.

Usage

The usage of richeradventurelib is almost identical to that of the original adventurelib with a few additions:

Usually in an adventurelib game, you would have this at the very bottom of your file:

look()
adv.start()

However, the introduction of the sidecar UI complicates this a bit more. Firstly, you must define two variables: one for the state and one for the UI.

import richeradventurelib as adv


TITLE = 'Moonfall Trail'

state = adv.GameState(title=TITLE, location_name='Lantern Cabin', tracked_vars={"health": 100, "strength": 10})
ui = adv.SidecarUI(title=TITLE, state=state)

Then at the very bottom of your file, you must start the UI, sync the state, and start the game with the UI provided.

ui.start()
sync_state()
look()
adv.start(help=False, ui=ui)

Throughout the game, whenever you need to update a tracked variable, use state.set_var(var, value)

For example, when updating the health:

state.set_var('health', 100)

AI Acknowledgement

I used GitHub Copilot for a lot of the code in this project, namely the demo game and most of the implementation of the sidecar layout. The exact amount could be found through this project's hackatime (reviewers have access I think?).

As of this commit, the AI usage for this project remains under 30% of the total time.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

richeradventurelib-2.0.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

richeradventurelib-2.0.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file richeradventurelib-2.0.0.tar.gz.

File metadata

  • Download URL: richeradventurelib-2.0.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for richeradventurelib-2.0.0.tar.gz
Algorithm Hash digest
SHA256 0448107ec370637940cef0560d9537e8d0c4c3849580769a0ef47aa4b1177e8f
MD5 bfe96eb5eab2946a56e35cb59bbb00f2
BLAKE2b-256 617a3f701d17d44528fe9780a8b86db158aff1beef6d7839804f161c93df02c1

See more details on using hashes here.

File details

Details for the file richeradventurelib-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for richeradventurelib-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29017f6ef36cab7fec56ab4dba3fa94fba4d6efa494a5273c7ebf8738aac2603
MD5 945263a554f14b665b68c8e9ac16917d
BLAKE2b-256 2cf81a6d415660c3d3fecdd089e6d6cde7fc5cfddf7345d8717c43d429dacf65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page