-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdgame2.py
96 lines (80 loc) · 2.99 KB
/
cmdgame2.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
import cmd
import world, tiles, items
from player import Player
from helpa import helpa
from npcschedule import sched
#from action_parse import action_parser
from action_parser import action_parser
from parse_translate import parse_translate # natural languiage to game speak
def describe_room(room):
print "\tMoves: {}".format(player.moves)
print "\t{}".format(room.room_name()),
mytime = player.time.strftime("%H:%M")
print mytime
print room.intro_text()
if room.inventory:
for item in room.inventory:
print "\t{} is here.".format(item.name)
if room.npcs:
for npc in room.npcs:
print "\t{} is here.".format(npc.name)
room.default(player)
if room.npcs:
for npc in room.npcs:
#npc.default(player)
pass
room.exits_text(player)
# for x, y in world.allrooms():
# print x, y
# tmproom= world.tile_exists(x, y)
# if tmproom and tmproom.npcs:
# for npc in tmproom.npcs:
# npc.default(player)
def play():
world.load_tiles()
global player
player = Player()
global room
room = world.tile_exists(player.location_x, player.location_y)
mapref = world.mapref()
for k in mapref:
print k
print mapref[k]
print type(mapref)
describe_room(room)
while player.is_alive() and not player.victory:
room = world.tile_exists(player.location_x, player.location_y)
loc = [player.location_x, player.location_y]
# room.modify_player(player)
if player.is_alive() and not player.victory:
global available_actions
available_actions = room.available_actions()
if player.moves > 0:
# print "Running all rooms NPC default"
room.default(player)
temp = world.allrooms()
npclist =[]
for x, y in temp:
tmproom= world.tile_exists(x, y)
if tmproom and tmproom.npcs:
for npc in tmproom.npcs:
if npc.name not in npclist: #we haven't called default on npc yet for this move
npc.default(player, world)
npclist.append(npc.name)
#print "called default on {}".format(npc.name)
Prompt().cmdloop()
class Prompt(cmd.Cmd):
"""Simple command processor example."""
prompt = '\t> '
def default(self, line):
action_input = parse_translate(line)
if "npcschedule" in action_input:
sched(action_input, available_actions, player, room)
return
if action_input != "ERROR":
action_parser(action_input, available_actions, player, room)
return line
def do_help(self, tmp="tmp"):# cmd _do_help func takes two arguments so faking it in order to override and call helpa()
helpa()
if __name__ == "__main__":
play()