DEV Community

Ciara Cloud
Ciara Cloud

Posted on

I Made My First RPG in Python

To start, I don't know if playing an RPG in the terminal on your computer will fulfill the full RPG experience. However, building this game in python allowed me to dissect the process of how more complex RPG games are constructed.

The overall goal of my game is to win a battle against the enemy, Vivian, so that the user can make it to their interior design interview and get the job! The user can choose which character they would like to be during their battle against Vivian. I created a class to make each character and give them their own attributes, such as their own name, starting health level, strength level, and attack options. All characters and their attributes are displayed by invoking a function that I created to print the character menu. From there, the user can input which character they would like to be and the game will continue with that character. Once the user is in the battle with Vivian, they can choose which attack option(s) to use against her and the game will continue until a winner is chosen. I made this possible by creating a game loop that allows the user to attack Vivian and for Vivian to attack back until either one of their health levels reach 0 or below.

If the user does not put in the correct information, the game will not continue until they have provided a choice from the options that are given. This is where I had the most trouble in my code. At one point I thought I was finished creating my game until I did a few test runs and noticed that when I put in the wrong information, the game would not continue as I wanted it to. Having to go back into my code and fix these errors ultimately led to me finding a more efficient way to write my code. For example, initially, I had a lot of repeated code, so when an error would happen, I would have to go back to each repeated line of code and change it in order to find the issue. I quickly realized how inefficient this was and found a way to eliminate the repeated lines by taking some code out of loops and making some information dynamic. Ultimately, I removed approximately 200 lines of code from my file and the game worked even better than it did originally (after I fixed the errors, of course)!

Overall, I had a lot of fun making this RPG! My favorite part of creating the game was that the whole process felt as if I was playing a coding game in Python. I would be coding along and then BAM, I was battling a while loop or else statement that wasn't executing properly. Each time I solved an issue in my code and got it working the way I wanted it to, I would do a mini dance to celebrate my victory (for my cat's eyes only)!

If given more time, I would expand this game into an interior design game that gives the users a certain amount of money and the ability to shop/design for different characters. But, that's for another day!

If you'd like to test my game, here's the link to my github repository.

Latest comments (3)

Collapse
 
mccurcio profile image
Matt Curcio

I love those early RPG that were all about imagination. ;)

Collapse
 
iceorfiresite profile image
Ice or Fire

Looks pretty good for your first RPG.

Collapse
 
ciaracloud profile image
Ciara Cloud

Thank you so much!