Game / app.py
AIRaja's picture
Create app.py
b5d6e04 verified
import streamlit as st
import random
def initialize_game():
if 'money' not in st.session_state:
st.session_state.money = 100
st.session_state.heat = 0 # Police attention
st.session_state.message = "You start in a run-down apartment with $100. What do you do?"
def commit_crime(crime, risk, reward):
if random.random() < risk: # Chance of getting caught
st.session_state.heat += random.randint(10, 30)
st.session_state.money -= random.randint(10,50)
st.session_state.message = f"You got caught {crime}! You lost money and gained heat."
else:
st.session_state.money += reward
st.session_state.heat += random.randint(1, 5)
st.session_state.message = f"You successfully {crime}! You earned ${reward}."
def main():
st.title("Liberty City Life (Very Simplified)")
initialize_game()
st.write(f"Money: ${st.session_state.money}, Heat: {st.session_state.heat}")
st.write(st.session_state.message)
col1, col2 = st.columns(2)
with col1:
if st.button("Steal a car (risky)"):
commit_crime("stealing a car", 0.6, 200)
if st.button("Mug someone (easy)"):
commit_crime("mugging someone", 0.3, 50)
with col2:
if st.button("Work a day job (safe)"):
st.session_state.money += 100
st.session_state.heat -= min(st.session_state.heat, 5)
st.session_state.message = "You worked a day job and earned $100. Heat reduced."
if st.button("Go to sleep (reduce heat)"):
st.session_state.heat = max(0, st.session_state.heat - 20)
st.session_state.message = "You got some sleep. Heat reduced."
if st.session_state.heat > 100:
st.write("The cops are after you! Game over!")
del st.session_state.money
del st.session_state.heat
if __name__ == "__main__":
main()