Spaces:
Build error
Build error
File size: 2,801 Bytes
c3235f9 02a63aa c3235f9 66454b8 c3235f9 02a63aa c3235f9 02a63aa 66454b8 02a63aa 66454b8 02a63aa c3235f9 02a63aa c3235f9 02a63aa c3235f9 66454b8 02a63aa c3235f9 02a63aa c3235f9 02a63aa 66454b8 c3235f9 02a63aa 66454b8 02a63aa 66454b8 02a63aa c3235f9 02a63aa c3235f9 | 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 | import streamlit as st
import random
# --- Custom CSS for Colorful Background ---
st.markdown(
"""
<style>
body {
background: linear-gradient(135deg, #FFDEE9 0%, #B5FFFC 100%);
color: #000000;
}
.stApp {
background: linear-gradient(135deg, #FFDEE9 0%, #B5FFFC 100%);
}
.stButton>button {
background-color: #FF7F50;
color: white;
font-size: 16px;
border-radius: 10px;
}
.stButton>button:hover {
background-color: #FF4500;
color: white;
}
</style>
""",
unsafe_allow_html=True
)
# --- Title and Instructions ---
st.title("๐ชจโ๏ธ๐ Rock-Paper-Scissors Game with Points")
st.write("Choose Rock, Paper, or Scissors and play against the computer! Each win earns you a point.")
# --- Options for the Game ---
choices = ["๐ชจ Rock", "๐ Paper", "โ๏ธ Scissors"]
# --- Initialize or Retrieve 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
# --- Display Current Scores ---
st.markdown(f"### **Your Score:** ๐ฏ {st.session_state.user_score}")
st.markdown(f"### **Computer Score:** ๐ค {st.session_state.computer_score}")
# --- User's Choice ---
user_choice = st.selectbox("Make your choice:", choices)
# --- Button to Submit the Choice ---
if st.button("๐ฎ Play"):
# Extract the actual choice (remove the emoji)
user_choice_text = user_choice.split()[1]
# Computer's random choice
computer_choice = random.choice(choices)
computer_choice_text = computer_choice.split()[1]
# Display both choices
st.write(f"**You chose:** {user_choice}")
st.write(f"**Computer chose:** {computer_choice}")
# Determine the winner and update scores
if user_choice_text == computer_choice_text:
st.info("๐ค It's a tie!")
elif (
(user_choice_text == "Rock" and computer_choice_text == "Scissors") or
(user_choice_text == "Paper" and computer_choice_text == "Rock") or
(user_choice_text == "Scissors" and computer_choice_text == "Paper")
):
st.success("๐ You win!")
st.session_state.user_score += 1
else:
st.error("๐ข You lose!")
st.session_state.computer_score += 1
# --- Reset Button to Restart the Game ---
if st.button("๐ Reset Scores"):
st.session_state.user_score = 0
st.session_state.computer_score = 0
st.success("โ
Scores have been reset!")
# --- Add Image for Fun ---
st.image("https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Rock-paper-scissors.svg/1920px-Rock-paper-scissors.svg.png", caption="Rock-Paper-Scissors", width=400)
|