- def update_position_y(self, position_y_string):
- """Update self.position[0]."""
- self.position[0] = int(position_y_string)
- self.draw_map()
-
- def update_position_x(self, position_x_string):
- """Update self.position[1]."""
- self.position[1] = int(position_x_string)
+ def update_position(self, position_string):
+ """Update self.position."""
+
+ def get_axis_position_from_argument(axis, token):
+ if len(token) < 3 or token[:2] != axis + ':' or \
+ not token[2:].isdigit():
+ raise ArgumentError('Bad arg for ' + axis + ' position.')
+ return int(token[2:])
+
+ tokens = position_string.split(',')
+ if len(tokens) != 2:
+ raise ArgumentError('wrong number of ","-separated arguments')
+ y = get_axis_position_from_argument('y', tokens[0])
+ x = get_axis_position_from_argument('x', tokens[1])
+ self.position = (y, x)