Advertisement
cipheron

GPT written RPG v3 - Final

Jan 7th, 2023 (edited)
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. import random
  2.  
  3. class Creature:
  4. def __init__(self, name, attack, defense, health, char_class=None):
  5. self.name = name
  6. self.char_class = char_class
  7. self.attack = attack
  8. self.defense = defense
  9. self.health = health
  10. self.max_health = health
  11.  
  12. def take_damage(self, damage):
  13. self.health -= damage
  14. if self.health < 0:
  15. self.health = 0
  16.  
  17. def is_dead(self):
  18. return self.health == 0
  19.  
  20. # Class choices
  21. class_choices = [
  22. ["Warrior", 10, 5],
  23. ["Mage", 5, 10],
  24. ["Rogue", 7, 7]
  25. ]
  26.  
  27. # Monster choices
  28. monster_choices = [
  29. ["Orc", 15, 0, 50],
  30. ["Troll", 10, 5, 75],
  31. ["Goblin", 5, 5, 25]
  32. ]
  33.  
  34. # Create character
  35. print("You are trapped in a dungeon and must fight your way out!")
  36. print("Choose your class:")
  37. for i, c in enumerate(class_choices):
  38. print(f"{i+1}: {c[0]} (Attack: {c[1]}, Defense: {c[2]})")
  39. choice = int(input()) - 1
  40. name = input("Enter your character's name: ")
  41. char_class = class_choices[choice][0]
  42. attack = class_choices[choice][1]
  43. defense = class_choices[choice][2]
  44. character = Creature(name, attack, defense, 200, char_class)
  45. healing_potions = 3
  46. gold = 0
  47. battles_won = 0
  48.  
  49. # Game loop
  50. while True:
  51. if battles_won == 5:
  52. print("You emerge from the dungeon, victorious!")
  53. print(f"You won {battles_won} battles, found {gold} gold, and have {healing_potions} healing potions left.")
  54. exit()
  55.  
  56. # Generate a random monster
  57. monster_choice = random.randint(0, len(monster_choices)-1)
  58. monster_name = monster_choices[monster_choice][0]
  59. monster_attack = monster_choices[monster_choice][1]
  60. monster_defense = monster_choices[monster_choice][2]
  61. monster_health = monster_choices[monster_choice][3]
  62. monster = Creature(monster_name, monster_attack, monster_defense, monster_health)
  63.  
  64. print(f"A wild {monster.name} appears!")
  65.  
  66. tried_to_flee = False
  67. while True:
  68. # Display stats
  69. print(f"{character.name} (Class: {character.char_class}, Health: {character.health}, Attack: {character.attack}, Defense: {character.defense})")
  70. print(f"{monster.name} (Health: {monster.health}, Attack: {monster.attack}, Defense: {monster.defense})")
  71.  
  72. # Display options
  73. print("Options:")
  74. print("1. Fight")
  75. if healing_potions > 0:
  76. print("2. Heal")
  77. if not tried_to_flee:
  78. print("3. Run")
  79. choice = int(input())
  80.  
  81. # Fight
  82. if choice == 1:
  83. # Character attacks monster
  84. monster.take_damage(character.attack)
  85. print(f"{character.name} attack the {monster.name} for {character.attack} damage")
  86. if monster.is_dead():
  87. print(f"{monster.name} has been defeated!")
  88. gold += random.randint(10, 20)
  89. if random.randint(1, 4) == 1:
  90. healing_potions += 1
  91. print(f"You found a healing potion! You now have {healing_potions}.")
  92. battles_won += 1
  93. character.health += random.uniform(0.25, 0.5) * character.health
  94. character.health = min(character.health, 100)
  95. tried_to_flee = False
  96. break
  97.  
  98. # Monster has a chance to run away
  99. if monster.health < 0.25 * monster.max_health:
  100. if random.randint(1, 2) == 1:
  101. print(f"{monster.name} ran away!")
  102. battles_won += 1
  103. gold += random.randint(10, 20)
  104. character.health += random.uniform(0.25, 0.5) * character.max_health
  105. character.health = min(character.health, character.max_health)
  106. tried_to_flee = False
  107. break
  108.  
  109. # Monster attacks character
  110. character.take_damage(monster.attack)
  111. print(f"{monster.name} attack {character.name} for {monster.attack} damage")
  112. if character.is_dead():
  113. print(f"{character.name} has been defeated :(")
  114. exit()
  115.  
  116. # Heal
  117. elif choice == 2:
  118. healing_potions -= 1
  119. character.health += 0.5 * character.max_health
  120. character.health = min(character.health, 100)
  121. print(f"You used a healing potion and healed for {int(0.5 * character.health)} health. You now have {healing_potions} healing potions left.")
  122.  
  123. # Run
  124. elif choice == 3:
  125. if random.randint(1, 2) == 1:
  126. print("You successfully fled!")
  127. tried_to_flee = False
  128. break
  129. else:
  130. print("You failed to flee.")
  131. tried_to_flee = True
  132.  
  133. # Automatic rest after battle
  134. if not character.is_dead():
  135. print(f"You rest after the battle and heal for {int(random.uniform(0.25, 0.5) * character.max_health)} health.")
  136. character.health += random.uniform(0.25, 0.5) * character.max_health
  137. character.health = min(character.health, character.max_health)
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement