Hacktoberfest 01: A Python Game

André Rosa
Oct 5 · 2 min read

This is my first try in the Hacktoberfest challenge. I selected a Python app because this is a topic I have not learned in Seneca classes. The project is in: https://github.com/WIU-Computer-Science-Association/typyboi

Firstly, I contacted the maintainer to ask for the opportunity to work on this issue. When he told me I was allowed to proceed I forked/cloned the repo and worked from my desktop. The problem was to create a new game item, healing potions, to do so I had to:

1) Setup the Python environment, as Python 2.7 and 3+ has some incompatibilities and I did not find in the project which version he was using, I tried Python 3.7 and it worked fine.

2) To code the solution, I had to work with classes and inheritance. Also, I had to change code in two different files as the maintainer asked me not only to create the new item but make the player use the healing potion and recover player’s life

3) In the end, I created the new class and three support functions to: use the healing item, remove item used and list available healing potions. To succeed I had to study about Python subclasses, loops and how functions pass parameters (reference, copy)

4) As the original code had some path issues when running locally (maybe the original was meant for Linux), I had to change some imports and then change them back to original before committing.

5) The last problem I faced was that the game is not ready yet, therefore I had to create a Python script to test the modifications I made. As this was not part of the issue, I did not commit the test script to the branch.

After creating the pull request, located in: https://github.com/WIU-Computer-Science-Association/typyboi/pull/8

I wrote to the maintainer to explain the modifications I made (in total 50+ lines of code):

Dear Ethan,

1 — Added subclass of Item named HealingItem

2 — On player class (line 2) imported the HealingItem

3 — Added function on Inventory class to get all healing items (function get_healing_item_list) like function to get weapons (get_weapon_list)

4 — Added function use_heal_item to allow player to use healing items, this function calls add-hp to heal the player.

5 — I had an issue with this Healing Item, probably it will be consumed when used, therefore it is necessary to delete the item from the player inventory. To delete the item from the list, I created the method delete_inventory_item from class Inventory. This method is called right after adding the hp to player in use_heal_item

André Rosa

Written by

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade