DEV Community

Cover image for That’s A Hat
Meg
Meg

Posted on • Updated on

That’s A Hat

In creating my first Python game I originally was at a loss for what to do.

Inherently I prefer world building stories, but in pondering a base idea my brain finally supplied a picture of the Felix the Cat animated movie and how his bag could turn into anything to help him defeat his adversaries.

I decided I wanted my game to be based on having a magic hat that you could pull things out of that would help the hero. But the question was, help the hero do what. I decided that instead of a battle, I wanted the hero to be running from the police.

I liked the idea of skirting the rules in not really having bad guys, since the police are running after someone innocent. I also liked the idea of having no outward physical violence, instead using the object as a distraction or eating the object to change the health of the hero to advance the game. 

To give the game boundaries, I gave each of the five hat options only five items (which related to the style of hat it was) and after ten turns the player automatically lost, although the game could be won or lost after two turns.

I wanted all the items in the hat to be edible as well as useable as distractions for the humor of it, even though eating a real vespa might be rather difficult. (It’s magic!) Each item pulled from the hat was random and could either take health away or add health randomly as well. Eating the item had the possibility to lose more health than using the item as a distraction, but it could also gain the hero more health for their risk.

Tricky aspects of the code were deciding to make the police reactions random, but tying them to the amount of health lost or gained. Originally their reactions and the amount of health lost or gained were all random, but I felt that having the police “unmoved” but gaining 30 health didn’t make logical sense.

I also had to play with the logic for what happened when the hero had gone through all the items in their hats. I decided it was an immediate loss, and instead of deleting the first hat item array from the nested array when the hat was empty, I moved it to the end so I could check to see if the two nested arrays were both empty and if so, end the game.

Overall this was my first game created in Python and I’m pleased with the way it turned out.

Link to game: https://replit.com/@Meg-Div/Thats-A-Hat#main.py

Link to code: https://github.com/Meg-Div/DigitalCraftsProjects/tree/main/rpg-game

Top comments (1)

Collapse
 
michaeltharrington profile image
Michael Tharrington

Love it!!

But woaa, I can't believe I wasn't able to distract the police with the baguette that I pulled outta my beret. 🤷

A screenshot from the game "That's a Hat". You can see the various decisions I've made thus far in the game including to try and distract the police with a baguette that I pulled outta my beret, a hat that I chose earlier in the game.