-
Notifications
You must be signed in to change notification settings - Fork 0
/
LeapingRobot.py
36 lines (30 loc) · 1.15 KB
/
LeapingRobot.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
from robot import Robot
class LeapingRobot(Robot):
def __init__(self, identifier, name, position, direction):
super().__init__(identifier, name, position, direction)
def move_forward(self, grid_size):
print('Leaping forward.')
if self.direction == 'n':
new_row = 0
new_row = max(0, new_row)
self.position = (new_row, self.position[1])
elif self.direction == 's':
new_row = grid_size - 1
new_row = min(grid_size - 1, new_row)
self.position = (new_row, self.position[1])
elif self.direction == 'e':
new_col = grid_size - 1
new_col = min(grid_size - 1, new_col)
self.position = (self.position[0], new_col)
elif self.direction == 'w':
new_col = 0
new_col = max(0, new_col)
self.position = (self.position[0], new_col)
self._report_leap()
def print_greeting(self):
""" Prints my robot's name and id"""
super().print_greeting()
print(f'{self.name} is a leaping robot.')
@staticmethod
def _report_leap():
print('I just jumped!')