Spaces:
Build error

CodeDay / app.py
faiz3123's picture
Update app.py
d3b2609 verified
Raw History Blame Contribute Delete
8.55 kB
import streamlit as st
import random
# Set page config
st.set_page_config(page_title="Emoji Detective", page_icon="๐Ÿ•ต๏ธ", layout="centered")
# Emoji mapping function
def get_emoji(score):
if score >= 50:
return "๐Ÿคฉ" # Star-struck face (ecstatic)
elif 30 <= score < 10:
return "๐Ÿ˜„" # Smiling face with open mouth (very happy)
elif 10 <= score < 30:
return "๐Ÿ˜€" # Grinning face (happy)
elif 0 <= score < 10:
return "๐Ÿ™‚" # Slightly smiling face (content)
elif -10 <= score < 0:
return "๐Ÿ˜•" # Confused face (neutral)
elif -20 <= score < -10:
return "๐Ÿ˜Ÿ" # Slightly frowning face (sad)
elif -25 <= score < -20:
return "๐Ÿ˜ข" # Crying face (very sad)
elif -30 <= score < -25:
return "๐Ÿ˜ญ" # Loudly crying face (heartbroken)
else:
return "๐Ÿ˜ฑ" # Face screaming in fear (game over)
# Initialize points, wrong attempts, and mysteries
if 'points' not in st.session_state:
st.session_state.points = 10 # Start with 10 points
if 'wrong_attempts' not in st.session_state:
st.session_state.wrong_attempts = 0
if 'mysteries' not in st.session_state:
st.session_state.mysteries = [
{"clue": "๐Ÿฆ๐Ÿ‘‘", "hint": "A story about a lion becoming king.", "answer": "Lion King"},
#{"clue": "๐Ÿญ๐Ÿฐ", "hint": "A mouse loves to cook in a restaurant.", "answer": "Ratatouille"},
{"clue": "๐Ÿ‘ธโ„๏ธ", "hint": "A princess with ice powers.", "answer": "Frozen"},
{"clue": "๐ŸŸ๐Ÿ”", "hint": "A clownfish looking for his son.", "answer": "Finding Nemo"},
# {"clue": "๐Ÿ‰๐Ÿ‘ฆ", "hint": "A boy trains a dragon.", "answer": "How to Train Your Dragon"},
{"clue": "๐Ÿš€๐Ÿ‘จโ€๐Ÿš€", "hint": "Toys go on a space adventure.", "answer": "Toy Story"},
# {"clue": "๐Ÿป๐Ÿฏ", "hint": "A bear who loves honey.", "answer": "Winnie the Pooh"},
#{"clue": "๐Ÿฆ•๐Ÿฆ–", "hint": "A park full of dinosaurs.", "answer": "Jurassic Park"},
{"clue": "๐Ÿง™โ€โ™‚๏ธโšก", "hint": "A boy wizard goes to magic school.", "answer": "Harry Potter"},
#{"clue": "๐Ÿ‘ธ๐Ÿธ", "hint": "A princess kisses a frog.", "answer": "The Princess and the Frog"},
# {"clue": "๐Ÿ›๐Ÿ“š", "hint": "A caterpillar eats lots of food.", "answer": "The Very Hungry Caterpillar"},
{"clue": "๐ŸŒŠ๐ŸŒบ", "hint": "A girl sails to save her island.", "answer": "Moana"},
{"clue": "๐Ÿพ๐Ÿ”Ž", "hint": "Pups solving mysteries together.", "answer": "Paw Patrol"},
#{"clue": "๐Ÿฆธโ€โ™€๏ธ๐Ÿฆธโ€โ™‚๏ธ", "hint": "A superhero family saves the world.", "answer": "The Incredibles"},
{"clue": "๐Ÿฆ’๐Ÿ˜", "hint": "Animals escape from a zoo.", "answer": "Madagascar"},
#{"clue": "๐Ÿ€๐Ÿง€", "hint": "A mouse wants to become a chef.", "answer": "Ratatouille"},
{"clue": "๐Ÿฐ๐Ÿ•ต๏ธโ€โ™‚๏ธ", "hint": "A bunny cop solves a case.", "answer": "Zootopia"},
#{"clue": "๐Ÿšดโ€โ™‚๏ธ๐ŸŒŸ", "hint": "A boy meets an alien who wants to go home.", "answer": "E.T."},
#{"clue": "๐Ÿข๐Ÿฅ‹", "hint": "Turtles fight crime using ninja skills.", "answer": "Teenage Mutant Ninja Turtles"},
{"clue": "๐Ÿ‘ฉโ€๐Ÿณ๐Ÿ", "hint": "A girl and a dog share a spaghetti kiss.", "answer": "Lady and the Tramp"},
{"clue": "๐Ÿ‘ ๐ŸŽƒ", "hint": "A girl loses her glass slipper.", "answer": "Cinderella"},
{"clue": "๐Ÿ‘ฆ๐ŸŒณ", "hint": "A boy and a tree become lifelong friends.", "answer": "The Giving Tree"},
#{"clue": "๐ŸฆŠ๐Ÿป", "hint": "A clever fox outsmarts everyone.", "answer": "Fantastic Mr. Fox"},
{"clue": "๐Ÿ‰๐ŸŽˆ", "hint": "A house flies with balloons.", "answer": "Up"},
#{"clue": "๐Ÿพ๐Ÿฏ", "hint": "A little bear and tiger go exploring.", "answer": "Winnie the Pooh"},
{"clue": "๐Ÿฐ๐ŸŒน", "hint": "A girl falls in love with a beast.", "answer": "Beauty and the Beast"},
# {"clue": "๐ŸŒฎ๐Ÿญ", "hint": "A mouse helps make tacos.", "answer": "Dragons Love Tacos"},
{"clue": "๐Ÿงžโ€โ™‚๏ธ๐Ÿ•Œ", "hint": "A genie grants three wishes.", "answer": "Aladdin"},
# {"clue": "๐Ÿœ๐Ÿž", "hint": "Tiny heroes save their colony.", "answer": "A Bug's Life"},
#{"clue": "๐ŸŽˆ๐Ÿคก", "hint": "Clowns have a party with lots of balloons.", "answer": "The Greatest Showman"},
# {"clue": "๐Ÿซ๐Ÿญ", "hint": "Kids visit a magical chocolate factory.", "answer": "Charlie and the Chocolate Factory"},
# {"clue": "๐Ÿ‘ฉโ€๐Ÿš€๐Ÿš€", "hint": "A girl dreams of being an astronaut.", "answer": "Interstellar Dreams"},
{"clue": "๐ŸŒด๐Ÿ’", "hint": "A jungle boy and his animal friends.", "answer": "The Jungle Book"},
{"clue": "๐Ÿฆ๐ŸŽค", "hint": "A bird learns how to sing.", "answer": "Rio"},
# {"clue": "๐Ÿฆ•๐ŸŒ‹", "hint": "Dinosaurs try to survive a volcanic eruption.", "answer": "The Land Before Time"},
{"clue": "๐ŸŽต๐ŸŒน", "hint": "A girl follows her dreams to make music.", "answer": "Coco"},
#{"clue": "๐Ÿฆ†๐ŸŒŠ", "hint": "A little duckling finds its family.", "answer": "The Ugly Duckling"},
{"clue": "๐ŸŒŒ๐Ÿš€", "hint": "A space ranger defends the galaxy.", "answer": "Buzz Lightyear"},
{"clue": "๐Ÿงต๐ŸŽŽ", "hint": "A girl shows courage by saving her family.", "answer": "Mulan"},
{"clue": "๐Ÿฆ๐Ÿ”ง", "hint": "Birds team up to build a giant nest.", "answer": "Angry Birds"},
# {"clue": "๐Ÿ๐ŸŽ", "hint": "A jungle boy grows up with animals.", "answer": "The Jungle Book"},
# {"clue": "๐Ÿงœโ€โ™€๏ธ๐ŸŽค", "hint": "A mermaid dreams of a new life.", "answer": "The Little Mermaid"},
# {"clue": "๐Ÿฆข๐ŸŽป", "hint": "A swan learns to dance.", "answer": "Swan Lake"},
# {"clue": "๐Ÿดโ€โ˜ ๏ธโš“", "hint": "A boy joins pirates on an adventure.", "answer": "Peter Pan"},
# {"clue": "๐ŸŒŸ๐Ÿ‘ ", "hint": "A girl visits another magical world in red shoes.", "answer": "Wizard of Oz"},
# {"clue": "๐Ÿ„๐Ÿง™โ€โ™‚๏ธ", "hint": "A small hero fights to save Middle Earth.", "answer": "The Hobbit"},
# {"clue": "๐ŸฆŒ๐ŸŽ„", "hint": "A reindeer helps save Christmas.", "answer": "Rudolph the Red-Nosed Reindeer"}
]
if 'selected_mystery' not in st.session_state:
st.session_state.selected_mystery = random.choice(st.session_state.mysteries)
# Main game function
def emoji_detective_game():
st.title("๐Ÿ•ต๏ธ Emoji Detective")
st.write("Welcome, Detective! Decode the emoji clues to solve the mystery! Here you will be getting clues regarding the famous cartoons guess it")
st.write(" For a correct answer you will be granted +10 ")
st.write("For a wrong answer -8")
st.write("When you skip the question -5")
st.write(f"Your current happiness score: {st.session_state.points} {get_emoji(st.session_state.points)}")
# Current mystery
selected_mystery = st.session_state.selected_mystery
st.subheader(f"Clue: {selected_mystery['clue']}")
# Provide a hint
if st.button("Get a hint ๐Ÿ•ต"):
st.info(f"Hint: {selected_mystery['hint']}")
# User input
user_answer = st.text_input("Your Answer", "").strip().lower()
# Check answer
if st.button("Submit Answer"):
if user_answer == selected_mystery['answer'].lower():
st.session_state.points += 10
st.success("๐ŸŽ‰ Correct! You've solved the mystery!")
st.balloons()
st.session_state.wrong_attempts = 0
st.session_state.selected_mystery = random.choice(st.session_state.mysteries)
else:
st.session_state.wrong_attempts += 1
if st.session_state.wrong_attempts >= 3:
st.session_state.points -= 8
st.warning("โš ๏ธ You've made 3 wrong attempts! Moving to the next mystery.")
st.session_state.wrong_attempts = 0
st.session_state.selected_mystery = random.choice(st.session_state.mysteries)
else:
st.error("Wrong answer! Try again.")
# Skip question
if st.button("Skip ๐Ÿ›‘"):
st.session_state.points -= 5
st.warning("โš ๏ธ You skipped the question! Points deducted.")
st.session_state.wrong_attempts = 0
st.session_state.selected_mystery = random.choice(st.session_state.mysteries)
# Display points in the sidebar
st.sidebar.write(f"Your Points: {st.session_state.points} {get_emoji(st.session_state.points)}")
# Main app function
def main():
emoji_detective_game()
if __name__ == "__main__":
main()