Spaces:
Sleeping
Sleeping
File size: 2,207 Bytes
b5a9731 f0e0b62 b5a9731 f0e0b62 b5a9731 f0e0b62 b5a9731 f0e0b62 b5a9731 f0e0b62 b5a9731 f0e0b62 b5a9731 f0e0b62 b5a9731 f0e0b62 b5a9731 |
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 |
import streamlit as st
import random
# Set up the app title and description
st.set_page_config(page_title="Rock Paper Scissors", page_icon="βοΈ", layout="centered")
st.title("Rock Paper Scissors Game βποΈβοΈ")
st.markdown("""
Play a game of **Rock-Paper-Scissors** against the computer!
Choose your move below, and see if you can outscore the machine.
""")
# Initialize session state variables 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
# Choices for the game
choices = ["Rock", "Paper", "Scissors"]
# Mapping choices to emojis
emoji_map = {"Rock": "β", "Paper": "ποΈ", "Scissors": "βοΈ"}
# Function to determine the winner and update scores
def determine_winner(user_choice, computer_choice):
if user_choice == computer_choice:
return "It's a tie! π€"
elif (
(user_choice == "Rock" and computer_choice == "Scissors") or
(user_choice == "Paper" and computer_choice == "Rock") or
(user_choice == "Scissors" and computer_choice == "Paper")
):
st.session_state['user_score'] += 1
return "You win! π"
else:
st.session_state['computer_score'] += 1
return "You lose! π’"
# Display current scores
st.sidebar.header("Scores")
st.sidebar.write(f"**Your Score:** {st.session_state['user_score']}")
st.sidebar.write(f"**Computer's Score:** {st.session_state['computer_score']}")
# User's choice
user_choice = st.radio("Choose your move:", choices)
# Generate computer's choice and play the game
if st.button("Play"):
computer_choice = random.choice(choices)
# Display choices
st.write(f"**You chose:** {emoji_map[user_choice]} {user_choice}")
st.write(f"**Computer chose:** {emoji_map[computer_choice]} {computer_choice}")
# Determine the winner
result = determine_winner(user_choice, computer_choice)
st.subheader(result)
# Reset Scores Button
if st.sidebar.button("Reset Scores"):
st.session_state['user_score'] = 0
st.session_state['computer_score'] = 0
st.sidebar.success("Scores have been reset!")
|