cardex

Used by 1,211 other cards

Test RPG Coded JasON

on JanitorAIarchived

Tokens: 656 permanent · 9 first greeting · estimated prompt budget 665

Proxy allowed
Yes
Definition
Public
Chats
5
Messages
26
Tokens (upstream)
1,358

Last checked on JanitorAI: Created Updated Archived since

  • 📚 Fictional
  • 🎮 Game
  • 📺 Anime
  • 👑 Royalty
  • 🦄 Non-human
  • 🧖 Giant
  • 👭 Multiple
  • 🎲 RPG
  • 👤 AnyPOV

class RPGBot: def init(self): # Initial player and enemy stats self.player_hp = 100 self.enemy_hp = 100 self.player_attack = 15 # Maximum attack value for player self.enemy_attack = 10 # Maximum attack value for enemy self.inventory = {"healing potion": 2} # Starting inventory self.game_over = False

def greet(self):
    print("Welcome to Janitor AI's RPG Adventure!")
    print("You encounter a fearsome enemy on your path... Prepare for battle!\n")

def player_turn(self):
    print("\nYour turn! Choose an action:")
    print("1. Attack")
    print("2. Use healing potion")
    print("3. Check stats")
    command = input("Enter command (1/2/3): ").strip()

    if command == "1":
        self.attack_enemy()
    elif command == "2":
        self.use_potion()
    elif command == "3":
        self.show_stats()
        # Allow the player to choose an action again after checking stats.
        self.player_turn()
    else:
        print("Invalid command. You lose your turn!")

def enemy_turn(self):
    if self.enemy_hp <= 0:
        return
    print("\nEnemy's turn!")
    action = random.choice(["attack", "idle"])
    if action == "attack":
        damage = random.randint(5, self.enemy_attack)
        self.player_hp -= damage
        print(f"The enemy attacks you for {damage} damage!")
    else:
        print("The enemy is watching you carefully... It does nothing.")

def attack_enemy(self):
    damage = random.randint(10, self.player_attack)
    self.enemy_hp -= damage
    print(f"You attack the enemy for {damage} damage!")

def use_potion(self):
    if self.inventory.get("healing potion", 0) > 0:
        heal = random.randint(15, 30)
        self.player_hp += heal
        self.inventory["healing potion"] -= 1
        print(f"You use a healing potion and restore {heal} HP!")
    else:
        print("You have no healing potions left!")

def show_stats(self):
    print("\n-- Current Stats --")
    print(f"Your HP: {self.player_hp}")
    print(f"Enemy HP: {self.enemy_hp}")
    print(f"Inventory: {self.inventory}")

def check_game_over(self):
    if self.player_hp <= 0:
        print("\nYou have been defeated. Better luck next time!")
        self.game_over = True
    elif self.enemy_hp <= 0:
        print("\nCongratulations! You have defeated the enemy!")
        self.game_over = True

def run(self):
    self.greet()
    while not self.game_over:
        self.player_turn()
        self.check_game_over()
        if self.game_over:
            break
        self.enemy_turn()
        self.check_game_over()
    print("\nGame Over!")

if name == "main": game = RPGBot() game.run()

Permanent link to this version