zarashahid commited on
Commit
fdfffce
ยท
verified ยท
1 Parent(s): 7b4c04e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -0
app.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import random
3
+
4
+ st.set_page_config(page_title="๐ŸŽฎ Mini Game Arcade", page_icon="๐ŸŽฒ")
5
+
6
+ st.title("๐ŸŽฎ Mini Game Arcade")
7
+
8
+ # Game selection
9
+ game = st.selectbox("Choose a game to play:", [
10
+ "Rock, Paper, Scissors",
11
+ "Guess the Number",
12
+ "Word Scramble",
13
+ "Emoji Quiz",
14
+ "Math Quiz",
15
+ "Hangman",
16
+ "Tic-Tac-Toe",
17
+ "Coin Toss",
18
+ "Dice Roll",
19
+ "Memory Challenge"
20
+ ])
21
+
22
+ # ------------------------------
23
+ if game == "Rock, Paper, Scissors":
24
+ st.subheader("โœŠโœ‹โœŒ๏ธ Rock, Paper, Scissors")
25
+ user_choice = st.radio("Choose:", ["Rock", "Paper", "Scissors"])
26
+ if st.button("Play"):
27
+ computer_choice = random.choice(["Rock", "Paper", "Scissors"])
28
+ st.write(f"Computer chose: **{computer_choice}**")
29
+ if user_choice == computer_choice:
30
+ st.info("It's a tie!")
31
+ elif (user_choice, computer_choice) in [("Rock", "Scissors"), ("Scissors", "Paper"), ("Paper", "Rock")]:
32
+ st.success("You win!")
33
+ else:
34
+ st.error("You lose!")
35
+
36
+ # ------------------------------
37
+ elif game == "Guess the Number":
38
+ st.subheader("๐Ÿ”ข Guess the Number (1-10)")
39
+ secret = random.randint(1, 10)
40
+ guess = st.number_input("Your guess:", 1, 10, step=1)
41
+ if st.button("Check"):
42
+ if guess == secret:
43
+ st.success("๐ŸŽ‰ Correct! You guessed it.")
44
+ else:
45
+ st.warning(f"Wrong! The number was {secret}.")
46
+
47
+ # ------------------------------
48
+ elif game == "Word Scramble":
49
+ st.subheader("๐Ÿ”ค Word Scramble")
50
+ word = random.choice(["streamlit", "python", "arcade", "developer", "career"])
51
+ scrambled = "".join(random.sample(word, len(word)))
52
+ answer = st.text_input(f"Unscramble this word: **{scrambled}**")
53
+ if st.button("Check"):
54
+ if answer.lower() == word:
55
+ st.success("โœ… Correct!")
56
+ else:
57
+ st.error(f"โŒ Wrong! The word was: **{word}**")
58
+
59
+ # ------------------------------
60
+ elif game == "Emoji Quiz":
61
+ st.subheader("๐Ÿ˜Š Emoji Quiz")
62
+ quiz = {
63
+ "๐Ÿฆ๐Ÿ‘‘": "lion king",
64
+ "๐ŸŽ๐Ÿ“ฑ": "apple",
65
+ "๐ŸŽฌ๐Ÿฟ": "movie",
66
+ "โšฝ๐Ÿ†": "football",
67
+ }
68
+ emoji, answer = random.choice(list(quiz.items()))
69
+ user_answer = st.text_input(f"What does this mean? {emoji}")
70
+ if st.button("Submit"):
71
+ if user_answer.lower() == answer:
72
+ st.success("Correct! ๐ŸŽ‰")
73
+ else:
74
+ st.error(f"Nope! The answer was: {answer}")
75
+
76
+ # ------------------------------
77
+ elif game == "Math Quiz":
78
+ st.subheader("โž• Math Quiz")
79
+ a, b = random.randint(1, 20), random.randint(1, 20)
80
+ user_answer = st.number_input(f"What is {a} + {b}?", value=0)
81
+ if st.button("Check Answer"):
82
+ if user_answer == a+b:
83
+ st.success("โœ… Correct!")
84
+ else:
85
+ st.error(f"โŒ Wrong! Answer is {a+b}.")
86
+
87
+ # ------------------------------
88
+ elif game == "Hangman":
89
+ st.subheader("๐Ÿชข Hangman (1 chance)")
90
+ word = random.choice(["cat", "dog", "bat", "rat", "sun"])
91
+ display = "_ " * len(word)
92
+ guess = st.text_input(f"Guess the word: {display}").lower()
93
+ if st.button("Submit Guess"):
94
+ if guess == word:
95
+ st.success("๐ŸŽ‰ You win!")
96
+ else:
97
+ st.error(f"You lose! Word was: {word}")
98
+
99
+ # ------------------------------
100
+ elif game == "Tic-Tac-Toe":
101
+ st.subheader("โŒโญ• Tic-Tac-Toe")
102
+ st.write("Sorry! Tic-Tac-Toe is currently just a placeholder (implementing full board interaction is advanced here).")
103
+ st.info("You can extend this by adding a 3x3 grid with session state!")
104
+
105
+ # ------------------------------
106
+ elif game == "Coin Toss":
107
+ st.subheader("๐Ÿช™ Coin Toss")
108
+ if st.button("Toss Coin"):
109
+ result = random.choice(["Heads", "Tails"])
110
+ st.write(f"Result: **{result}**")
111
+
112
+ # ------------------------------
113
+ elif game == "Dice Roll":
114
+ st.subheader("๐ŸŽฒ Dice Roll")
115
+ if st.button("Roll Dice"):
116
+ roll = random.randint(1,6)
117
+ st.write(f"You rolled: **{roll}**")
118
+
119
+ # ------------------------------
120
+ elif game == "Memory Challenge":
121
+ st.subheader("๐Ÿง  Memory Challenge")
122
+ numbers = [random.randint(1, 9) for _ in range(3)]
123
+ st.write(f"Remember this sequence: {numbers}")
124
+ guess = st.text_input("Enter the sequence (comma-separated):")
125
+ if st.button("Check Sequence"):
126
+ if guess.replace(" ", "") == ",".join(map(str, numbers)):
127
+ st.success("๐ŸŽ‰ Correct!")
128
+ else:
129
+ st.error(f"Wrong! It was: {numbers}")