-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.py
125 lines (90 loc) · 3.64 KB
/
action.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
import game
from player import Player
import world
import collections
def get_player_command():
"""the player input"""
return raw_input('Action: ').lower().strip()
### Main Script
#print("++++++++++++++++++++++++++++++++++")
#print("| DEATHSCHOOL!!!! |")
#print("| By: Cori Sparks |")
#print("++++++++++++++++++++++++++++++++++\n\n\n")
#print("You walk up the stairs on the first day of school.\n Something doesn't feel right......\n The parking lot was full, but building is eerily silent.\n")
#player = Player()
#while True:
## room = world.tile_at(player.x, player.y)
## print(room.intro_text())
## room.modify_player(player)
## action_input = get_player_command()
## if action_input == 'w':
## player.move_forward()
## elif action_input == 's':
## player.move_backward()
## elif action_input == 'a':
## player.move_left()
## elif action_input == 'd':
## player.move_right()
## elif action_input == 'b':
## player.print_pack()
## elif action_input == 'f':
## player.attack()
## elif action_input == 'h':
## player.heal()
## elif action_input == 'q':
## break
## else:
## print("Invalid!")
##
def action_adder(action_dict, hotkey, action, name):
action_dict[hotkey.lower()] = action
action_dict[hotkey.upper()] = action
print("{}: {}".format(hotkey, name))
def get_available_actions(room,player):
actions = collections.OrderedDict()
print ("Choose an action: ")
if player.backpack:
action_adder(actions, 'b', player.print_pack, "Print Backpack")
if isinstance (room, world.TraderTile):
action_adder(actions, 't', player.trade, "Trade")
if isinstance (room, world.EnemyTile) and room.enemy.is_alive():
action_adder(actions, 'f', player.attack, "Fight!")
else:
if world.tile_at(room.x, room.y - 1):
action_adder(actions, 'w', player.move_forward, "Go Forward!")
if world.tile_at(room.x, room.y + 1):
action_adder(actions, 's', player.move_backward, "Go Backward!")
if world.tile_at(room.x + 1, room.y):
action_adder(actions, 'd', player.move_right, "Go Right!")
if world.tile_at(room.x - 1, room.y):
action_adder(actions, 'a', player.move_left, "Go Left!")
if player.lifepoints < 100:
action_adder(actions, 'h', player.heal, "Heal")
return actions
def choose_action(room, player):
action = None
while not action:
available_actions = get_available_actions(room, player)
action_input = raw_input("Action: ").lower().strip()
action = available_actions.get(action_input)
if action:
action()
else:
print("Invalid action!")
def play():
print("++++++++++++++++++++++++++++++++++")
print("| DEATHSCHOOL!!!! |")
print("| By: Cori Sparks |")
print("++++++++++++++++++++++++++++++++++\n\n\n")
print("You walk up the stairs on the first day of school.\n Something doesn't feel right......\n The parking lot was full, but building is eerily silent.\n")
player = Player()
while True:
room = world.tile_at(player.x, player.y)
print(room.intro_text())
room.modify_player(player)
choose_action(room, player)
if player.is_alive() and not player.victory:
choose_action(room,player)
elif not player.is_alive():
print("Failure...")
play()