chmawia commited on
Commit
40e22e0
·
verified ·
1 Parent(s): 93cb561

Create game

Browse files
Files changed (1) hide show
  1. game +98 -0
game CHANGED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import random
3
+
4
+ # Game Settings
5
+ MAP_SIZE = 20 # 20 km x 20 km map
6
+
7
+ # Initialize session state
8
+ if "player_position" not in st.session_state:
9
+ st.session_state.player_position = [10, 10] # Start in the center
10
+ if "player_health" not in st.session_state:
11
+ st.session_state.player_health = 100
12
+ if "enemy_health" not in st.session_state:
13
+ st.session_state.enemy_health = random.randint(50, 100)
14
+ if "inventory" not in st.session_state:
15
+ st.session_state.inventory = {"vehicles": "Car", "weapons": ["UMP"]}
16
+
17
+ # Helper functions
18
+ def move_player(direction):
19
+ if direction == "North" and st.session_state.player_position[1] < MAP_SIZE:
20
+ st.session_state.player_position[1] += 1
21
+ elif direction == "South" and st.session_state.player_position[1] > 0:
22
+ st.session_state.player_position[1] -= 1
23
+ elif direction == "East" and st.session_state.player_position[0] < MAP_SIZE:
24
+ st.session_state.player_position[0] += 1
25
+ elif direction == "West" and st.session_state.player_position[0] > 0:
26
+ st.session_state.player_position[0] -= 1
27
+
28
+ def fight_enemy():
29
+ weapon = st.session_state.inventory["weapons"][0] # Use the first weapon
30
+ damage = random.randint(10, 30)
31
+ st.session_state.enemy_health -= damage
32
+ st.write(f"You used {weapon} and dealt {damage} damage!")
33
+
34
+ # Enemy counterattack
35
+ if st.session_state.enemy_health > 0:
36
+ enemy_damage = random.randint(5, 20)
37
+ st.session_state.player_health -= enemy_damage
38
+ st.write(f"The enemy attacked and dealt {enemy_damage} damage!")
39
+ else:
40
+ st.write("Enemy defeated!")
41
+
42
+ def explore():
43
+ event = random.choice(["Nothing found", "Found ammo", "Enemy encountered"])
44
+ st.write(f"Exploring... {event}")
45
+ if event == "Found ammo":
46
+ st.session_state.inventory["weapons"].append(random.choice(["AK-47", "Pistol"]))
47
+ st.write("You found a new weapon!")
48
+ elif event == "Enemy encountered":
49
+ st.session_state.enemy_health = random.randint(50, 100)
50
+ st.write("An enemy appeared!")
51
+
52
+ # Game Interface
53
+ st.title("Adventure Game")
54
+
55
+ # Display Player Stats
56
+ st.subheader("Player Stats")
57
+ st.write(f"Health: {st.session_state.player_health}")
58
+ st.write(f"Position: {st.session_state.player_position}")
59
+ st.write(f"Inventory: {st.session_state.inventory}")
60
+
61
+ # Display Enemy Stats (if any)
62
+ if st.session_state.enemy_health > 0:
63
+ st.subheader("Enemy Stats")
64
+ st.write(f"Enemy Health: {st.session_state.enemy_health}")
65
+
66
+ # Game Actions
67
+ st.subheader("Actions")
68
+
69
+ # Movement
70
+ st.write("Move:")
71
+ col1, col2, col3 = st.columns(3)
72
+ with col1:
73
+ if st.button("North"):
74
+ move_player("North")
75
+ with col2:
76
+ if st.button("South"):
77
+ move_player("South")
78
+ with col3:
79
+ if st.button("East"):
80
+ move_player("East")
81
+ if st.button("West"):
82
+ move_player("West")
83
+
84
+ # Fight
85
+ if st.session_state.enemy_health > 0:
86
+ if st.button("Fight"):
87
+ fight_enemy()
88
+
89
+ # Explore
90
+ if st.button("Explore"):
91
+ explore()
92
+
93
+ # End Game if Health <= 0
94
+ if st.session_state.player_health <= 0:
95
+ st.write("Game Over! You have been defeated.")
96
+ st.stop()
97
+
98
+ st.write("Keep playing and exploring the map!")