Guest User

Untitled

a guest
Jun 21st, 2022
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. import sys
  2. import random
  3.  
  4. class Creature:
  5. def __init__(self,name,level):
  6. self.name=name
  7. self.level=level
  8.  
  9. def defensive_roll(self):
  10. roll=random.randint(1,12)
  11. return(roll*self.level)
  12.  
  13.  
  14. class Dragon(Creature):
  15. def __init__(self,name,level,scales,breath_fire):
  16. super().__init__(name,level)
  17. self.scales=scales
  18. self.breath_fire=breath_fire
  19.  
  20. def breath_weapon(self):
  21. return(random.randint(1,12)*self.level)
  22.  
  23. def defensive_roll(self):
  24. roll=random.randint(1,12)
  25. value=roll*self.level
  26. if self.scales>=roll:
  27. value=value*2
  28. return(value)
  29.  
  30. class Wizard(Creature):
  31. def __init__(self,name,level):
  32. super().__init__(name,level)
  33.  
  34. def attack(self,creature):
  35. my_roll=self.defensive_roll()
  36. creature_roll=creature.defensive_roll()
  37.  
  38. print("You roll {}...".format(my_roll))
  39. print("{} rolls {}...".format(creature.name,creature_roll))
  40. if(my_roll>=creature_roll):
  41. print("The wizard has handily triumphed over {}".format(creature.name))
  42. return True
  43. else:
  44. print("The wizard has been DEFEATED!!!")
  45. return False
  46.  
  47. class SmallAnimal(Creature):
  48. def __init__(self,name,level):
  49. super().__init__(name,level)
  50.  
  51. def defensive_roll(self):
  52. roll=random.randint(1, 12)
  53. value=roll*self.level
  54. if 2>=roll:
  55. value=value*2
  56. return(value)
  57.  
  58. class BigAnimal(Creature):
  59. def __init__(self,name,level):
  60. super().__init__(name,level)
  61.  
  62. def main():
  63. print("The Adventure Begins")
  64. creatures=[SmallAnimal("Toad",1),BigAnimal("Tiger",12),Dragon("Dragon",50,75,False),Wizard("Evil Wizard",15)]
  65. hero=Wizard("Gandalf",75)
  66. while True:
  67. active_creature=random.choice(creatures)
  68. print("A {} of level {} has apeared from a dark and foggy forest...".format(active_creature.name,active_creature.level))
  69. print()
  70. cmd=input("Do you [a]ttack, [r]un away, or [l]ook around? ")
  71. if cmd=="a":
  72. if hero.attack(active_creature):
  73. creatures.remove(active_creature)
  74. else:
  75. print("The wizard runs and hides taking time to recover...")
  76. time.sleep(5)
  77. print("The wizard returns revitalized!")
  78. elif cmd=="r":
  79. print("The wizard has become unsure of his power and flees!!!")
  80. elif cmd=="l":
  81. print("The wizard {} takes in the surroundings and sees:".format(hero.name))
  82. for c in creatures:
  83. print(" * A {} of level {}".format(c.name,c.level))
  84. else:
  85. print("OK, exiting game... bye!")
  86. break
  87.  
  88. if __name__=="__main__":
  89. main()
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment