Game / app.py
Amelia-James's picture
Create app.py
f62874c verified
import streamlit as st
import random
# Page config (wide layout + nicer title)
st.set_page_config(page_title="๐ŸŽฎ Rock Paper Scissors", layout="wide")
# Custom CSS for buttons
st.markdown("""
<style>
.btn-img {
background:none;
border:none;
padding: 10px;
cursor: pointer;
}
.btn-img:hover {
transform: scale(1.2);
transition-duration: 0.2s;
}
</style>
""", unsafe_allow_html=True)
st.title("๐Ÿชจ๐Ÿ“„โœ‚๏ธ Rock Paper Scissors")
# Show choices as images (you can replace URLs with your own hosted images)
col1, col2, col3 = st.columns(3)
with col1:
if st.button("๐Ÿชจ Rock", key="rock"):
user_choice = "Rock"
with col2:
if st.button("๐Ÿ“„ Paper", key="paper"):
user_choice = "Paper"
with col3:
if st.button("โœ‚๏ธ Scissors", key="scissors"):
user_choice = "Scissors"
try:
user_choice
except NameError:
st.write("๐Ÿ‘‰ **Choose Rock, Paper, or Scissors to start!**")
else:
# Computer move
computer_choice = random.choice(["Rock", "Paper", "Scissors"])
# Display choices
st.markdown(f"๐Ÿ’ก **You chose:** {user_choice}")
st.markdown(f"๐Ÿค– **Computer chose:** {computer_choice}")
# Result logic
if user_choice == computer_choice:
st.info("๐Ÿค 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.balloons()
st.success("๐ŸŽ‰ You win!")
else:
st.error("๐Ÿ˜ข You lose!")