-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
85 lines (75 loc) · 2.41 KB
/
main.py
File metadata and controls
85 lines (75 loc) · 2.41 KB
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
import os
import game
player = game.player
world = game.world
inventory = game.inventory
obj = game.object
npc = game.npc
def clearConsole():
command = 'clear'
if os.name in ('nt', 'dos'): # If computer is running windows use cls
command = 'cls'
os.system(command)
# Set up the evironment
# The main spawn
room_spawn = world.Room('Spawn',
[
["#", "?", "#", "#", "#"],
["#", ".", ".", ".", "#"],
["#", ".", "#", ".", "#"],
["#", ".", ".", ".", "#"],
["#", "#", "#", "#", "#"]
]
)
# Closet room
room_closet = world.Room('Closet',
[
["#", "?", "#", "#"],
["#", ".", ".", "#"],
["#", ".", ".", "#"],
["#", "#", "#", "#"]
]
)
TestChar = player.Character("TestChar",room_spawn,1,1)
# Door Initialization
room_spawn.add_door(1,0,room_closet,1,1)
room_closet.add_door(1,0,room_spawn,1,1)
# Chests Initialization
chest = obj.Chest({
"Coin": 5,
"SmallPotion": 1
})
# Npcs Initialization
badguy = npc.Enemy("Badguy", health=30, damage=5)
room_spawn.add_npc(3, 3, badguy)
room_closet.add_chest(2, 2, chest)
print("Useful commands are: inventory, loot, use")
print("To move, type the direction, up/left/right/down")
print(f"Current room: {TestChar.room.name}")
for i in TestChar.look():
print(i)
try:
while True:
if TestChar.alive:
i = input()
clearConsole()
if i == "inventory":
print(TestChar.invsee())
elif i == "loot":
print(TestChar.loot())
elif i.startswith("use "):
try:
item = i.split()[1]
print(TestChar.use(item))
except IndexError:
print("Use what? (Example: use SmallPotion)")
else:
TestChar.move(i)
if TestChar.alive:
print(f"Current room: {TestChar.room.name}, Current health: {TestChar.health}/{TestChar.maxhealth}")
for i in TestChar.look():
print(i)
else:
break
except KeyboardInterrupt:
print("Closing program...")