r/madeinpython • • May 09 '21

2D Open world ASCII rpg written in Python 3, standard library

https://github.com/Ninedeadeyes/GrimeLore-Land-of-the-Heretic-Hand

For those that are interested in seeing how an 2d rpg is written using just the standard library. I also have a basic 'game engine' within MISC folder for those who want to make their own..

24 Upvotes

9 comments sorted by

4

u/SweetOnionTea May 10 '21

Very cool to see some of the old ASCII rpgs in modern time. There's definitely a bit of pythonic polish needed in your code though.

3

u/ninedeadeyes May 10 '21

thanks for the comment. Will definitely appreciate any feedback regarding my coding. I code for fun and I kind of make it up as I go along.

2

u/RojerGS May 10 '21

Shameless plug right here, I write some articles about writing Pythonic code at https://mathspp.com/blog/pydonts, but I'll look at the code and play with the game to see if I can give some explicit pointers.

Either way, great job! Keep up the good work :D

2

u/ninedeadeyes May 10 '21

Nothing shameless about trying to help someone else :) Def will have a look but because my main job has nothing to do with coding, I am not the most discipline of coders and just enjoy building 'game mechanics' with code.

2

u/RojerGS May 10 '21

IMO that's the best way to learn coding: building the things that you like. I must say I really loved opening the game and being greeted with that nice music intro and the ASCII art drawing itself! It was amusing!

I opened a random file (game engine.py – by the way, avoid file names with characters that are not latin letters, digits, or underscores) and by the end of the file I noticed you have 4 very similar if statements. There is this coding principle, DRY, that stands for "Don't Repeat Yourself". If you find yourself writing the (almost) exact same code repeatedly, then you probably could refactor the code. Sometimes that means creating a function to do what you want, or maybe rethinking the way your code works. In this particular example I am talking about, you have 3 lines of code under each of the if, and 2 of them are literally the same for each if, so you could already save some trouble if you removed those 2 lines of code from the 4 if and only do them after the 4 ifs.

This is not about being a purist: if you have repeated lines of code, when it comes the time that you want to change one of them, you will have to change all of them, and more often than not you will forget to do that, or make a typo, or whatever, and create a bug in your code! So try not to repeat yourself too much :D

Look for patterns in your code and try to redo those bits more programmatically.

That's just a random suggestion.

Good luck with the game! Please update it further :D What if I wanted to save my progress or maybe have the game recall that I don't want the music on (i.e. save "configurations").

2

u/ninedeadeyes May 10 '21 edited May 10 '21

When I find the time, I'll probably go through my code and see where I can do some refactoring. Sometimes I 'repeat myself' because at the time I couldn't think of another way of doing it for example, if you look at my settlement.py each settlement is an individual function which isn't very effective since I am repeating myself a lot.. Could have done it as an OOP but it was getting a bit complex and this was the easier/quicker solution ( even though not as efficient ) and thank you for your feedback, once I find some time will probably will add more elements for the game

2

u/RojerGS May 10 '21

Thanks a lot for sharing this! What did you use to create the executable of the game?

3

u/ninedeadeyes May 10 '21

Very very easy.. All you need to do is open powershell within the folder of your files and then type pyinstaller --onefile game.py and press enter

2

u/Zed-Hanok2585 Aug 23 '22

This is just what I was looking for to brighten my day! Great work!