Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from random import randint
- class Character(object):
- def __init__(self, name, health):
- self.name=name
- self.health=health
- self.max_health=health
- def printstatus(self):
- if self.health > 0:
- print(self.name,":", self.health, "hp")
- elif self.health <= 0:
- print(self.name, "Is Dead")
- def Menu(self):
- print("What would you like to do?")
- print("1. Attack")
- print("2. Heal")
- print("3. Magic Attack")
- print("___________________________")
- choice=str(input())
- if choice in ["Attack","attack","1"]:
- return 1
- elif choice in ["heal","Heal","2"]:
- return 2
- elif choice in ["Magic","magic","3"]:
- return 3
- def Attack(self,target): #deals 5-35 damage, 75% chance to hit , 2.5% chance for 2x damage.
- chancetohit=randint(1,101)
- damage = randint(15, 35)
- if chancetohit <= 25:
- print(self.name,"Missed")
- target.health += 0
- elif 26 < chancetohit < 95:
- print(self.name,"did",damage,"damage")
- target.health-=damage
- elif chancetohit >= 95:
- damage*=2
- print("Crit!",self.name," did ", damage, "damage")
- target.health -= damage
- def Magic(self,target): #deals 5-35 damage, 75% chance to hit , 2.5% chance for 2x damage.
- chancetohit=randint(1,101)
- damage = randint(10, 60)
- if chancetohit <= 40:
- print(self.name,"Missed")
- target.health += 0
- elif 40 < chancetohit < 95:
- print(self.name,"did",damage,"damage")
- target.health-=damage
- elif chancetohit >= 95:
- damage*=2
- print("Crit!",self.name," did ", damage, "damage")
- target.health -= damage
- def Heal(self):
- chancetocrit=randint(1,101)
- healamount = randint(10, 26)
- if chancetocrit < 95:
- if (self.health + healamount) < self.max_health:
- self.health+=healamount
- print(self.name, "Healed: ", healamount)
- elif (self.health + healamount) > self.max_health:
- self.health=self.max_health
- print(self.name, "Healed to full")
- elif chancetocrit >=95:
- healamount = healamount*2
- if (self.health + healamount) < self.max_health:
- self.health+=healamount
- print("Crit!",self.name, "Healed: ", healamount)
- elif (self.health + healamount) > self.max_health:
- self.health=self.max_health
- print("Crit!", self.name, "Healed to full")
- while True:
- charName1=""
- charName2=""
- while True:
- while charName1 == "":
- print("Player 1 What is your name?")
- charName1 = input()
- while charName2 == "":
- print("Player 2 What is your name?")
- charName2 = input()
- Player1=Character(charName1,randint(75,125))
- Player2=Character(charName2,randint(75,125))
- while Player1.health >= 1 and Player2.health >= 1 :
- turn=0
- for x in range(0,1000):
- print("*"*25)
- print("Turn: ", turn)
- Player1.printstatus()
- Player2.printstatus()
- print("*"*25)
- if Player1.health <=0:
- break
- if Player2.health <=0:
- break
- if turn % 2 == 0:
- print(Player1.name,"'s turn")
- option=Player1.Menu()
- turn+=1
- if option == 1:
- Player1.Attack(Player2)
- elif option == 2:
- Player1.Heal()
- elif option == 3:
- Player1.Magic(Player2)
- elif turn % 2 != 0:
- print(Player2.name+"'s turn")
- option = Player2.Menu()
- turn += 1
- if option == 1:
- Player2.Attack(Player1)
- elif option == 2:
- Player2.Heal()
- elif option == 3:
- Player2.Magic(Player1)
- while Player1.health >0 and Player2.health <= 0:
- print(Player1.name,"Is Victorious!")
- break
- while Player2.health >0 and Player1.health <= 0:
- print(Player2.name,"Is Victorious!")
- break
- while True:
- print("Do you want to play again? y/n")
- response=input()
- if response in ["y","Y","Yes","YES","yes"]:
- print("Restarting...")
- break
- elif response in ["n","N","No","NO","no"]:
- sys.exit("Quitting")
- else:
- print("invalid response")
- break
Advertisement
Add Comment
Please, Sign In to add comment