Update app.py
Browse files
app.py
CHANGED
|
@@ -129,7 +129,7 @@ def main():
|
|
| 129 |
st.markdown("""
|
| 130 |
<div class="question-box">
|
| 131 |
<h3>Welcome to <span style='color:#6C63FF;'>KASOTI 🎯</span></h3>
|
| 132 |
-
<p>This is a fun guessing game! You’ll think of something, and I’ll ask
|
| 133 |
<p>You can choose from three categories:</p>
|
| 134 |
<ul>
|
| 135 |
<li><strong>person</strong> – like a celebrity, fictional character, etc.</li>
|
|
@@ -142,18 +142,14 @@ def main():
|
|
| 142 |
|
| 143 |
with st.form("start_form"):
|
| 144 |
category_input = st.text_input("Enter category (person / place / object):").strip().lower()
|
| 145 |
-
user_input = st.text_input("Now think of something in that category (we won't peek!):").strip().lower()
|
| 146 |
|
| 147 |
if st.form_submit_button("Start Game"):
|
| 148 |
-
if not category_input
|
| 149 |
st.error("Please fill out both fields!")
|
| 150 |
elif category_input not in ["person", "place", "object"]:
|
| 151 |
st.error("Oops! Type either person, place or object to start the game!")
|
| 152 |
-
elif len(user_input) < 3:
|
| 153 |
-
st.error("Too short! Type properly.")
|
| 154 |
else:
|
| 155 |
st.session_state.category = category_input
|
| 156 |
-
st.session_state.user_input = user_input
|
| 157 |
st.session_state.game_state = "gameplay"
|
| 158 |
st.rerun()
|
| 159 |
|
|
@@ -163,22 +159,26 @@ def main():
|
|
| 163 |
f'<strong>{st.session_state.questions[st.session_state.current_q]}</strong></div>',
|
| 164 |
unsafe_allow_html=True)
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
st.
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
|
| 176 |
# Result screen
|
| 177 |
elif st.session_state.game_state == "result":
|
| 178 |
show_confetti()
|
| 179 |
st.markdown('<div class="final-reveal">🎉 I think it\'s a...</div>', unsafe_allow_html=True)
|
| 180 |
time.sleep(1)
|
| 181 |
-
st.markdown(f'<div class="final-reveal" style="font-size:3.5rem;color:#6C63FF;">{st.session_state.
|
| 182 |
unsafe_allow_html=True)
|
| 183 |
|
| 184 |
if st.button("Play Again", key="play_again"):
|
|
@@ -187,3 +187,4 @@ def main():
|
|
| 187 |
|
| 188 |
if __name__ == "__main__":
|
| 189 |
main()
|
|
|
|
|
|
| 129 |
st.markdown("""
|
| 130 |
<div class="question-box">
|
| 131 |
<h3>Welcome to <span style='color:#6C63FF;'>KASOTI 🎯</span></h3>
|
| 132 |
+
<p>This is a fun guessing game! You’ll think of something, and I’ll ask maximum 20 Yes/No questions to guess what it is.</p>
|
| 133 |
<p>You can choose from three categories:</p>
|
| 134 |
<ul>
|
| 135 |
<li><strong>person</strong> – like a celebrity, fictional character, etc.</li>
|
|
|
|
| 142 |
|
| 143 |
with st.form("start_form"):
|
| 144 |
category_input = st.text_input("Enter category (person / place / object):").strip().lower()
|
|
|
|
| 145 |
|
| 146 |
if st.form_submit_button("Start Game"):
|
| 147 |
+
if not category_input:
|
| 148 |
st.error("Please fill out both fields!")
|
| 149 |
elif category_input not in ["person", "place", "object"]:
|
| 150 |
st.error("Oops! Type either person, place or object to start the game!")
|
|
|
|
|
|
|
| 151 |
else:
|
| 152 |
st.session_state.category = category_input
|
|
|
|
| 153 |
st.session_state.game_state = "gameplay"
|
| 154 |
st.rerun()
|
| 155 |
|
|
|
|
| 159 |
f'<strong>{st.session_state.questions[st.session_state.current_q]}</strong></div>',
|
| 160 |
unsafe_allow_html=True)
|
| 161 |
|
| 162 |
+
with st.form("answer_form"):
|
| 163 |
+
answer_input = st.text_input("Type your answer (yes / no):").strip().lower()
|
| 164 |
+
|
| 165 |
+
if st.form_submit_button("Submit Answer"):
|
| 166 |
+
if answer_input not in ["yes", "no"]:
|
| 167 |
+
st.error("Please type only 'yes' or 'no' (case doesn't matter)!")
|
| 168 |
+
else:
|
| 169 |
+
st.session_state.answers.append(answer_input == "yes")
|
| 170 |
+
st.session_state.current_q += 1
|
| 171 |
|
| 172 |
+
if st.session_state.current_q >= len(st.session_state.questions):
|
| 173 |
+
st.session_state.game_state = "result"
|
| 174 |
+
st.rerun()
|
| 175 |
|
| 176 |
# Result screen
|
| 177 |
elif st.session_state.game_state == "result":
|
| 178 |
show_confetti()
|
| 179 |
st.markdown('<div class="final-reveal">🎉 I think it\'s a...</div>', unsafe_allow_html=True)
|
| 180 |
time.sleep(1)
|
| 181 |
+
st.markdown(f'<div class="final-reveal" style="font-size:3.5rem;color:#6C63FF;">{f"something in the category of {st.session_state.category.upper()}"}</div>',
|
| 182 |
unsafe_allow_html=True)
|
| 183 |
|
| 184 |
if st.button("Play Again", key="play_again"):
|
|
|
|
| 187 |
|
| 188 |
if __name__ == "__main__":
|
| 189 |
main()
|
| 190 |
+
|