-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
75 lines (55 loc) · 2.22 KB
/
app.py
File metadata and controls
75 lines (55 loc) · 2.22 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import streamlit as st
import random
st.set_page_config(page_title="One Room Boss Fight", layout="centered")
# Initialize game state
if "player_hp" not in st.session_state:
st.session_state.player_hp = 100
st.session_state.boss_hp = 150
st.session_state.turn = 1
st.session_state.game_over = False
st.title("⚔️ One Room Boss Fight")
st.subheader("Arena: The Final Chamber")
st.write("Defeat the Boss to win. Survive or fall.")
st.progress(st.session_state.player_hp / 100)
st.write(f"🧍 Player HP: {st.session_state.player_hp}")
st.progress(st.session_state.boss_hp / 150)
st.write(f"👹 Boss HP: {st.session_state.boss_hp}")
if not st.session_state.game_over:
st.markdown("### Choose your action")
col1, col2, col3 = st.columns(3)
action = None
if col1.button("⚔️ Attack"):
action = "attack"
if col2.button("🛡️ Dodge"):
action = "dodge"
if col3.button("💊 Heal"):
action = "heal"
if action:
if action == "attack":
damage = random.randint(12, 20)
st.session_state.boss_hp -= damage
st.write(f"You strike the boss for **{damage}** damage!")
elif action == "heal":
st.session_state.player_hp += 10
if st.session_state.player_hp > 100:
st.session_state.player_hp = 100
st.write("You regain **10 HP**.")
# Boss turn
boss_damage = random.randint(8, 18)
if action == "dodge" and random.random() < 0.5:
st.write("You dodged the boss attack!")
else:
st.session_state.player_hp -= boss_damage
st.write(f"Boss hits you for **{boss_damage}** damage!")
# Win / Lose check
if st.session_state.player_hp <= 0:
st.session_state.game_over = True
st.error("☠️ You were defeated.")
elif st.session_state.boss_hp <= 0:
st.session_state.game_over = True
st.success("🎉 Boss defeated. You win!")
else:
if st.button("🔁 Restart Game"):
for key in list(st.session_state.keys()):
del st.session_state[key]
st.experimental_rerun()