File size: 1,891 Bytes
efb1d36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7fe9dae
acb365d
fec54bd
1b3451f
acb365d
fec54bd
efb1d36
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
import random

class Adventure:
    def __init__(self, name):
        self.name = name
        self.health = 100
        self.gold = 0
        self.victory = False

    def fight(self, monster_name, monster_attack):
        self.health -= monster_attack
        if self.health <= 0:
            st.write("You have been defeated by the {}.".format(monster_name))
            st.write("Your adventure has come to an end.")
            self.victory = False
        else:
            st.write("You fought the {} and took {} damage. Your health is now {}.".format(
                monster_name, monster_attack, self.health))
            self.victory = True

    def move(self, direction):
        if direction == "North":
            st.write("You move North.")
        elif direction == "South":
            st.write("You move South.")
        elif direction == "East":
            st.write("You move East.")
        elif direction == "West":
            st.write("You move West.")
        else:
            st.write("Invalid direction. Please choose North, South, East, or West.")

def play_game():
    name = st.text_input("Enter your name:")
    adventure = Adventure(name)
    st.write("Welcome to the dungeon, {}.".format(adventure.name))

    while adventure.victory==False:
        count=1
        #direction = st.selectbox('Choose your next move:', ('North', 'South', 'East', 'West'), key = count)
        #direction = st.selectbox("Choose your next move:", ("North", "South", "East", "West"), key = count)
        count = count + 1
        adventure.move("North")

        if random.random() > 0.7:
            monster_name = "Goblin"
            monster_attack = random.randint(10, 25)
            st.write("A {} appears and attacks you.".format(monster_name))
            adventure.fight(monster_name, monster_attack)

if __name__ == "__main__":
    play_game()