Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- # Creature class
- class Creature:
- def __init__(self, name, attack, defense, health, char_class=None):
- self.name = name
- self.char_class = char_class
- 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
- # Class choices
- class_choices = [
- ["Warrior", 10, 5],
- ["Mage", 5, 10],
- ["Rogue", 7, 7]
- ]
- # Monster choices
- monster_choices = [
- ["Orc", 15, 0, 50],
- ["Troll", 10, 5, 75],
- ["Goblin", 5, 5, 25]
- ]
- # Create character
- print("Choose your class:")
- for i, c in enumerate(class_choices):
- print(f"{i+1}: {c[0]} (Attack: {c[1]}, Defense: {c[2]})")
- choice = int(input()) - 1
- name = input("Enter your character's name: ")
- char_class = class_choices[choice][0]
- attack = class_choices[choice][1]
- defense = class_choices[choice][2]
- character = Creature(name, attack, defense, 100, char_class)
- # Game loop
- while True:
- # Generate a random monster
- monster_choice = random.randint(0, len(monster_choices)-1)
- monster_name = monster_choices[monster_choice][0]
- monster_attack = monster_choices[monster_choice][1]
- monster_defense = monster_choices[monster_choice][2]
- monster_health = monster_choices[monster_choice][3]
- monster = Creature(monster_name, monster_attack, monster_defense, monster_health)
- print(f"A wild {monster.name} appears!")
- while True:
- # Display stats
- print(f"{character.name} (Class: {character.char_class}, Health: {character.health}, Attack: {character.attack}, Defense: {character.defense})")
- print(f"{monster.name} (Health: {monster.health}, Attack: {monster.attack}, Defense: {monster.defense})")
- input("Press enter to continue...")
- # Character attacks monster
- monster.take_damage(character.attack)
- print(f"{character.name} attack 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