Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- from itertools import count
- 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")
- def one_move(attacker, defender):
- print(attacker.name,"'s turn")
- option=attacker.Menu()
- if option == 1:
- attacker.Attack(defender)
- elif option == 2:
- attacker.Heal()
- elif option == 3:
- attacker.Magic(defender)
- def game():
- charName1 = input("Player 1 What is your name?")
- charName2 = input("Player 2 What is your name?")
- Player1=Character(charName1,randint(75,125))
- Player2=Character(charName2,randint(75,125))
- for turn in count(1):
- print()
- print("*"*25)
- print("Turn: ", turn)
- Player1.printstatus()
- Player2.printstatus()
- print("*"*25)
- if Player1.health <=0:
- print(Player2.name,"Is Victorious!")
- break
- if Player2.health <=0:
- print(Player1.name,"Is Victorious!")
- break
- if turn % 2 == 0:
- one_move(Player1, Player2)
- else:
- one_move(Player2, Player1)
- def main():
- game()
- while True:
- print("Do you want to play again? y/n")
- response=input()
- if response in ["y","Y","Yes","YES","yes"]:
- print("Restarting...")
- game()
- elif response in ["n","N","No","NO","no"]:
- print("Quitting")
- break
- else:
- print("invalid response")
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment