Spaces:
Runtime error
Runtime error
# ChatGPT prompt: write a python streamlit program that creates a dungeon crawler game featuring a reinforcement learning monster that a player can fight and slay | |
import streamlit as st | |
import random | |
import numpy as np | |
# create a class for the monster | |
class Monster(): | |
def __init__(self, name, hp, attack, defense): | |
self.name = name | |
self.hp = hp | |
self.attack = attack | |
self.defense = defense | |
# create a class for the player | |
class Player(): | |
def __init__(self, name, hp, attack, defense): | |
self.name = name | |
self.hp = hp | |
self.attack = attack | |
self.defense = defense | |
# create the reinforcement learning monster | |
class ReinforcementMonster(): | |
def __init__(self, name, hp, attack, defense): | |
self.name = name | |
self.hp = hp | |
self.attack = attack | |
self.defense = defense | |
# create a function to generate a random number | |
def random_number(): | |
x = random.randint(1,20) | |
return x | |
# create a function to start the game | |
def start_game(): | |
# create a monster | |
monster = Monster('goblin',100,20,10) | |
# create a player | |
player = Player('hero',100,20,10) | |
# create a reinforcement monster | |
reinforcement_monster = ReinforcementMonster('dragon',100,30,15) | |
# create a loop to simulate a battle | |
while monster.hp > 0 and player.hp > 0: | |
# player attack monster | |
monster.hp = monster.hp - player.attack | |
st.write(f'Player {player.name} attacks {monster.name} with {player.attack}') | |
st.write(f'{monster.name} has {monster.hp} hp left') | |
# monster attack player | |
if monster.hp > 0: | |
player.hp = player.hp - monster.attack | |
st.write(f'{monster.name} attacks {player.name} with {monster.attack}') | |
st.write(f'{player.name} has {player.hp} hp left') | |
# check if player won the fight | |
if player.hp > 0: | |
st.write(f'{player.name} has defeated {monster.name}!') | |
# reinforcement monster attack | |
reinforcement_monster.hp = reinforcement_monster.hp - player.attack | |
st.write(f'Player {player.name} attacks {reinforcement_monster.name} with {player.attack}') | |
st.write(f'{reinforcement_monster.name} has {reinforcement_monster.hp} hp left') | |
# reinforcement monster attack player | |
if reinforcement_monster.hp > 0: | |
player.hp = player.hp - reinforcement_monster.attack | |
st.write(f'{reinforcement_monster.name} attacks {player.name} with {reinforcement_monster.attack}') | |
st.write(f'{player.name} has {player.hp} hp left') | |
# check if player won the fight | |
if player.hp > 0: | |
st.write(f'{player.name} has defeated {reinforcement_monster.name}!') | |
st.write('You have won the game! Congratulations!') | |
# create a main function | |
def main(): | |
st.title('Dungeon Crawler with Reinforcement Learning Monster') | |
# create a start button | |
if st.button('Start'): | |
start_game() | |
if __name__ == '__main__': | |
main() |