-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
executable file
·133 lines (105 loc) · 3.94 KB
/
game.py
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#Import core libs
import os
from core.libs import *
#Import all the items
from items import *
from items.weapons import *
from core import *
from mobiles import *
world = WorldMap([
[Room([Sword("Gideon's Destroyer"), Dagger("Gideon's Stabber")]), Room([], SlimeMobile("Bobo")), Room([], SlimeMobile("Baba")), Room(), Room(), Room(), Room(), Room(), Room(), Room()],
[Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room()],
[Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room()],
[Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room()],
[Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room()],
[Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room()],
[Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room()],
[Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room()],
[Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room()],
[Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room(), Room()],
])
player = None
game_running = True
# Game States
# Intro
# Menu
# Inventory
# GameWorld
game_state = "Intro"
while (game_running):
os.system("clear")
if game_state == "Intro":
intro_screen()
elif game_state == "Menu":
menu_screen(player)
elif game_state == "Inventory":
player.draw_inventory()
elif game_state == "GameWorld":
if world.rooms[player.x][player.y].monster is not None:
world.rooms[player.x][player.y].monster.attack(player)
if player.hits <= 0:
player = None
game_state = "Menu"
continue
world.draw_room(player)
player.draw_actions(world.rooms[player.x][player.y])
else:
pass
valid_action = False
while not valid_action:
action = getch()
if action.lower() == "q":
valid_action = True
game_running = False
os.system("clear")
if game_state == "Intro":
if action.lower() == " ":
game_state = "Menu"
valid_action = True
elif game_state == "Menu":
if action.lower() == "n":
player = PlayerMobile("Samantha")
valid_action = True
game_state = "GameWorld"
elif action.lower() == "r" and player is not None:
valid_action = True
game_state = "GameWorld"
elif game_state == "Inventory":
if action.lower() == "i":
valid_action = True
game_state = "GameWorld"
elif len(player.inventory) > 0:
try:
if int(action) >= 0 and int(action) < len(player.inventory):
valid_action = True
player.equip_item(int(action))
except:
pass
elif game_state == "GameWorld":
if action.lower() == "n" and player.can_move_north():
valid_action = True
player.move_north()
elif action.lower() == "s" and player.can_move_south():
valid_action = True
player.move_south()
elif action.lower() == "e" and player.can_move_east():
valid_action = True
player.move_east()
elif action.lower() == "w" and player.can_move_west():
valid_action = True
player.move_west()
elif action.lower() == "g" and len(world.rooms[player.x][player.y].items) > 0:
valid_action = True
player.grab_items(world.rooms[player.x][player.y])
elif action.lower() == "u" and world.rooms[player.x][player.y].monster is not None:
valid_action = True
monster = world.rooms[player.x][player.y].monster
player.attack(monster)
if monster.hits <= 0:
world.rooms[player.x][player.y].monster = None
elif action.lower() == "i":
valid_action = True
game_state = "Inventory"
elif action.lower() == "m":
valid_action = True
game_state = "Menu"