Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.9 kB
1
Indexable
Never
import random

class Player:
    def __init__(self, name):
        self.name = name
        self.hp = 100
        self.attack = 10
        self.defense = 5

    def display_stats(self):
        print(f"Name: {self.name}")
        print(f"HP: {self.hp}")
        print(f"Attack: {self.attack}")
        print(f"Defense: {self.defense}")

class Monster:
    def __init__(self, name, hp, attack, defense):
        self.name = name
        self.hp = hp
        self.attack = attack
        self.defense = defense

class Encounter:
    def __init__(self, player):
        self.player = player
        self.monster = self.generate_monster()

    def generate_monster(self):
        monsters = [
            Monster("Froggit", 30, 8, 2),
            Monster("Whimsun", 25, 6, 1),
            Monster("Napstablook", 40, 10, 3)
        ]
        return random.choice(monsters)

    def fight(self):
        print(f"You encountered a {self.monster.name}!")
        print("Fight or Spare?")
        choice = input("> ").lower()
        if choice == "fight":
            print("You attacked the monster!")
            self.battle()
        elif choice == "spare":
            print("You chose to spare the monster!")
            print("The monster left peacefully.")
        else:
            print("Invalid choice. Please try again.")
            self.fight()

    def battle(self):
        while self.player.hp > 0 and self.monster.hp > 0:
            player_damage = max(0, self.player.attack - self.monster.defense)
            monster_damage = max(0, self.monster.attack - self.player.defense)

            print(f"You dealt {player_damage} damage to {self.monster.name}!")
            self.monster.hp -= player_damage
            if self.monster.hp <= 0:
                print(f"You defeated the {self.monster.name}!")
                break

            print(f"The {self.monster.name} attacked you!")
            print(f"You received {monster_damage} damage!")
            self.player.hp -= monster_damage
            if self.player.hp <= 0:
                print("You were defeated by the monster. Game Over!")
                break

def main():
    print("Welcome to Undertale-inspired text adventure!")
    name = input("Enter your name: ")
    player = Player(name)
    player.display_stats()
    print("Navigate through encounters and decide whether to fight or spare.")

    while True:
        print("\nYou're walking through the underground...")
        print("What will you do?")
        print("1. Continue walking")
        print("2. Quit")
        choice = input("> ")
        if choice == "1":
            encounter = Encounter(player)
            encounter.fight()
        elif choice == "2":
            print("Goodbye!")
            break
        else:
            print("Invalid choice. Please try again.")

if __name__ == "__main__":
    main()
Leave a Comment