Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import random
- import time
- os.system('clear')
- php = 60
- maxphp = 30
- Ghp = random.randint(20,60)
- maxghp = Ghp
- mmsl = 2 # Define these variables, what do they do?
- fbsl = 4 # Same for this one, what does this do?
- print('A wild Goblin appears Snarling, getting ready to attack. What do you do?')
- time.sleep(2)
- while Ghp > 0 and php > 0: # While both player and golbin are alive
- turnreset = 0 # Make a comment for this one. It is not immediately clear what it does.
- print('it is your turn what do you do. You have '+str(php) +' hp') # This is good, but you can also look at string foratting:
- # https://realpython.com/python-f-strings/
- Action = str(input('to make an action type: firebolt, magic missile, bow, longsword or heal '))
- os.system('clear')
- if Action == 'firebolt':
- if fbsl > 0:
- fireboltdmg=random.randint(1,10)+2
- fbar = random.randint(1,20)+2 # Why + 2?
- fbsl = fbsl - 1 # This is some sort of mana? (got this from league)
- if fbar > 15:
- Ghp = Ghp-fireboltdmg
- print('your firebolt hit the goblin doing '+str(fireboltdmg) +' damage')
- else:
- print ('your firebolt missed')
- else:
- print('as you try to conjure the magical energy required to cast firebolt you fail, you can\'t cast firebolt anymore.')
- turnreset = 1 # Define this too.
- elif Action == 'magic missile':
- if mmsl > 0:
- mmd = random.randint(3,12)+6
- Ghp = Ghp-mmd
- print('your magic missiles hit the goblin doing ' +str(mmd) +' damage')
- mmsl = mmsl - 1
- else:
- print('as you try to conjure the magical energy required to cast magic missile you fail, you can\'t cast magic missile anymore.')
- turnreset = 1
- elif Action == 'bow':
- bd = random.randint(1,8)+2
- bar = random.randint(1,20)+2
- if bar > 15:
- Ghp = Ghp-bd
- print('your arrow slammed into the goblin\'s shoulder and did ' +str(bd) +' damage')
- else:
- print('you shot an arrow at the goblin and missed')
- elif Action == 'longsword':
- lsd = random.randint(1,12)
- lsar = random.randint(1,20)+2 # Chance that you are going to attack
- if lsar > 15:
- Ghp = Ghp - lsd
- print('you slash at the goblin and hit dealing ' + str(lsd) +' damage')
- else:
- print('you slash at the goblin and miss')
- elif Action == 'heal':
- heal = random.randint(1,8)
- php = php+heal
- print('you heal your wounds restoring ' +str(heal) +' health')
- if php > maxphp:
- php = maxphp
- else:
- print('please enter a valid action and be sure not to type anything until the list prompt pops up, that causes an error and you have to wait again')
- turnreset=1
- time.sleep(5)
- print('you have ' +str(php) + ' health left')
- # Goblin's turn to attack
- time.sleep(3)
- os.system('clear')
- if turnreset == 0: # If the player did not perform an action
- if Ghp/maxghp > 0.8:
- Gaction = random.randint(1,7)
- if Gaction == 7:
- Ghp = Ghp + random.randint(1,4)
- elif Gaction <= 3:
- gar = random.randint(1,20)+1
- if gar > 13:
- gdmg = random.randint(1,8)+3
- php = php - gdmg
- print('the goblin stabs at you hits and deals ' + str(gdmg) +' damgage')
- else:
- print('the goblin tries to stab at you, but the goblin misses')
- else:
- gar = random.randint(1,20)+3
- gdmg = random.randint(1,12)+3
- if gar > 13:
- php = php - gdmg
- print('the goblin draws back it\'s longbow\'s string and releases, the arrow flies into your leg dealing ' +str(gdmg) +' damage')
- else:
- print('the goblin draws back it\'s longbow\'s string and releases, the arrow flies right past you doing nothing')
- elif Ghp/maxghp > 0.5 and Ghp/maxghp < 0.8:
- Gaction = random.randint(1,5)
- if Gaction < 3:
- gar = random.randint(1,20)+1
- if gar > 13:
- gdmg = random.randint(1,8)+3
- php = php - gdmg
- print('the goblin stabs at you hits and deals ' + str(gdmg) +' damgage')
- else:
- print('the goblin tries to stab at you, but the goblin misses')
- elif Gaction < 5:
- gar = random.randint(1,20)+3
- gdmg = random.randint(1,12)+3
- if gar > 13:
- php = php - gdmg
- print('the goblin draws back it\'s longbow\'s string and releases, the arrow flies into your leg dealing ' +str(gdmg) +' damage')
- else:
- print('the goblin draws back it\'s longbow\'s string and releases, the arrow flies right past you doing nothing')
- else:
- gheal = random.randint(1,4)
- Ghp = Ghp + gheal
- print('the goblin tends to it\'s wounds for a moment healing ' +str(gheal) +' hitpoints')
- # I would check here if the goblin's health is more than his maximum:
- # if Ghp > maxghp:
- # Ghp = maxghp
- elif Ghp/maxghp > 0.3:
- Gaction = random.randint(1,3)
- if Gaction == 3:
- gar = random.randint(1,20)+3
- gdmg = random.randint(1,12)+3
- if gar > 13:
- php = php - gdmg
- print('the goblin draws back it\'s longbow\'s string and releases, the arrow flies into your leg dealing ' +str(gdmg) +' damage')
- else:
- print('the goblin draws back it\'s longbow\'s string and releases, the arrow flies right past you doing nothing')
- elif Gaction == 2:
- gar = random.randint(1,20)+1
- if gar > 13:
- gdmg = random.randint(1,8)+3
- php = php - gdmg
- print('the goblin stabs at you hits and deals ' + str(gdmg) +' damgage')
- else:
- print('the goblin tries to stab at you, but the goblin misses')
- else:
- gheal = random.randint(1,5)
- Ghp = Ghp + gheal
- print('the goblin tends to it\'s wounds for a moment healing ' +str(gheal) +' hitpoints')
- else:
- gheal = random.randint(1,5)
- Ghp = Ghp + gheal
- print('the goblin tends to it\'s wounds for a moment healing ' +str(gheal) +' hitpoints')
- if Ghp > maxghp:
- Ghp = maxghp
- time.sleep(4)
- os.system('clear')
- if Ghp <= 0: # I would check if the goblin is dead before he does any action. That way he dies immediately before healing itself.
- print('the goblin falls to the ground, dead.')
- print('congratulations YOU WIN')
- else:
- print('the goblin has dealt the final blow, you lay on the ground unconscious')
- print('YOU DIED')
- print('GAME OVER')
- time.sleep(5)
- os.system('clear')
- exit()
- # Hey Andrew! This game is really awesome and the physics of it are actually really well thought. I am happy you spent some time
- # At home practicing. This is actually what I wanted to do on Thursday with the class, a text based RPG.
- # The game works very well and I am actually quite impressed. One thing you need to make sure that you do is to add comments.
- # Comments help people like me revise your code and understand better what it does. Even though I could understand it, it
- # would have taken me less time to and would have been easier :) I wrote some comments in the code where I think you should change
- # Some things, so make sure to read those.
- # I think you understand the logic pretty well, but to me the obvious next step would be to add functions. I am not going to explain
- # what they are here, but you can try look them up. Unfortunately I don't think we'll cover them in class this Thursday
- # since other people are still not at this level.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement