import streamlit as st import random # ----------------------------- # Page Configuration # ----------------------------- st.set_page_config( page_title="Rock Paper Scissors Game", page_icon="🎮", layout="centered" ) # ----------------------------- # 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 if "draws" not in st.session_state: st.session_state.draws = 0 # ----------------------------- # Title # ----------------------------- st.title("🎮 Rock Paper Scissors Game") st.write("Play against the computer!") # ----------------------------- # User Choice # ----------------------------- choices = ["Rock", "Paper", "Scissors"] user_choice = st.selectbox( "Choose your move:", choices ) # ----------------------------- # Play Button # ----------------------------- if st.button("Play"): computer_choice = random.choice(choices) st.subheader("Results") st.write(f"🧑 Your Choice: **{user_choice}**") st.write(f"💻 Computer Choice: **{computer_choice}**") # ----------------------------- # Game Logic # ----------------------------- if user_choice == computer_choice: result = "It's a Draw!" st.session_state.draws += 1 elif ( (user_choice == "Rock" and computer_choice == "Scissors") or (user_choice == "Paper" and computer_choice == "Rock") or (user_choice == "Scissors" and computer_choice == "Paper") ): result = "🎉 You Win!" st.session_state.user_score += 1 else: result = "😢 Computer Wins!" st.session_state.computer_score += 1 st.success(result) # ----------------------------- # Score Board # ----------------------------- st.markdown("---") st.subheader("🏆 Score Board") col1, col2, col3 = st.columns(3) with col1: st.metric("🧑 You", st.session_state.user_score) with col2: st.metric("💻 Computer", st.session_state.computer_score) with col3: st.metric("🤝 Draws", st.session_state.draws) # ----------------------------- # Reset Button # ----------------------------- if st.button("Reset Scores"): st.session_state.user_score = 0 st.session_state.computer_score = 0 st.session_state.draws = 0 st.success("Scores Reset Successfully!")