The 'why'
As part of Codecademy's Computer Science course, the final project of the Python section wanted you to create a program to run in your terminal.
Your program could be a game, a calculator, a magic 8 ball etc..
I decided to expand on a previous project and create an old school text adventure. These were some of the first games I played on a computer and I loved them.
The Game
As you can see in the gif above, the program starts with a basic introduction. You are given some of the commands to play the game and then are asked for your name. The game starts with a wizard explaining what he wants you to do, and if you agree, your adventure begins.
During the game there will be items to find, objects and people to interact with and monsters to fight.
If you want to try it, you can find the code on my github page here.
The code
Your program had to contain at least 1 input command and a combination of classes and functions.
The input command looked like this:
heroes_name = input("\nPlease input your name and press enter to begin. : ")
I created two classes. One for the hero and one for the monsters.
class Adventurer:
def __init__(self, name, health = 30, gems = 0, inventory = ["sword"]):
self.name = name
self.health = health
self.gems = gems
self.inventory = inventory
def __repr__(self):
return "The name of this adventurer is {name}. {name}, with sword in hand, has bravely accepted the challenge to rid this dungeon of it's evil.".format(name = self.name)
class Monster:
def __init__(self, name, health):
self.name = name
self.health = health
def __repr__(self):
return "This is a {name}. It is a foul creature that has dwelled in this dungeon for far too long. It's health is {health}.".format(name = self.name, health = self.health)
The functions inside the classes were for using items and attacking enemies.
The functions outside of the classes were for:
- getting items
- examining objects
- giving items etc..
Conclusion
I really enjoyed this project. It took alot longer than I thought it would, probably because I kept rewriting parts of the game, but I am really pleased with the end result.
I know there are probably alot of parts that could be thinned out to make the code cleaner, but I am not at that level yet.
Thankyou for reading and happy coding.
Latest comments (0)