awacke1 commited on
Commit
efb1d36
·
1 Parent(s): 78c59a0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import random
3
+
4
+ class Adventure:
5
+ def __init__(self, name):
6
+ self.name = name
7
+ self.health = 100
8
+ self.gold = 0
9
+ self.victory = False
10
+
11
+ def fight(self, monster_name, monster_attack):
12
+ self.health -= monster_attack
13
+ if self.health <= 0:
14
+ st.write("You have been defeated by the {}.".format(monster_name))
15
+ st.write("Your adventure has come to an end.")
16
+ self.victory = False
17
+ else:
18
+ st.write("You fought the {} and took {} damage. Your health is now {}.".format(
19
+ monster_name, monster_attack, self.health))
20
+ self.victory = True
21
+
22
+ def move(self, direction):
23
+ if direction == "North":
24
+ st.write("You move North.")
25
+ elif direction == "South":
26
+ st.write("You move South.")
27
+ elif direction == "East":
28
+ st.write("You move East.")
29
+ elif direction == "West":
30
+ st.write("You move West.")
31
+ else:
32
+ st.write("Invalid direction. Please choose North, South, East, or West.")
33
+
34
+ def play_game():
35
+ name = st.text_input("Enter your name:")
36
+ adventure = Adventure(name)
37
+ st.write("Welcome to the dungeon, {}.".format(adventure.name))
38
+
39
+ while adventure.victory:
40
+ direction = st.selectbox("Choose your next move:", ["North", "South", "East", "West"])
41
+ adventure.move(direction)
42
+
43
+ if random.random() > 0.7:
44
+ monster_name = "Goblin"
45
+ monster_attack = random.randint(10, 25)
46
+ st.write("A {} appears and attacks you.".format(monster_name))
47
+ adventure.fight(monster_name, monster_attack)
48
+
49
+ if __name__ == "__main__":
50
+ play_game()