-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRobot.py
62 lines (46 loc) · 2.07 KB
/
Robot.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
from Part import Part
from robot_assets import robot_art, colors
class Robot:
def __init__(self, name, color_code):
self.name = name
self.color_code = color_code
self.energy = 100
self.parts = [
Part("Head", attack_level=5, defense_level=10, energy_consumption=5, robot_energy=self.energy),
Part("Weapon", attack_level=15, defense_level=20, energy_consumption=10, robot_energy=self.energy),
Part("Left Arm", attack_level=3, defense_level=20, energy_consumption=10, robot_energy=self.energy),
Part("Right Arm", attack_level=6, defense_level=20, energy_consumption=10, robot_energy=self.energy),
Part("Left Leg", attack_level=4, defense_level=20, energy_consumption=15, robot_energy=self.energy),
Part("Right Leg", attack_level=8, defense_level=20, energy_consumption=15, robot_energy=self.energy),
]
def attack(self, enemy_robot, part_to_use, part_to_attack):
enemy_robot.parts[part_to_attack].reduce_defense(self.parts[part_to_use].attack_level)
self.energy -= self.parts[part_to_use].energy_consumption
def print_status(self):
print(self.color_code)
str_robot = robot_art.format(**self.get_part_status())
self.greet()
self.print_energy()
print(str_robot)
print(colors["White"])
def greet(self):
print("Hello, my name is", self.name)
def print_energy(self):
print("We have", self.energy, " percent energy left")
def get_part_status(self):
part_status = {}
for part in self.parts:
status_dict = part.get_status_dict()
part_status.update(status_dict)
return part_status
def is_there_available_part(self):
for part in self.parts:
if part.is_available():
return True
return False
def check_if_part_is_available(self, part):
if self.parts[part].is_available():
return True
return False
def is_on(self):
return self.energy >= 0