Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,35 +3,31 @@ import random
|
|
| 3 |
|
| 4 |
st.set_page_config(page_title="Mini Game Arcade ๐ฎ", layout="centered")
|
| 5 |
|
| 6 |
-
# --- Initialize Score ---
|
| 7 |
if 'score' not in st.session_state:
|
| 8 |
st.session_state.score = 0
|
| 9 |
|
| 10 |
-
# --- Header ---
|
| 11 |
st.title("๐ฎ Mini Game Arcade")
|
| 12 |
st.markdown("Welcome! Play a game and earn points! ๐ง ๐ก")
|
| 13 |
|
| 14 |
-
|
| 15 |
-
st.markdown(f"### โญ Current Score: `{st.session_state.score}`")
|
| 16 |
if st.button("๐ Reset Score"):
|
| 17 |
st.session_state.score = 0
|
| 18 |
st.success("Score has been reset!")
|
| 19 |
|
| 20 |
-
# --- Game Selection ---
|
| 21 |
games = [
|
| 22 |
"Rock Paper Scissors", "Guess the Number", "Word Scramble", "Emoji Quiz",
|
| 23 |
-
"Math Quiz", "Coin Toss", "Color Guess", "Yes or No",
|
|
|
|
| 24 |
]
|
| 25 |
|
| 26 |
-
selected_game = st.selectbox("
|
| 27 |
|
| 28 |
-
# --- ROCK PAPER SCISSORS ---
|
| 29 |
if selected_game == "Rock Paper Scissors":
|
| 30 |
-
st.subheader("
|
| 31 |
-
user_choice = st.radio("Your
|
| 32 |
if st.button("Play"):
|
| 33 |
computer = random.choice(["Rock", "Paper", "Scissors"])
|
| 34 |
-
st.write(f"
|
| 35 |
if user_choice == computer:
|
| 36 |
st.info("It's a tie!")
|
| 37 |
elif (user_choice == "Rock" and computer == "Scissors") or \
|
|
@@ -42,117 +38,43 @@ if selected_game == "Rock Paper Scissors":
|
|
| 42 |
else:
|
| 43 |
st.error("You lose!")
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
if guess == number:
|
| 52 |
-
st.success("๐ Correct! +1 point")
|
| 53 |
-
st.session_state.score += 1
|
| 54 |
-
elif guess < number:
|
| 55 |
-
st.warning("Too low!")
|
| 56 |
-
else:
|
| 57 |
-
st.warning("Too high!")
|
| 58 |
-
st.caption(f"The number was: {number}")
|
| 59 |
-
|
| 60 |
-
# --- WORD SCRAMBLE ---
|
| 61 |
-
elif selected_game == "Word Scramble":
|
| 62 |
-
st.subheader("๐ค Word Scramble")
|
| 63 |
-
words = ["streamlit", "python", "arcade", "gaming", "developer"]
|
| 64 |
-
word = random.choice(words)
|
| 65 |
-
scrambled = ''.join(random.sample(word, len(word)))
|
| 66 |
-
st.write(f"Unscramble this word: `{scrambled}`")
|
| 67 |
-
answer = st.text_input("Your Guess")
|
| 68 |
-
if st.button("Check Answer"):
|
| 69 |
-
if answer.lower() == word:
|
| 70 |
-
st.success("Correct! +1 point")
|
| 71 |
-
st.session_state.score += 1
|
| 72 |
-
else:
|
| 73 |
-
st.error(f"Wrong. It was `{word}`.")
|
| 74 |
-
|
| 75 |
-
# --- EMOJI QUIZ ---
|
| 76 |
-
elif selected_game == "Emoji Quiz":
|
| 77 |
-
st.subheader("๐ Emoji Quiz")
|
| 78 |
-
emojis = {
|
| 79 |
-
"๐๐ป": "python",
|
| 80 |
-
"๐๐จโ๐": "student",
|
| 81 |
-
"๐ง๏ธโ": "rain",
|
| 82 |
-
"๐โค๏ธ": "pizza",
|
| 83 |
-
"๐ฎ๐ง ": "game"
|
| 84 |
}
|
| 85 |
-
|
| 86 |
-
st.write(
|
| 87 |
-
|
| 88 |
-
if st.button("Check"):
|
| 89 |
-
if
|
| 90 |
-
st.success("You're right! +1 point")
|
| 91 |
-
st.session_state.score += 1
|
| 92 |
-
else:
|
| 93 |
-
st.error(f"Oops, the answer was: {answer}")
|
| 94 |
-
|
| 95 |
-
# --- MATH QUIZ ---
|
| 96 |
-
elif selected_game == "Math Quiz":
|
| 97 |
-
st.subheader("โ Math Quiz")
|
| 98 |
-
a, b = random.randint(1, 10), random.randint(1, 10)
|
| 99 |
-
correct = a + b
|
| 100 |
-
st.write(f"What is {a} + {b}?")
|
| 101 |
-
user_ans = st.number_input("Your Answer", 0)
|
| 102 |
-
if st.button("Submit"):
|
| 103 |
-
if user_ans == correct:
|
| 104 |
-
st.success("Correct! +1 point")
|
| 105 |
-
st.session_state.score += 1
|
| 106 |
-
else:
|
| 107 |
-
st.error(f"Wrong. Answer: {correct}")
|
| 108 |
-
|
| 109 |
-
# --- COIN TOSS ---
|
| 110 |
-
elif selected_game == "Coin Toss":
|
| 111 |
-
st.subheader("๐ช Coin Toss")
|
| 112 |
-
user_call = st.radio("Call it:", ["Heads", "Tails"])
|
| 113 |
-
if st.button("Flip"):
|
| 114 |
-
result = random.choice(["Heads", "Tails"])
|
| 115 |
-
st.write(f"๐ช It's {result}!")
|
| 116 |
-
if user_call == result:
|
| 117 |
-
st.success("You guessed it! +1 point")
|
| 118 |
-
st.session_state.score += 1
|
| 119 |
-
else:
|
| 120 |
-
st.error("Try again!")
|
| 121 |
-
|
| 122 |
-
# --- COLOR GUESS ---
|
| 123 |
-
elif selected_game == "Color Guess":
|
| 124 |
-
st.subheader("๐จ Color Guess")
|
| 125 |
-
colors = ["Red", "Blue", "Green", "Yellow", "Purple"]
|
| 126 |
-
correct = random.choice(colors)
|
| 127 |
-
user_guess = st.selectbox("Guess the color", colors)
|
| 128 |
-
if st.button("Check Color"):
|
| 129 |
-
if user_guess == correct:
|
| 130 |
st.success("Correct! +1 point")
|
| 131 |
st.session_state.score += 1
|
| 132 |
else:
|
| 133 |
-
st.
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
st.
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
st.
|
| 157 |
-
|
| 158 |
|
|
|
|
| 3 |
|
| 4 |
st.set_page_config(page_title="Mini Game Arcade ๐ฎ", layout="centered")
|
| 5 |
|
|
|
|
| 6 |
if 'score' not in st.session_state:
|
| 7 |
st.session_state.score = 0
|
| 8 |
|
|
|
|
| 9 |
st.title("๐ฎ Mini Game Arcade")
|
| 10 |
st.markdown("Welcome! Play a game and earn points! ๐ง ๐ก")
|
| 11 |
|
| 12 |
+
st.markdown(f"### โญ Score: `{st.session_state.score}`")
|
|
|
|
| 13 |
if st.button("๐ Reset Score"):
|
| 14 |
st.session_state.score = 0
|
| 15 |
st.success("Score has been reset!")
|
| 16 |
|
|
|
|
| 17 |
games = [
|
| 18 |
"Rock Paper Scissors", "Guess the Number", "Word Scramble", "Emoji Quiz",
|
| 19 |
+
"Math Quiz", "Coin Toss", "Color Guess", "Yes or No",
|
| 20 |
+
"Hangman", "Riddle Me This", "Number Memory"
|
| 21 |
]
|
| 22 |
|
| 23 |
+
selected_game = st.selectbox("Choose a game to play:", games)
|
| 24 |
|
|
|
|
| 25 |
if selected_game == "Rock Paper Scissors":
|
| 26 |
+
st.subheader("Rock Paper Scissors")
|
| 27 |
+
user_choice = st.radio("Your move:", ["Rock", "Paper", "Scissors"])
|
| 28 |
if st.button("Play"):
|
| 29 |
computer = random.choice(["Rock", "Paper", "Scissors"])
|
| 30 |
+
st.write(f"Computer chose: {computer}")
|
| 31 |
if user_choice == computer:
|
| 32 |
st.info("It's a tie!")
|
| 33 |
elif (user_choice == "Rock" and computer == "Scissors") or \
|
|
|
|
| 38 |
else:
|
| 39 |
st.error("You lose!")
|
| 40 |
|
| 41 |
+
elif selected_game == "Riddle Me This":
|
| 42 |
+
st.subheader("๐ง Riddle Me This")
|
| 43 |
+
riddles = {
|
| 44 |
+
"What has to be broken before you can use it?": "egg",
|
| 45 |
+
"Iโm tall when Iโm young, and Iโm short when Iโm old. What am I?": "candle",
|
| 46 |
+
"What month has 28 days?": "all"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
+
question, answer = random.choice(list(riddles.items()))
|
| 49 |
+
st.write(question)
|
| 50 |
+
user_input = st.text_input("Your answer:")
|
| 51 |
+
if st.button("Check Answer"):
|
| 52 |
+
if user_input.lower().strip() == answer:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
st.success("Correct! +1 point")
|
| 54 |
st.session_state.score += 1
|
| 55 |
else:
|
| 56 |
+
st.error(f"Incorrect. The answer was: {answer}")
|
| 57 |
+
|
| 58 |
+
elif selected_game == "Number Memory":
|
| 59 |
+
st.subheader("๐ข Number Memory")
|
| 60 |
+
if 'memory_number' not in st.session_state:
|
| 61 |
+
st.session_state.memory_number = str(random.randint(1000, 9999))
|
| 62 |
+
st.session_state.memory_phase = 'show'
|
| 63 |
+
|
| 64 |
+
if st.session_state.memory_phase == 'show':
|
| 65 |
+
st.write(f"Memorize this number: **{st.session_state.memory_number}**")
|
| 66 |
+
if st.button("I memorized it"):
|
| 67 |
+
st.session_state.memory_phase = 'guess'
|
| 68 |
+
st.experimental_rerun()
|
| 69 |
+
|
| 70 |
+
elif st.session_state.memory_phase == 'guess':
|
| 71 |
+
guess = st.text_input("Enter the number you memorized")
|
| 72 |
+
if st.button("Check"):
|
| 73 |
+
if guess == st.session_state.memory_number:
|
| 74 |
+
st.success("Correct! +1 point")
|
| 75 |
+
st.session_state.score += 1
|
| 76 |
+
else:
|
| 77 |
+
st.error(f"Wrong! It was {st.session_state.memory_number}")
|
| 78 |
+
del st.session_state.memory_number
|
| 79 |
+
del st.session_state.memory_phase
|
|
|
|
| 80 |
|