Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

I would like some feedback on my script

Hello, I would like people to throw some feedback about my "game"

import os
import random
import sys

version = '\n Harry Potter duel V0.1'

enter = "\n Press Enter to start the duel !"

miss_spell = (0, 1, 2, 4)

decor = ' ==========================='

believe = " Remember Harry ! if you don't truly believe that you can do it your spell won't work ! BELIEVE HARRY !!!"

missed_spells = 0

spell_check = -1

motivational_quotes_0 = [' Hold on Harry your parents are in your side !!', ' Harry this is it keep going !!']
motivational_quotes_1 = [' Destroy him once and for all !!', ' Your mother and father would be proud..']

random_motiv = [0, 1]

duel_sp = """\n
 1. Avada Kedavra
 2. Vasanous
 3. Crucio
"""
                                        #Make a door fall on harry, if spell != alonhamora then exit the game, and other situations with situational spells
situational_sp = """\n
 4. Arresto Momentum
 5. Aqua Eructo
 6. Arania Exumai
"""
                                        #Refactor the code
                                        #Find something fun to add !
spell_list = """
 DUEL Spells: {}
 SITUATIONAL Spells: {}
""".format(duel_sp, situational_sp)

harry_potter = 20
voldemord = 25

def clear():
    os.system("cls" if os.name == "nt" else "clear")

def intro():
    clear()
    print(version)
    print("\n Harry's Life Points: {}".format(harry_potter))
    print(decor + "\n Voldemord's Life Points: {}\n".format(voldemord))
    print(" You are the famous Harry Potter and you are about to duel your\n destined enemy to death, his name is 'You know who..'")
    print(" Remember Harry ! if you don't truly believe that you can do it\n your spell won't work ! BELIEVE HARRY !!!")
    print("\n\n\n 'Hold your wands, because this is about to become as hard as trying to avoid a bludger ball in a quidditch game !'")
    input(enter + ' > ')
    spell_duel()

def spell_duel():

    global spell_check
    global missed_spells
    global voldemord
    clear()
    print(version)
    print("\n Harry's Life Points: {}".format(harry_potter))
    print(decor + "\n Voldemord's Life Points: {}".format(voldemord))
    print(spell_list)

    if spell_check != missed_spells - 1:
        spell_check += 1
        print(believe)

    print(' Type the number before the spell to use it !')

    spell = int(input('\n > '))

    if isinstance(spell, int):

        if random.choice(miss_spell) == 1:
            missed_spells += 1
            print("\n You missed your spell Harry !! BELIEVE in yourself, I believe in you, only you can do it.. END HIS MISERY !!!")
            print("\n It's voldemords turn now, press Enter to continue > ")
            voldemords_turn()
            spell_duel()
        else:

            the_word = ''

            for x in [1]:

                if random.choice(random_motiv) == 0:
                    the_word = random.choice(motivational_quotes_0)
                else:
                    the_word = random.choice(motivational_quotes_1)

            if spell == 1:

                print("\n AVADA KEDAVRA!!")
                print('\n' + the_word)
                hit = 7
                voldemord -= 7
                print(' Voldemord lost {} points'.format(hit))
                voldemords_turn()
                spell_duel()

            if spell == 2:

                print("\n VASANOUS!!")
                print('\n' + the_word)
                hit = 5
                voldemord -= 5
                print(' Voldemord lost {} points'.format(hit))
                voldemords_turn()
                spell_duel()

            if spell == 3:
                print("\n CRUCIOO!!")
                print('\n' + the_word)
                hit = 5
                voldemord -= 5
                print(' Voldemord lost {} points'.format(voldemord))
                voldemords_turn()
                spell_duel()


    else:
        print(" You should put a spell that is available on your spell book !")
        input(enter)
        spell_duel()

def voldemords_turn():

    global harry_potter
    spell_dmg = random.choice([6, 7, 8])
    print("\n VOLDEMORD: 'AAVADA KEDAVRA'\n Voldemord has striked you back successfully, you lost {} life points !".format(spell_dmg))
    harry_potter -= spell_dmg
    input("\n > ")

    if random.choice([0, 1, 2]) == 1:
        print("\n Your mother's love protected you once again.. she absorbed 4 hit point from voldemords spell !")
        print("\n VOLDEMORD: Mother's love, disgusting.. next time you shall not be spared !") 
        input("\n Press Enter to return to the duel > ")
        harry_potter += 4

    if harry_potter < 1:
        clear()
        print(version)
        print("\n Harry's Life Points: {}".format(harry_potter))
        print(decor + "\n Voldemord's Life Points: {}".format(voldemord))
        print("\n You didn't believe enough in yourself Harry... there is no second chances.. ('except if you restart the game manually hehehe')")
        input("\n Press Enter to exit the game > ")
        sys.exit()

if __name__ == '__main__':
    intro()

Regards Penguin

ohh by the way.. HARRY POTTER FOR LIFE!!

2 Answers

Keith Whatling
Keith Whatling
17,759 Points

I would put the following code in a function call for the printing, anytime you repeat code means it can almost always be sent to a function.

            if spell == 2:

                print("\n VASANOUS!!")
                print('\n' + the_word)
                hit = 5
                voldemord -= 5
                print(' Voldemord lost {} points'.format(hit))
                voldemords_turn()
                spell_duel()

Even better with Classes, this could be a method, so Voldemord.hit(random.randint(0,5)) could decrease his health by X, print the hit to the screen, print(' Voldemord lost {} points'.format(hit)) and check for misses based on some other bit of his class.

Do the dungeon game in python classes. You'll love it!

I will surely do the dungeon game :) I skipped it because it felt unimportant but I will do it ! thanks for the heads up man, I really appreciate it, I hope you have a beautiful day!

Keith Whatling
Keith Whatling
17,759 Points

Fantastic!

Ok so if I have to go for some "Even Better Ifs": Game wise, it would be nice to know what the difference between situational spells and attack ones are. if it just went straight into the next round rather than pressing enter.

For Coding, good job but I have some ideas If you used Classes and made the code object based you could build a game that had a lot more verity, more characters and greater scope.

Classes and making games just go so beautifully together, I can't wait to see the next version. Maybe you could combine the game you have here with Kevin Loves dungeon game, Harry could be walking around the maze in the goblet of fire.

Please share what you come up with.

Thank you soo much for your kind words.. well the situational spells are going to be used on my next version which before the actual duel there is going to be a chance of 1 out of 5 to maybe bring a big spider, the user will need to use the spells available that match with the situation, maybe a iron door could come flying towards you and you might need to open it with Alonhamora ahahaha who knows.. I was thinking of saving this and making a actual game which will look like the fighting scenes from pokemon, in one side harry in the other voldemord, it initially crossed my mind to use classes but at the start this was going to be a tiny project but I expanded it the same day.

Anyways thank you so much Keith !

I see... I should have used elif but I forgot about it, thanks for reminding me :) by the way this is like the prototype I just made it today, that's why I left the other spells untouched. and the pressing enter inputs are in my opinion better than doing time.sleep() since the screen is clearing kinda instantly I got the choice to the user to either quick forward or to read the text.

I will definetly do my next mini game with harry potter which is going to be kind of a story using classes so I can practice a bit more.