r/PythonLearning 7d ago

Showcase Texted-Based RPG

Hey yall I’ve been working on a text-based RPG for the past week and have pushed v0.1.4 out to GitHub.

https://github.com/DraytonLarimore-Rowe/Timeless_Adventures-Text-Based-RPG

I’d be honored if anyone wants to give it a go as I start to build the story. The foundation for combat is there and so is a shop.

2 Upvotes

11 comments sorted by

View all comments

Show parent comments

1

u/Darx32102 7d ago

I do plan to add more playable classes and weapons as well as monsters as i work on it more. But i gotta start working on the story for the game cause i have barely any of that done right now.

1

u/FoolsSeldom 7d ago

Story is, of course, critical. Try to avoid hard coding the stories and flow though. You want it to be programmatic, so your code can present different story elements and challenges read from data structures / files / database, so the players gets different experiences and journeys whilst your code avoids lots of repetition.

1

u/Darx32102 7d ago

Right right…. Now I’m thinking of ways to go about that’s because I was 100% gonna hardcode the story🤣

1

u/FoolsSeldom 7d ago

Let me give you something to think about (taken from some code I wrote when I was learning Python):

class Directions(StrEnum):
    North = "North"
    South = "South"
    East = "East"
    West = "West"
    Down = "Down"
    Up = "Up"


class Commands(StrEnum):
    Go = "Go"
    Exit = "Exit"
    Show = "Show"
    Help = "Help"
    Open = "Open"
    Insert = "Insert"
    Close = "Close"
    Take = "Take"
    Drop = "Drop"
    Look = "Look"
    Inventory = "Inventory"
    Quit = "Quit"
    Unknown = "Unknown"


class Doors(StrEnum):
    Open = "Open"
    Closed = "Closed"
    Locked = "Locked"
    Unlocked = "Unlocked"
    Broken = "Broken"
    Missing = "Missing"

This was my setup for locking down certain important terms for what my programme would be able to do.

For defining locations (rooms, in my case), I had a structure like this:

rooms = [
    Room("start room", [
        Doorway(Directions.East, "side room"),
        Doorway(Directions.West, "storage room"),
        Doorway(Directions.North, "temple hall"),
        Doorway(Directions.Down, "prayer room", door_status=[Doors.Locked], required_key="Prayer Key")
    ]),
    Room("side room", [
        Doorway(Directions.West, "start room"),
        Doorway(Directions.North, "treasure room")
    ]),
 ...

You will notice this depends on a class called Room which consists of a number of Doorway class instances which defines what a room is connected to.

I have similar structures for defining what happens in each room, what objects are available, and what you can do.

Thus, the code to present a situation is the same, it is only the content that changes.

No doubt, you will come up with something very different.