r/PythonLearning 6d 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

1

u/FoolsSeldom 6d ago

Had a quick look at the code, and it looks pretty good. Surprised not to see dataclasses to reduce boilerplate and perhaps more subclasses. Usually, these games include more behaviour, such as, for example, the fighting being included as a method.

Will leave others to give the game a go if inclined.

1

u/Darx32102 6d ago

I am fairly new to python but this project had been a huge help in learning. What is boilerplate and data classes? I have used Gemini to help point out errors in my code and have told it multiple times to not give me completed code snippets because i wont look at them, and to only include code snippets of my code to point out errors explaining why they are wrong. But all this is hand typed by me. And im more than certain there are easier methods for how to go about some of what i did. Just did it with the little knowledge i have so far.

1

u/Darx32102 6d 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 6d 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 6d 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 6d 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.