Advertisement
cipheron

GPT written RPG v2

Jan 7th, 2023 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. import random
  2.  
  3. # Creature class
  4. class Creature:
  5. def __init__(self, name, attack, defense, health, char_class=None):
  6. self.name = name
  7. self.char_class = char_class
  8. self.attack = attack
  9. self.defense = defense
  10. self.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("Choose your class:")
  36. for i, c in enumerate(class_choices):
  37. print(f"{i+1}: {c[0]} (Attack: {c[1]}, Defense: {c[2]})")
  38. choice = int(input()) - 1
  39. name = input("Enter your character's name: ")
  40. char_class = class_choices[choice][0]
  41. attack = class_choices[choice][1]
  42. defense = class_choices[choice][2]
  43. character = Creature(name, attack, defense, 100, char_class)
  44.  
  45. # Game loop
  46. while True:
  47. # Generate a random monster
  48. monster_choice = random.randint(0, len(monster_choices)-1)
  49. monster_name = monster_choices[monster_choice][0]
  50. monster_attack = monster_choices[monster_choice][1]
  51. monster_defense = monster_choices[monster_choice][2]
  52. monster_health = monster_choices[monster_choice][3]
  53. monster = Creature(monster_name, monster_attack, monster_defense, monster_health)
  54.  
  55. print(f"A wild {monster.name} appears!")
  56.  
  57. while True:
  58. # Display stats
  59. print(f"{character.name} (Class: {character.char_class}, Health: {character.health}, Attack: {character.attack}, Defense: {character.defense})")
  60. print(f"{monster.name} (Health: {monster.health}, Attack: {monster.attack}, Defense: {monster.defense})")
  61. input("Press enter to continue...")
  62.  
  63. # Character attacks monster
  64. monster.take_damage(character.attack)
  65. print(f"{character.name} attack the {monster.name} for {character.attack} damage")
  66. if monster.is_dead():
  67. print(f"{monster.name} has been defeated!")
  68. break
  69.  
  70. # Monster attacks character
  71. character.take_damage(monster.attack)
  72. print(f"{monster.name} attack {character.name} for {monster.attack} damage")
  73. if character.is_dead():
  74. print(f"{character.name} has been defeated :(")
  75. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement