Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- # Character class
- class Character:
- def __init__(self, name, char_class):
- self.name = name
- self.char_class = char_class
- self.health = 100
- self.attack = 10
- self.defense = 5
- def take_damage(self, damage):
- self.health -= damage
- if self.health < 0:
- self.health = 0
- def is_dead(self):
- return self.health == 0
- # Monster class
- class Monster:
- def __init__(self, name, attack, defense, health):
- self.name = name
- self.attack = attack
- self.defense = defense
- self.health = health
- def take_damage(self, damage):
- self.health -= damage
- if self.health < 0:
- self.health = 0
- def is_dead(self):
- return self.health == 0
- # Create character
- name = input("Enter your character's name: ")
- char_class = input("Enter your character's class: ")
- character = Character(name, char_class)
- # Game loop
- while True:
- # Generate a random monster
- monster_name = "Orc"
- monster_attack = random.randint(5, 15)
- monster_defense = random.randint(0, 5)
- monster_health = random.randint(50, 100)
- monster = Monster(monster_name, monster_attack, monster_defense, monster_health)
- print(f"A wild {monster.name} appears!")
- while True:
- # Character attacks monster
- monster.take_damage(character.attack)
- print(f"{character.name} attacked the {monster.name} for {character.attack} damage")
- if monster.is_dead():
- print(f"{monster.name} has been defeated!")
- break
- # Monster attacks character
- character.take_damage(monster.attack)
- print(f"{monster.name} attack {character.name} for {monster.attack} damage")
- if character.is_dead():
- print(f"{character.name} has been defeated :(")
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement