|
import streamlit as st |
|
import random |
|
|
|
|
|
st.title("🎮 Rock-Paper-Scissors Game 🎮") |
|
|
|
|
|
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. |
|
""") |
|
|
|
|
|
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 |
|
|
|
|
|
st.subheader("Choose your move:") |
|
choices = ["Rock", "Paper", "Scissors"] |
|
user_choice = st.selectbox("Select your move:", choices) |
|
|
|
|
|
if st.button("Play"): |
|
computer_choice = random.choice(choices) |
|
|
|
|
|
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 |
|
|
|
|
|
st.write(f"**Your Choice:** {user_choice}") |
|
st.write(f"**Computer's Choice:** {computer_choice}") |
|
st.subheader(result) |
|
|
|
|
|
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}") |
|
|
|
|
|
if st.button("Reset Scores"): |
|
st.session_state.user_score = 0 |
|
st.session_state.computer_score = 0 |
|
st.success("Scores have been reset!") |
|
|
|
|
|
st.write("---") |
|
st.markdown("💻 **Developed by Abdullah**") |
|
|