A Day In Paradise - a text-based adventure

Hello coding world!

First post


Day 99 of learning how to code…

99 days ago I registered on Codecademy.com and started the Python 3 beginner course.
I did the course in the same fashion I play video games. I’m an achievement hunter.
After finishing the beginner course, I started HTML, CSS, Python intermediate courses and began to wonder if I could start a project of my own. Without the smooth guidance of Codecademy’s courses.

It was a tough realization, that finishing a course doesn’t necessarily mean I understand how to apply the new knowledge.
I came across Al Sweigart’s Automate the boring stuff with python which made me repeat and refine my understanding of the subjects I learned on Codecademy through simple programs and it gave me enough confidence to start my very first own program.
What a comfortable coincidence, Codecademy’s Computer Science career path wanted me to do exactly that.

A Day In Paradise - Portfolio Project

I had to decide, what kind of program to write.
Should it be a useful program to help me and my friends organize everyday tasks? Or should it be fun?
I’m a gamer in my free time and I always wanted to try writing my own game.
It became a text based adventure. Or digital novel.

A Day In Paradise

It’s a simple story and I would’ve made it much more complex but I realized:
This text based adventure was less coding, more writing and I am definitely not a writer.
The logic is quite simple: Pick this path and this text get’s printed. Pick another path and you can read a different text.
The code was messy and long so I decided to add functions.
It worked! And the code became much more readable.
I even added a little inventory section and seeing it work made me so proud!

pam_inv = {}
backpack = {}
home_inv = {1: "Keys", 2: "Phone", 3: "Wallet", 4: "Headphones", 
            5: "Charger", 6: "Laptop", 7: "Water", 8: "Food", 9: "Backpack"}

print("I need to pack my things quickly! What do I need?")
print("\n")
print(" Items nearby ".center(25, "#"))
for key, value in home_inv.items():
    print(str(key).ljust(20, "."), value.rjust(5, " "))
print("Press a number + ENTER to collect an item. To quit press Q + ENTER")
while True:
    choice = input()
    if choice.lower() == "q":
        break
    if choice.isdecimal() == False or (int(choice) < 1 or int(choice) > 9):
        print("Pick a number from 1 to 9 and press ENTER. To quit press Q + ENTER")
        continue
    if 9 not in pam_inv.keys() and (int(choice) >= 5 and int(choice) <= 8):
        print("You can't put this in your pockets. You need a backpack.")
        continue
    pam_inv.setdefault(int(choice), home_inv.get(int(choice)))
print(" Inventory: ".center(20, "#"))
for item in pam_inv.values():
    print(item.ljust(20, "."))

The code for the inventory section in-game

The game is far from finished but it gave me a lot of confidence.
If you want to see the game for yourself, check out this GitHub repository
Tomorrow is day 100 of my coding journey and there is yet so much to learn!
I love it!

print("Till next time!")

1 Like