-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNode.py
181 lines (150 loc) · 6.2 KB
/
Node.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
"""
Final Project Class. Implements the nodes and their affects on the robot.
This class creates the different node types that are stored within the map and defines their interactions with the robot
"""
import random
import time
class Node:
start = False
end = False
def __init__(self):
self.type = "wall"
self.encountered = False
# TODO: Need to implement a general method to check if the node is the end and if the robot has the key. If so, the game is over.
def performAction(self, map, robot):
pass
def getType(self):
return self.type
def __str__(self):
return f"[N: {self.type} v: {self.encountered}]"
def getEnd(self):
return self.end
def setEnd(self, bool):
self.end = bool
def setStart(self, bool):
self.start = bool
def getStart(self):
return self.start
def checkEnd(self, robot):
if self.end and robot.getKey():
print("You won!")
robot.bot.speak("Victory!")
exit()
elif self.end:
print("This is the exit, but I don't have a key")
robot.bot.speak("This is the exit, but I don't have a key.")
class EmptyNode(Node):
def __init__(self):
self.type = "empty"
self.encountered = False
def performAction(self, map, robot):
if self.encountered == False:
self.encountered = True
print("There's nothing here")
robot.bot.speak("There's nothing here.")
else:
print("You've already been here")
robot.bot.speak("We've already been here")
# TODO: I have not added a fight node to the map so this has not been tested.
class FightNode(Node):
# Name : [Health, Damage]
enemies = {"goblin" : [15, 5], "orc" : [30, 3], "giant spider" : [10, 2], "dragon" : [40, 10], "elf" : [2, 0]}
def __init__(self):
self.type = "fight"
self.encountered = False
self.enemy, stats = random.choice(list(self.enemies.items()))
self.enemyHealth = stats[0]
self.enemyAttack = stats[1]
self.enemyAlive = True
def performAction(self, map, robot):
self.encountered = True
if self.enemyAlive:
while self.enemyAlive: # If enemy alive
if robot.getHealth() > 0: # if robot alive
choice = robot.fightChoice(self.enemy, self.enemyHealth)
if choice == "attack":
print("ATTACK!!!!")
robot.bot.speak("Pinch Attack Go!")
robot.bot.moveArmUp()
time.sleep(1)
robot.bot.pinch()
time.sleep(1)
robot.bot.moveArmDown()
self.enemyHealth -= robot.getDamage()
if self.enemyHealth <= 0:
self.enemyKilled()
robot.bot.speak("Enemy Vanquished.")
else:
self.enemyTurn(robot)
elif choice == "retreat": # TODO: Add retreat condition
print("Attempting retreat\n")
robot.bot.speak("Run away!")
if random.random() <= 0.75:
print("Retreat Successful")
robot.bot.speak("Retreat Successful")
robot.retreat(map)
break
else:
print("Could not escape")
robot.bot.speak("I couldn't get away.")
self.enemyTurn(robot)
else:
print("You have been killed")
robot.bot.speak("I don't feel so good.")
print("Game Over")
robot.bot.speak("Game over.")
robot.bot.moveHeadDown()
time.sleep(1)
robot.bot.moveHeadDown()
time.sleep(1)
robot.bot.moveHeadDown()
time.sleep(1)
robot.bot.moveHeadDown()
time.sleep(1)
robot.bot.moveHeadDown()
exit()
else:
print(f"The scars of battle remain here, but the {self.enemy} has been long vanquished")
robot.bot.speak("The scars of battle remain here, but the enemy has been long vanquished")
# subtract enemy attack from robot health
def enemyTurn(self, robot):
robot.takeDamage(self.enemyAttack)
robot.bot.moveWaistLeft()
print("OUCH! Damage Taken")
robot.bot.speak("Ouch! I've been hit.")
time.sleep(1)
robot.bot.moveWaistRight()
# changes node type to empty once enemy is killed
def enemyKilled(self):
self.enemyAlive = False
print("enemy killed")
# TODO: needs to be implemented. Should replace the robots equiped weapon with something better. Select randomly from a list like the enemy node.
# One of these should also have a key. Or we could make it drop from a monster?
class ItemNode(Node):
def __init__(self):
self.type = "item"
self.encountered = False
def performAction(self, map, robot):
if self.encountered == False:
self.encountered = True
print("I found a key!")
robot.bot.speak("I found a Key!")
robot.setKey(True)
else:
print("You've already been here")
robot.bot.speak("We've already been here.")
# Heals robot to full health one time.
class HealthNode(Node):
def __init__(self):
self.type = "health"
self.encountered = False
def performAction(self, map, robot):
if self.encountered == False:
self.encountered = True
if robot.getHealth() < 80:
print("Found a health node. Health restored to 80")
robot.bot.speak("I found a spring. Health has been restored.")
robot.setHealth(80)
else:
print("You've already been here")
robot.bot.speak("We've already been here.")