FaizaRiaz commited on
Commit
6d60025
·
verified ·
1 Parent(s): 9b66c05

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +156 -0
app.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import random
3
+
4
+ # Title
5
+ st.title("🎮 Mini Game Arcade")
6
+
7
+ # Sidebar Menu
8
+ game = st.sidebar.selectbox(
9
+ "Choose a Game",
10
+ [
11
+ "Rock Paper Scissors",
12
+ "Guess the Number",
13
+ "Word Scramble",
14
+ "Emoji Quiz",
15
+ "Score Tracker",
16
+ "Dice Roller",
17
+ "Coin Toss",
18
+ "Math Quiz",
19
+ "Hangman",
20
+ "Color Guess"
21
+ ]
22
+ )
23
+
24
+ # Rock Paper Scissors
25
+ if game == "Rock Paper Scissors":
26
+ st.header("🪨📄✂️ Rock Paper Scissors")
27
+ options = ["Rock", "Paper", "Scissors"]
28
+ user_choice = st.selectbox("Choose your move:", options)
29
+ if st.button("Play"):
30
+ ai_choice = random.choice(options)
31
+ st.write(f"Computer chose: {ai_choice}")
32
+ if user_choice == ai_choice:
33
+ st.success("It's a tie!")
34
+ elif (user_choice == "Rock" and ai_choice == "Scissors") or \
35
+ (user_choice == "Paper" and ai_choice == "Rock") or \
36
+ (user_choice == "Scissors" and ai_choice == "Paper"):
37
+ st.success("You win!")
38
+ else:
39
+ st.error("You lose!")
40
+
41
+ # Guess the Number
42
+ elif game == "Guess the Number":
43
+ st.header("🔢 Guess the Number")
44
+ number = random.randint(1, 100)
45
+ guess = st.number_input("Guess a number between 1 and 100:", 1, 100)
46
+ if st.button("Check"):
47
+ if guess == number:
48
+ st.success("Correct! 🎉")
49
+ elif guess < number:
50
+ st.info("Try higher!")
51
+ else:
52
+ st.info("Try lower!")
53
+
54
+ # Word Scramble
55
+ elif game == "Word Scramble":
56
+ st.header("🔤 Word Scramble")
57
+ words = ["streamlit", "python", "arcade", "game", "computer"]
58
+ word = random.choice(words)
59
+ scrambled = "".join(random.sample(word, len(word)))
60
+ st.write(f"Scrambled word: {scrambled}")
61
+ user_guess = st.text_input("Guess the original word:")
62
+ if st.button("Submit"):
63
+ if user_guess.lower() == word:
64
+ st.success("Correct!")
65
+ else:
66
+ st.error("Try again!")
67
+
68
+ # Emoji Quiz
69
+ elif game == "Emoji Quiz":
70
+ st.header("😄 Emoji Quiz")
71
+ quiz = {
72
+ "🐱🐶": "animals",
73
+ "🎬🍿": "movie",
74
+ "🎓📚": "study",
75
+ "🍕🍔": "food"
76
+ }
77
+ emojis, answer = random.choice(list(quiz.items()))
78
+ st.write(f"What category do these emojis represent? {emojis}")
79
+ guess = st.text_input("Your answer:")
80
+ if st.button("Answer"):
81
+ if guess.lower() == answer:
82
+ st.success("Correct!")
83
+ else:
84
+ st.error("Nope! Try again.")
85
+
86
+ # Score Tracker
87
+ elif game == "Score Tracker":
88
+ st.header("📊 Score Tracker")
89
+ if "score" not in st.session_state:
90
+ st.session_state.score = 0
91
+ add = st.button("➕ Add Point")
92
+ subtract = st.button("➖ Subtract Point")
93
+ reset = st.button("🔄 Reset")
94
+ if add:
95
+ st.session_state.score += 1
96
+ elif subtract:
97
+ st.session_state.score -= 1
98
+ elif reset:
99
+ st.session_state.score = 0
100
+ st.metric("Current Score", st.session_state.score)
101
+
102
+ # Dice Roller
103
+ elif game == "Dice Roller":
104
+ st.header("🎲 Dice Roller")
105
+ if st.button("Roll Dice"):
106
+ roll = random.randint(1, 6)
107
+ st.write(f"🎲 You rolled a {roll}")
108
+
109
+ # Coin Toss
110
+ elif game == "Coin Toss":
111
+ st.header("🪙 Coin Toss")
112
+ if st.button("Toss Coin"):
113
+ toss = random.choice(["Heads", "Tails"])
114
+ st.write(f"🪙 It's {toss}!")
115
+
116
+ # Math Quiz
117
+ elif game == "Math Quiz":
118
+ st.header("➕ Math Quiz")
119
+ a = random.randint(1, 20)
120
+ b = random.randint(1, 20)
121
+ st.write(f"What is {a} + {b}?")
122
+ answer = st.number_input("Your answer:", step=1)
123
+ if st.button("Submit Answer"):
124
+ if answer == a + b:
125
+ st.success("Correct!")
126
+ else:
127
+ st.error("Wrong answer!")
128
+
129
+ # Hangman (Very simple)
130
+ elif game == "Hangman":
131
+ st.header("🪓 Hangman (Lite)")
132
+ words = ["apple", "banana", "grape", "orange"]
133
+ if "hang_word" not in st.session_state:
134
+ st.session_state.hang_word = random.choice(words)
135
+ st.session_state.hang_guesses = []
136
+ guessed = st.text_input("Guess a letter:").lower()
137
+ if st.button("Submit Letter"):
138
+ if guessed in st.session_state.hang_word:
139
+ st.session_state.hang_guesses.append(guessed)
140
+ st.success("Correct!")
141
+ else:
142
+ st.error("Incorrect.")
143
+ display = " ".join([letter if letter in st.session_state.hang_guesses else "_" for letter in st.session_state.hang_word])
144
+ st.write("Word:", display)
145
+
146
+ # Color Guess
147
+ elif game == "Color Guess":
148
+ st.header("🎨 Color Guess")
149
+ colors = ["red", "blue", "green", "yellow", "purple"]
150
+ chosen_color = random.choice(colors)
151
+ guess = st.selectbox("Pick a color", colors)
152
+ if st.button("Guess Color"):
153
+ if guess == chosen_color:
154
+ st.success("Correct! 🎯")
155
+ else:
156
+ st.warning(f"Wrong! The color was {chosen_color}")