File size: 3,159 Bytes
40e22e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
87
88
89
90
91
92
93
94
95
96
97
98
99
import streamlit as st
import random

# Game Settings
MAP_SIZE = 20  # 20 km x 20 km map

# Initialize session state
if "player_position" not in st.session_state:
    st.session_state.player_position = [10, 10]  # Start in the center
if "player_health" not in st.session_state:
    st.session_state.player_health = 100
if "enemy_health" not in st.session_state:
    st.session_state.enemy_health = random.randint(50, 100)
if "inventory" not in st.session_state:
    st.session_state.inventory = {"vehicles": "Car", "weapons": ["UMP"]}

# Helper functions
def move_player(direction):
    if direction == "North" and st.session_state.player_position[1] < MAP_SIZE:
        st.session_state.player_position[1] += 1
    elif direction == "South" and st.session_state.player_position[1] > 0:
        st.session_state.player_position[1] -= 1
    elif direction == "East" and st.session_state.player_position[0] < MAP_SIZE:
        st.session_state.player_position[0] += 1
    elif direction == "West" and st.session_state.player_position[0] > 0:
        st.session_state.player_position[0] -= 1

def fight_enemy():
    weapon = st.session_state.inventory["weapons"][0]  # Use the first weapon
    damage = random.randint(10, 30)
    st.session_state.enemy_health -= damage
    st.write(f"You used {weapon} and dealt {damage} damage!")

    # Enemy counterattack
    if st.session_state.enemy_health > 0:
        enemy_damage = random.randint(5, 20)
        st.session_state.player_health -= enemy_damage
        st.write(f"The enemy attacked and dealt {enemy_damage} damage!")
    else:
        st.write("Enemy defeated!")

def explore():
    event = random.choice(["Nothing found", "Found ammo", "Enemy encountered"])
    st.write(f"Exploring... {event}")
    if event == "Found ammo":
        st.session_state.inventory["weapons"].append(random.choice(["AK-47", "Pistol"]))
        st.write("You found a new weapon!")
    elif event == "Enemy encountered":
        st.session_state.enemy_health = random.randint(50, 100)
        st.write("An enemy appeared!")

# Game Interface
st.title("Adventure Game")

# Display Player Stats
st.subheader("Player Stats")
st.write(f"Health: {st.session_state.player_health}")
st.write(f"Position: {st.session_state.player_position}")
st.write(f"Inventory: {st.session_state.inventory}")

# Display Enemy Stats (if any)
if st.session_state.enemy_health > 0:
    st.subheader("Enemy Stats")
    st.write(f"Enemy Health: {st.session_state.enemy_health}")

# Game Actions
st.subheader("Actions")

# Movement
st.write("Move:")
col1, col2, col3 = st.columns(3)
with col1:
    if st.button("North"):
        move_player("North")
with col2:
    if st.button("South"):
        move_player("South")
with col3:
    if st.button("East"):
        move_player("East")
if st.button("West"):
    move_player("West")

# Fight
if st.session_state.enemy_health > 0:
    if st.button("Fight"):
        fight_enemy()

# Explore
if st.button("Explore"):
    explore()

# End Game if Health <= 0
if st.session_state.player_health <= 0:
    st.write("Game Over! You have been defeated.")
    st.stop()

st.write("Keep playing and exploring the map!")