File size: 4,884 Bytes
64c34ca
8b1da88
 
085e7f5
8b1da88
 
085e7f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fab141
085e7f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fab141
085e7f5
 
 
 
 
 
 
 
 
 
 
 
6e5363d
085e7f5
 
 
 
 
 
 
 
 
 
 
 
 
6e5363d
085e7f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e5363d
085e7f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e5363d
085e7f5
 
 
 
 
 
6e5363d
085e7f5
 
 
 
 
 
6e5363d
085e7f5
 
 
 
 
 
 
 
 
 
 
 
6e5363d
085e7f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e5363d
085e7f5
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import streamlit as st
import random

# Title
st.title("๐ŸŽฎ Mini Game Arcade")

# Sidebar Menu
game = st.sidebar.selectbox(
    "Choose a Game",
    [
        "Rock Paper Scissors",
        "Guess the Number",
        "Word Scramble",
        "Emoji Quiz",
        "Score Tracker",
        "Dice Roller",
        "Coin Toss",
        "Math Quiz",
        "Hangman",
        "Color Guess"
    ]
)

# Rock Paper Scissors
if game == "Rock Paper Scissors":
    st.header("๐Ÿชจ๐Ÿ“„โœ‚๏ธ Rock Paper Scissors")
    options = ["Rock", "Paper", "Scissors"]
    user_choice = st.selectbox("Choose your move:", options)
    if st.button("Play"):
        ai_choice = random.choice(options)
        st.write(f"Computer chose: {ai_choice}")
        if user_choice == ai_choice:
            st.success("It's a tie!")
        elif (user_choice == "Rock" and ai_choice == "Scissors") or \
             (user_choice == "Paper" and ai_choice == "Rock") or \
             (user_choice == "Scissors" and ai_choice == "Paper"):
            st.success("You win!")
        else:
            st.error("You lose!")

# Guess the Number
elif game == "Guess the Number":
    st.header("๐Ÿ”ข Guess the Number")
    number = random.randint(1, 100)
    guess = st.number_input("Guess a number between 1 and 100:", 1, 100)
    if st.button("Check"):
        if guess == number:
            st.success("Correct! ๐ŸŽ‰")
        elif guess < number:
            st.info("Try higher!")
        else:
            st.info("Try lower!")

# Word Scramble
elif game == "Word Scramble":
    st.header("๐Ÿ”ค Word Scramble")
    words = ["streamlit", "python", "arcade", "game", "computer"]
    word = random.choice(words)
    scrambled = "".join(random.sample(word, len(word)))
    st.write(f"Scrambled word: {scrambled}")
    user_guess = st.text_input("Guess the original word:")
    if st.button("Submit"):
        if user_guess.lower() == word:
            st.success("Correct!")
        else:
            st.error("Try again!")

# Emoji Quiz
elif game == "Emoji Quiz":
    st.header("๐Ÿ˜„ Emoji Quiz")
    quiz = {
        "๐Ÿฑ๐Ÿถ": "animals",
        "๐ŸŽฌ๐Ÿฟ": "movie",
        "๐ŸŽ“๐Ÿ“š": "study",
        "๐Ÿ•๐Ÿ”": "food"
    }
    emojis, answer = random.choice(list(quiz.items()))
    st.write(f"What category do these emojis represent? {emojis}")
    guess = st.text_input("Your answer:")
    if st.button("Answer"):
        if guess.lower() == answer:
            st.success("Correct!")
        else:
            st.error("Nope! Try again.")

# Score Tracker
elif game == "Score Tracker":
    st.header("๐Ÿ“Š Score Tracker")
    if "score" not in st.session_state:
        st.session_state.score = 0
    add = st.button("โž• Add Point")
    subtract = st.button("โž– Subtract Point")
    reset = st.button("๐Ÿ”„ Reset")
    if add:
        st.session_state.score += 1
    elif subtract:
        st.session_state.score -= 1
    elif reset:
        st.session_state.score = 0
    st.metric("Current Score", st.session_state.score)

# Dice Roller
elif game == "Dice Roller":
    st.header("๐ŸŽฒ Dice Roller")
    if st.button("Roll Dice"):
        roll = random.randint(1, 6)
        st.write(f"๐ŸŽฒ You rolled a {roll}")

# Coin Toss
elif game == "Coin Toss":
    st.header("๐Ÿช™ Coin Toss")
    if st.button("Toss Coin"):
        toss = random.choice(["Heads", "Tails"])
        st.write(f"๐Ÿช™ It's {toss}!")

# Math Quiz
elif game == "Math Quiz":
    st.header("โž• Math Quiz")
    a = random.randint(1, 20)
    b = random.randint(1, 20)
    st.write(f"What is {a} + {b}?")
    answer = st.number_input("Your answer:", step=1)
    if st.button("Submit Answer"):
        if answer == a + b:
            st.success("Correct!")
        else:
            st.error("Wrong answer!")

# Hangman (Very simple)
elif game == "Hangman":
    st.header("๐Ÿช“ Hangman (Lite)")
    words = ["apple", "banana", "grape", "orange"]
    if "hang_word" not in st.session_state:
        st.session_state.hang_word = random.choice(words)
        st.session_state.hang_guesses = []
    guessed = st.text_input("Guess a letter:").lower()
    if st.button("Submit Letter"):
        if guessed in st.session_state.hang_word:
            st.session_state.hang_guesses.append(guessed)
            st.success("Correct!")
        else:
            st.error("Incorrect.")
    display = " ".join([letter if letter in st.session_state.hang_guesses else "_" for letter in st.session_state.hang_word])
    st.write("Word:", display)

# Color Guess
elif game == "Color Guess":
    st.header("๐ŸŽจ Color Guess")
    colors = ["red", "blue", "green", "yellow", "purple"]
    chosen_color = random.choice(colors)
    guess = st.selectbox("Pick a color", colors)
    if st.button("Guess Color"):
        if guess == chosen_color:
            st.success("Correct! ๐ŸŽฏ")
        else:
            st.warning(f"Wrong! The color was {chosen_color}")