File size: 1,936 Bytes
0c0d366
 
 
 
beb29de
0c0d366
beb29de
 
 
 
 
 
 
 
 
0c0d366
 
beb29de
 
 
 
 
 
0c0d366
beb29de
0c0d366
beb29de
0c0d366
 
 
 
 
 
 
beb29de
0c0d366
 
 
 
beb29de
0c0d366
 
beb29de
0c0d366
 
 
 
 
beb29de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import random

# Title
st.title("🎮 Rock-Paper-Scissors Game 🎮")

# Sidebar for Instructions
st.sidebar.title("How to Play")
st.sidebar.write("""
1. Choose your move: Rock, Paper, or Scissors.  
2. Click the "Play" button to see the result.  
3. Earn points by beating the computer!  
   - Rock beats Scissors.  
   - Scissors beats Paper.  
   - Paper beats Rock.
""")

# Initialize session state for scores
if "user_score" not in st.session_state:
    st.session_state.user_score = 0
if "computer_score" not in st.session_state:
    st.session_state.computer_score = 0

# User input
st.subheader("Choose your move:")
choices = ["Rock", "Paper", "Scissors"]
user_choice = st.selectbox("Select your move:", choices)

# Play the game
if st.button("Play"):
    computer_choice = random.choice(choices)

    # Determine the winner
    if user_choice == computer_choice:
        result = "It's a Tie! 🤝"
    elif (user_choice == "Rock" and computer_choice == "Scissors") or \
         (user_choice == "Scissors" and computer_choice == "Paper") or \
         (user_choice == "Paper" and computer_choice == "Rock"):
        result = "You Win! 🎉"
        st.session_state.user_score += 1
    else:
        result = "You Lose! 😢"
        st.session_state.computer_score += 1

    # Display results
    st.write(f"**Your Choice:** {user_choice}")
    st.write(f"**Computer's Choice:** {computer_choice}")
    st.subheader(result)

# Display Scores
st.write("---")
st.subheader("Scores")
col1, col2 = st.columns(2)
with col1:
    st.write(f"**Your Score:** {st.session_state.user_score}")
with col2:
    st.write(f"**Computer's Score:** {st.session_state.computer_score}")

# Reset scores
if st.button("Reset Scores"):
    st.session_state.user_score = 0
    st.session_state.computer_score = 0
    st.success("Scores have been reset!")

# Footer
st.write("---")
st.markdown("💻 **Developed by Abdullah**")