Mahrukhh commited on
Commit
ba48ec3
ยท
verified ยท
1 Parent(s): 930b56f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -64
app.py CHANGED
@@ -4,69 +4,89 @@ import time
4
 
5
  # ------------------ Page Setup ------------------
6
  st.set_page_config(page_title="๐ŸŽฎ Mini Game Arcade", layout="centered")
7
- st.title("๐ŸŽฎ Mini Game Arcade")
8
- st.caption("Enjoy a variety of mini games with a clean, fun interface!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  st.markdown("---")
10
 
11
  # ------------------ Game Selector ------------------
12
  games = [
13
- "Rock Paper Scissors",
14
- "Guess the Number",
15
- "Word Scramble",
16
- "Emoji Quiz",
17
- "Coin Toss",
18
- "Dice Roll",
19
- "Hangman (Mini)",
20
- "Math Quiz",
21
- "Quick Typing Challenge",
22
- "Memory Test"
23
  ]
24
 
25
- selected_game = st.selectbox("๐Ÿ•น๏ธ Pick a game to play", games)
26
  st.markdown("---")
27
 
28
  # ------------------ Game Functions ------------------
29
 
30
  def rock_paper_scissors():
31
  st.subheader("๐Ÿชจ Rock Paper Scissors")
32
- user = st.radio("Your move:", ["Rock", "Paper", "Scissors"], horizontal=True)
33
- if st.button("Play"):
34
  computer = random.choice(["Rock", "Paper", "Scissors"])
35
- st.write(f"Computer chose: **{computer}**")
36
  if user == computer:
37
- st.info("It's a draw!")
38
  elif (user == "Rock" and computer == "Scissors") or \
39
  (user == "Paper" and computer == "Rock") or \
40
  (user == "Scissors" and computer == "Paper"):
41
- st.success("You win!")
42
  else:
43
- st.error("You lose!")
44
 
45
  def guess_the_number():
46
- st.subheader("๐Ÿ”น Guess the Number (1-10)")
47
  number = random.randint(1, 10)
48
- guess = st.number_input("Enter your guess:", 1, 10, step=1)
49
- if st.button("Check"):
50
  if guess == number:
51
- st.success("Correct! ๐ŸŽ‰")
52
  else:
53
- st.error(f"Wrong! It was {number}")
54
 
55
  def word_scramble():
56
- st.subheader("๐ŸŒค๏ธ Word Scramble")
57
  words = ["python", "arcade", "streamlit", "banana", "gamer"]
58
  word = random.choice(words)
59
  scrambled = "".join(random.sample(word, len(word)))
60
  st.write(f"Unscramble this word: **{scrambled}**")
61
  guess = st.text_input("Your guess:")
62
- if st.button("Submit"):
63
  if guess.lower() == word:
64
- st.success("Correct!")
65
  else:
66
- st.error(f"Nope! The word was **{word}**")
67
 
68
  def emoji_quiz():
69
- st.subheader("๐Ÿ˜ Emoji Quiz")
70
  quiz = {
71
  "๐Ÿ•๐Ÿ”๐ŸŸ": "Fast Food",
72
  "๐Ÿš—๐Ÿšจ": "Speed",
@@ -76,23 +96,23 @@ def emoji_quiz():
76
  emojis, answer = random.choice(list(quiz.items()))
77
  st.write(f"What do these emojis mean? {emojis}")
78
  guess = st.text_input("Your answer:")
79
- if st.button("Check Answer"):
80
  if guess.lower() == answer.lower():
81
- st.success("Correct!")
82
  else:
83
- st.error(f"Correct answer was **{answer}**")
84
 
85
  def coin_toss():
86
  st.subheader("๐Ÿช™ Coin Toss")
87
- if st.button("Toss"):
88
  result = random.choice(["Heads", "Tails"])
89
- st.success(f"It's **{result}**!")
90
 
91
  def dice_roll():
92
  st.subheader("๐ŸŽฒ Dice Roll")
93
- if st.button("Roll"):
94
  result = random.randint(1, 6)
95
- st.success(f"You rolled a **{result}**!")
96
 
97
  def hangman_mini():
98
  st.subheader("๐Ÿ‘ป Hangman (Mini)")
@@ -100,34 +120,34 @@ def hangman_mini():
100
  word = random.choice(words)
101
  st.info(f"Hint: The word has {len(word)} letters.")
102
  guess = st.text_input("Guess the word:")
103
- if st.button("Reveal"):
104
  if guess.lower() == word:
105
- st.success("Correct!")
106
  else:
107
- st.error(f"The word was **{word}**")
108
 
109
  def math_quiz():
110
  st.subheader("โž• Math Quiz")
111
  a = random.randint(1, 20)
112
  b = random.randint(1, 20)
113
- st.write(f"What is {a} + {b}?")
114
  answer = st.number_input("Your answer:", step=1)
115
- if st.button("Submit"):
116
  if answer == a + b:
117
- st.success("Correct!")
118
  else:
119
- st.error(f"Wrong! It was **{a + b}**")
120
 
121
  def quick_typing():
122
  st.subheader("โŒจ๏ธ Quick Typing Challenge")
123
  word = random.choice(["elephant", "keyboard", "arcade", "stream", "python"])
124
- st.info(f"Type this word exactly: **{word}**")
125
- user_input = st.text_input("Start typing:")
126
- if st.button("Submit"):
127
  if user_input == word:
128
- st.success("Well done!")
129
  else:
130
- st.error("Mismatch! Try again.")
131
 
132
  def memory_test():
133
  st.subheader("๐Ÿง  Memory Test")
@@ -135,37 +155,37 @@ def memory_test():
135
  st.info("Remember these numbers:")
136
  st.code(nums)
137
  time.sleep(2)
138
- st.write("Now enter any one number you remember:")
139
- guess = st.number_input("Enter a number:", step=1)
140
- if st.button("Check"):
141
  if guess in nums:
142
- st.success("Correct!")
143
  else:
144
- st.error(f"Oops! Numbers were: {nums}")
145
 
146
  # ------------------ Game Dispatcher ------------------
147
 
148
- if selected_game == "Rock Paper Scissors":
149
  rock_paper_scissors()
150
- elif selected_game == "Guess the Number":
151
  guess_the_number()
152
- elif selected_game == "Word Scramble":
153
  word_scramble()
154
- elif selected_game == "Emoji Quiz":
155
  emoji_quiz()
156
- elif selected_game == "Coin Toss":
157
  coin_toss()
158
- elif selected_game == "Dice Roll":
159
  dice_roll()
160
- elif selected_game == "Hangman (Mini)":
161
  hangman_mini()
162
- elif selected_game == "Math Quiz":
163
  math_quiz()
164
- elif selected_game == "Quick Typing Challenge":
165
  quick_typing()
166
- elif selected_game == "Memory Test":
167
  memory_test()
168
 
169
  # ------------------ Footer ------------------
170
  st.markdown("---")
171
- st.markdown("<center>Made with โค๏ธ for fun and learning.</center>", unsafe_allow_html=True)
 
4
 
5
  # ------------------ Page Setup ------------------
6
  st.set_page_config(page_title="๐ŸŽฎ Mini Game Arcade", layout="centered")
7
+ st.markdown("""
8
+ <style>
9
+ .stApp {
10
+ background-color: #fdfdfd;
11
+ }
12
+ .title-style {
13
+ font-size: 3em;
14
+ text-align: center;
15
+ font-weight: bold;
16
+ margin-bottom: 0;
17
+ }
18
+ .subtitle-style {
19
+ text-align: center;
20
+ font-size: 1.2em;
21
+ color: #555;
22
+ margin-top: 0;
23
+ }
24
+ </style>
25
+ """, unsafe_allow_html=True)
26
+
27
+ st.markdown("<div class='title-style'>๐ŸŽฎ Mini Game Arcade</div>", unsafe_allow_html=True)
28
+ st.markdown("<div class='subtitle-style'>Enjoy a variety of mini games with a sleek, fun interface!</div>", unsafe_allow_html=True)
29
  st.markdown("---")
30
 
31
  # ------------------ Game Selector ------------------
32
  games = [
33
+ "๐ŸŽฎ Rock Paper Scissors",
34
+ "๐Ÿ”ข Guess the Number",
35
+ "๐Ÿ”€ Word Scramble",
36
+ "๐Ÿ˜Š Emoji Quiz",
37
+ "๐Ÿช™ Coin Toss",
38
+ "๐ŸŽฒ Dice Roll",
39
+ "๐Ÿ‘ป Hangman (Mini)",
40
+ "โž• Math Quiz",
41
+ "โŒจ๏ธ Quick Typing Challenge",
42
+ "๐Ÿง  Memory Test"
43
  ]
44
 
45
+ selected_game = st.selectbox("๐ŸŽฏ Pick a game to play", games)
46
  st.markdown("---")
47
 
48
  # ------------------ Game Functions ------------------
49
 
50
  def rock_paper_scissors():
51
  st.subheader("๐Ÿชจ Rock Paper Scissors")
52
+ user = st.radio("Choose your move:", ["Rock", "Paper", "Scissors"], horizontal=True)
53
+ if st.button("๐Ÿ’ฅ Play Now"):
54
  computer = random.choice(["Rock", "Paper", "Scissors"])
55
+ st.write(f"๐Ÿค– Computer chose: **{computer}**")
56
  if user == computer:
57
+ st.info("๐Ÿ˜ It's a draw!")
58
  elif (user == "Rock" and computer == "Scissors") or \
59
  (user == "Paper" and computer == "Rock") or \
60
  (user == "Scissors" and computer == "Paper"):
61
+ st.success("๐ŸŽ‰ You win!")
62
  else:
63
+ st.error("๐Ÿ’€ You lose!")
64
 
65
  def guess_the_number():
66
+ st.subheader("๐Ÿ”ข Guess the Number (1โ€“10)")
67
  number = random.randint(1, 10)
68
+ guess = st.number_input("Your guess:", 1, 10)
69
+ if st.button("๐ŸŽฏ Check"):
70
  if guess == number:
71
+ st.success("๐ŸŽ‰ Correct!")
72
  else:
73
+ st.error(f"๐Ÿ˜ข Nope! It was {number}")
74
 
75
  def word_scramble():
76
+ st.subheader("๐Ÿ”€ Word Scramble")
77
  words = ["python", "arcade", "streamlit", "banana", "gamer"]
78
  word = random.choice(words)
79
  scrambled = "".join(random.sample(word, len(word)))
80
  st.write(f"Unscramble this word: **{scrambled}**")
81
  guess = st.text_input("Your guess:")
82
+ if st.button("๐Ÿงฉ Submit"):
83
  if guess.lower() == word:
84
+ st.success("๐ŸŽ‰ Correct!")
85
  else:
86
+ st.error(f"๐Ÿšซ Nope! The word was **{word}**")
87
 
88
  def emoji_quiz():
89
+ st.subheader("๐Ÿ˜Š Emoji Quiz")
90
  quiz = {
91
  "๐Ÿ•๐Ÿ”๐ŸŸ": "Fast Food",
92
  "๐Ÿš—๐Ÿšจ": "Speed",
 
96
  emojis, answer = random.choice(list(quiz.items()))
97
  st.write(f"What do these emojis mean? {emojis}")
98
  guess = st.text_input("Your answer:")
99
+ if st.button("๐Ÿ” Check Answer"):
100
  if guess.lower() == answer.lower():
101
+ st.success("๐ŸŽฏ Correct!")
102
  else:
103
+ st.error(f"โŒ It was **{answer}**")
104
 
105
  def coin_toss():
106
  st.subheader("๐Ÿช™ Coin Toss")
107
+ if st.button("๐ŸŽฒ Toss Coin"):
108
  result = random.choice(["Heads", "Tails"])
109
+ st.success(f"๐Ÿช™ It's **{result}**!")
110
 
111
  def dice_roll():
112
  st.subheader("๐ŸŽฒ Dice Roll")
113
+ if st.button("๐ŸŽฏ Roll Dice"):
114
  result = random.randint(1, 6)
115
+ st.success(f"๐ŸŽ‰ You rolled a **{result}**!")
116
 
117
  def hangman_mini():
118
  st.subheader("๐Ÿ‘ป Hangman (Mini)")
 
120
  word = random.choice(words)
121
  st.info(f"Hint: The word has {len(word)} letters.")
122
  guess = st.text_input("Guess the word:")
123
+ if st.button("๐Ÿ•ต๏ธ Reveal"):
124
  if guess.lower() == word:
125
+ st.success("โœ… Correct!")
126
  else:
127
+ st.error(f"๐Ÿ™ˆ The word was **{word}**")
128
 
129
  def math_quiz():
130
  st.subheader("โž• Math Quiz")
131
  a = random.randint(1, 20)
132
  b = random.randint(1, 20)
133
+ st.write(f"Solve: {a} + {b}")
134
  answer = st.number_input("Your answer:", step=1)
135
+ if st.button("๐Ÿง  Submit"):
136
  if answer == a + b:
137
+ st.success("๐ŸŽ‰ Correct!")
138
  else:
139
+ st.error(f"๐Ÿ˜ž Wrong! It was **{a + b}**")
140
 
141
  def quick_typing():
142
  st.subheader("โŒจ๏ธ Quick Typing Challenge")
143
  word = random.choice(["elephant", "keyboard", "arcade", "stream", "python"])
144
+ st.info(f"Type this exactly: **{word}**")
145
+ user_input = st.text_input("Your input:")
146
+ if st.button("๐Ÿš€ Submit"):
147
  if user_input == word:
148
+ st.success("๐Ÿ”ฅ Perfect!")
149
  else:
150
+ st.error("๐Ÿ˜ฌ Mismatch. Try again!")
151
 
152
  def memory_test():
153
  st.subheader("๐Ÿง  Memory Test")
 
155
  st.info("Remember these numbers:")
156
  st.code(nums)
157
  time.sleep(2)
158
+ st.write("Enter any one number you remember:")
159
+ guess = st.number_input("Your guess:", step=1)
160
+ if st.button("๐Ÿ”Ž Check"):
161
  if guess in nums:
162
+ st.success("๐ŸŽฏ Correct!")
163
  else:
164
+ st.error(f"๐Ÿ’” Nope! Numbers were: {nums}")
165
 
166
  # ------------------ Game Dispatcher ------------------
167
 
168
+ if selected_game.endswith("Rock Paper Scissors"):
169
  rock_paper_scissors()
170
+ elif selected_game.endswith("Guess the Number"):
171
  guess_the_number()
172
+ elif selected_game.endswith("Word Scramble"):
173
  word_scramble()
174
+ elif selected_game.endswith("Emoji Quiz"):
175
  emoji_quiz()
176
+ elif selected_game.endswith("Coin Toss"):
177
  coin_toss()
178
+ elif selected_game.endswith("Dice Roll"):
179
  dice_roll()
180
+ elif selected_game.endswith("Hangman (Mini)"):
181
  hangman_mini()
182
+ elif selected_game.endswith("Math Quiz"):
183
  math_quiz()
184
+ elif selected_game.endswith("Quick Typing Challenge"):
185
  quick_typing()
186
+ elif selected_game.endswith("Memory Test"):
187
  memory_test()
188
 
189
  # ------------------ Footer ------------------
190
  st.markdown("---")
191
+ st.markdown("<center><sub>Made with โค๏ธ for fun and learning.</sub></center>", unsafe_allow_html=True)