Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import time
- import os
- php = 50
- phpmax = 50
- pdefence = 14
- pactions = ['attack','upgrade']
- pattackmax = 10
- enemydefense = 0
- pdamg = 0
- # Logic for the turn of the player
- def playerturn(pdamg, pattackmax, enemydefense):
- print('it is your turn what do you do')
- print('possible actions are ' +str(pactions))
- action = input('please type an action ')
- if action == 'attack':
- atkrll = random.randint(1,20)+2 # Generating a number between 1 and 20.
- if atkrll >= enemydefense: # 7/20 chance he is going to hit
- pdamg = random.randint(1,pattackmax) # Attack damage of player
- print('you hit your enemy dealing ' +str(pdamg) +' damage')
- else:
- print('you attacked your enemy and missed')
- elif action == 'upgrade':
- print('In function before', pattackmax)
- pattackmax += 1 # To revise
- print('In function after', pattackmax)
- print('you spend some time sharpening your blade, you can now deal a maximum of ' +str(pattackmax) +' damage in one attack')
- def enemyfight(coheal,ctsattack,cthit,ehp,adamagemax,hamountmax,name,armour, php, pdamg):
- while(True):
- ehpmax = ehp # Enemy max hit points are full
- if ehp > 0:
- pdamg = 0
- print('Before function call', pattackmax)
- playerturn(pdamg, pattackmax, armour)
- ehp -= pdamg
- #convert chance to heal to 100 minus the chance so that I can check independently for healing and special attack
- coheal = 100 - coheal
- #generate number between 1 and 100 to determine action
- action = random.randint(1,100)
- if action >= coheal and ehp < ehpmax:
- #making sure the enemy does not heal at full health
- if ehp < ehpmax:
- heal = random.randint(1,hamountmax)
- ehp = ehp + heal
- healtext = f'{name} tends to it\'s wounds for a moment healing itself'
- print(healtext)
- # making sure the enemy's health is not over the maximum
- if ehp > ehpmax:
- ehp = ehpmax
- #checking to see whether the attack is critically hitting
- elif action <= ctsattack:
- #dealing twice the amount of damage than a normal attack
- damage = random.randint(1,adamagemax)*2
- php -= damage
- satktxt = f'{name} struck you with a critically hitting attack, dealing twice as much damage, it did {damage} damage'
- print(satktxt)
- else:
- # try to hit enemy and add the to hit bonus
- accuracy = random.randint(1,20)+cthit
- if accuracy >= pdefence:
- damage = random.randint(1,adamagemax)
- #deal damage
- php -= damage
- atktxt = f'{name} attacks you and deals {damage} damage'
- print(atktxt)
- #take away the amount of hitpoints that the enemy does damage
- else:
- txt=f'{name} attacked you and missed'
- print(txt)
- else:
- print('you killed your enemy')
- break
- os.system('clear')
- # Create enemy
- enemyfight(10,4,1,50,10,10,'potatoman',13, php, pdamg)
- # Hey Andrew, once again, really nice game and good use of functions. This time you put comments which is good, but I would put them differently.
- # A good practice is to always put a comment above every function to explain exactly what it does. Most of the times, the name implies what the
- # Function does, but it makes it much more clear. Furthermore, whenever you create a new variable, explain what it is. That is really important to
- # Do. When you created the variable "ehpmax" it took me just a little longer to understand what it is. I figured out that you use "hp" for hitpoints,
- # But I would not have to if you put a comment. (Programmers are very lazy, and don't want to think too much ;). When you write comments think about
- # A programmer that has never made a game before. Everyone thinks differently, and so you must use comments to explain your train of thought.
- # I would also avoid global variables. It is unbelievably easy to mix global variables up and it is a best practice not to have too many global variables.
- # You can see that I got rid of them and instead passed them as arguments in other functions. It is going to be a real pain debugging when there is a problem
- # With global variables.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement