import streamlit as st import random # --- Custom CSS for Colorful Background --- st.markdown( """ """, 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)