Firetruckyou098

Testturnbasedgame

Jan 30th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.00 KB | None | 0 0
  1. import sys
  2. from random import randint
  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. while True:
  80.     charName1=""
  81.     charName2=""
  82.  
  83.     while True:
  84.         while charName1 == "":
  85.             print("Player 1 What is your name?")
  86.             charName1 = input()
  87.         while charName2 == "":
  88.             print("Player 2 What is your name?")
  89.             charName2 = input()
  90.         Player1=Character(charName1,randint(75,125))
  91.         Player2=Character(charName2,randint(75,125))
  92.         while Player1.health >= 1 and Player2.health >= 1 :
  93.  
  94.             turn=0
  95.             for x in range(0,1000):
  96.                 print("*"*25)
  97.                 print("Turn: ", turn)
  98.                 Player1.printstatus()
  99.                 Player2.printstatus()
  100.                 print("*"*25)
  101.                 if Player1.health <=0:
  102.                     break
  103.                 if Player2.health <=0:
  104.                     break
  105.                 if turn % 2 == 0:
  106.                     print(Player1.name,"'s turn")
  107.                     option=Player1.Menu()
  108.                     turn+=1
  109.  
  110.                     if option == 1:
  111.                         Player1.Attack(Player2)
  112.  
  113.  
  114.                     elif option == 2:
  115.                         Player1.Heal()
  116.  
  117.                     elif option == 3:
  118.                         Player1.Magic(Player2)
  119.  
  120.                 elif turn % 2 != 0:
  121.                     print(Player2.name+"'s turn")
  122.                     option = Player2.Menu()
  123.  
  124.                     turn += 1
  125.  
  126.                     if option == 1:
  127.                         Player2.Attack(Player1)
  128.  
  129.  
  130.                     elif option == 2:
  131.                         Player2.Heal()
  132.  
  133.                     elif option == 3:
  134.                         Player2.Magic(Player1)
  135.  
  136.  
  137.  
  138.         while Player1.health >0 and Player2.health <= 0:
  139.             print(Player1.name,"Is Victorious!")
  140.             break
  141.  
  142.         while Player2.health >0 and Player1.health <= 0:
  143.             print(Player2.name,"Is Victorious!")
  144.             break
  145.         while True:
  146.             print("Do you want to play again? y/n")
  147.             response=input()
  148.             if response in ["y","Y","Yes","YES","yes"]:
  149.                 print("Restarting...")
  150.                 break
  151.             elif response in ["n","N","No","NO","no"]:
  152.                 sys.exit("Quitting")
  153.             else:
  154.                 print("invalid response")
  155.         break
Advertisement
Add Comment
Please, Sign In to add comment