Advertisement
cipheron

GPT written RPG v1

Jan 7th, 2023 (edited)
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. import random
  2.  
  3. # Character class
  4. class Character:
  5. def __init__(self, name, char_class):
  6. self.name = name
  7. self.char_class = char_class
  8. self.health = 100
  9. self.attack = 10
  10. self.defense = 5
  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. # Monster class
  21. class Monster:
  22. def __init__(self, name, attack, defense, health):
  23. self.name = name
  24. self.attack = attack
  25. self.defense = defense
  26. self.health = health
  27.  
  28. def take_damage(self, damage):
  29. self.health -= damage
  30. if self.health < 0:
  31. self.health = 0
  32.  
  33. def is_dead(self):
  34. return self.health == 0
  35.  
  36. # Create character
  37. name = input("Enter your character's name: ")
  38. char_class = input("Enter your character's class: ")
  39. character = Character(name, char_class)
  40.  
  41. # Game loop
  42. while True:
  43. # Generate a random monster
  44. monster_name = "Orc"
  45. monster_attack = random.randint(5, 15)
  46. monster_defense = random.randint(0, 5)
  47. monster_health = random.randint(50, 100)
  48. monster = Monster(monster_name, monster_attack, monster_defense, monster_health)
  49.  
  50. print(f"A wild {monster.name} appears!")
  51.  
  52. while True:
  53. # Character attacks monster
  54. monster.take_damage(character.attack)
  55. print(f"{character.name} attacked the {monster.name} for {character.attack} damage")
  56. if monster.is_dead():
  57. print(f"{monster.name} has been defeated!")
  58. break
  59.  
  60. # Monster attacks character
  61. character.take_damage(monster.attack)
  62. print(f"{monster.name} attack {character.name} for {monster.attack} damage")
  63. if character.is_dead():
  64. print(f"{character.name} has been defeated :(")
  65. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement