Guest User

Untitled

a guest
Jan 30th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.12 KB | None | 0 0
  1. from random import randint
  2. from itertools import count
  3.  
  4. class Character(object):
  5.     def __init__(self, name, health):
  6.         self.name=name
  7.         self.health=health
  8.         self.max_health=health
  9.  
  10.     def printstatus(self):
  11.         if self.health > 0:
  12.             print(self.name,":", self.health, "hp")
  13.         elif self.health <= 0:
  14.             print(self.name, "Is Dead")
  15.     def Menu(self):
  16.         print("What would you like to do?")
  17.         print("1. Attack")
  18.         print("2. Heal")
  19.         print("3. Magic Attack")
  20.         print("___________________________")
  21.         choice=str(input())
  22.         if choice in ["Attack","attack","1"]:
  23.             return 1
  24.         elif choice in ["heal","Heal","2"]:
  25.             return 2
  26.         elif choice in ["Magic","magic","3"]:
  27.             return 3
  28.  
  29.     def Attack(self,target): #deals 5-35 damage, 75% chance to hit , 2.5% chance for 2x damage.
  30.         chancetohit=randint(1,101)
  31.         damage = randint(15, 35)
  32.         if chancetohit <= 25:
  33.             print(self.name,"Missed")
  34.             target.health += 0
  35.         elif 26 < chancetohit < 95:
  36.  
  37.             print(self.name,"did",damage,"damage")
  38.             target.health-=damage
  39.         elif chancetohit >= 95:
  40.             damage*=2
  41.             print("Crit!",self.name," did ", damage, "damage")
  42.             target.health -= damage
  43.  
  44.     def Magic(self,target): #deals 5-35 damage, 75% chance to hit , 2.5% chance for 2x damage.
  45.         chancetohit=randint(1,101)
  46.         damage = randint(10, 60)
  47.         if chancetohit <= 40:
  48.             print(self.name,"Missed")
  49.             target.health += 0
  50.         elif 40 < chancetohit < 95:
  51.             print(self.name,"did",damage,"damage")
  52.             target.health-=damage
  53.         elif chancetohit >= 95:
  54.             damage*=2
  55.             print("Crit!",self.name," did ", damage, "damage")
  56.             target.health -= damage
  57.  
  58.  
  59.     def Heal(self):
  60.         chancetocrit=randint(1,101)
  61.         healamount = randint(10, 26)
  62.         if chancetocrit < 95:
  63.  
  64.             if (self.health + healamount) < self.max_health:
  65.                 self.health+=healamount
  66.                 print(self.name, "Healed: ", healamount)
  67.             elif (self.health + healamount) > self.max_health:
  68.                 self.health=self.max_health
  69.                 print(self.name, "Healed to full")
  70.         elif chancetocrit >=95:
  71.             healamount = healamount*2
  72.             if (self.health + healamount) < self.max_health:
  73.                 self.health+=healamount
  74.                 print("Crit!",self.name, "Healed: ", healamount)
  75.             elif (self.health + healamount) > self.max_health:
  76.                 self.health=self.max_health
  77.                 print("Crit!", self.name, "Healed to full")
  78.  
  79. def one_move(attacker, defender):
  80.     print(attacker.name,"'s turn")
  81.     option=attacker.Menu()
  82.     if option == 1:
  83.         attacker.Attack(defender)
  84.     elif option == 2:
  85.         attacker.Heal()
  86.     elif option == 3:
  87.         attacker.Magic(defender)
  88.  
  89. def game():
  90.     charName1 = input("Player 1 What is your name?")
  91.     charName2 = input("Player 2 What is your name?")
  92.     Player1=Character(charName1,randint(75,125))
  93.     Player2=Character(charName2,randint(75,125))
  94.  
  95.     for turn in count(1):
  96.         print()
  97.         print("*"*25)
  98.         print("Turn: ", turn)
  99.         Player1.printstatus()
  100.         Player2.printstatus()
  101.         print("*"*25)
  102.         if Player1.health <=0:
  103.             print(Player2.name,"Is Victorious!")
  104.             break
  105.         if Player2.health <=0:
  106.             print(Player1.name,"Is Victorious!")
  107.             break
  108.         if turn % 2 == 0:
  109.             one_move(Player1, Player2)
  110.         else:
  111.             one_move(Player2, Player1)
  112.  
  113. def main():
  114.     game()
  115.     while True:
  116.         print("Do you want to play again? y/n")
  117.         response=input()
  118.         if response in ["y","Y","Yes","YES","yes"]:
  119.             print("Restarting...")
  120.             game()
  121.         elif response in ["n","N","No","NO","no"]:
  122.             print("Quitting")
  123.             break
  124.         else:
  125.             print("invalid response")
  126.  
  127. if __name__ == '__main__':
  128.     main()
Advertisement
Add Comment
Please, Sign In to add comment