def process(self, player, **kwargs): material = player.field.room_material if not self.has_resources_for_room(material, player): raise CancelledActionException( 'Need 5 wood and 2 reed to build a room. ' + 'You currently have %s wood and %s reed.' % (player.wood, player.reed)) player.field.draw() correct_input = False while not correct_input: try: coordinates_input = raw_input( 'Write the coordinates of the new room: (eg \'31\' or \'3 1\')' ) if coordinates_input.lower() == 'cancel': raise CancelledActionException() x, y = parse_coordinates(coordinates_input) player.field.add_item_to_node(x, y, RoomItem()) correct_input = True except ValueError as e: print e.message self.adjust_player_resources(material, player) print 'Built a %s room' % material player.field.draw()
def place_animal(cls, player, animal_type, count): correct_input = False while not correct_input: try: coordinates_input = raw_input( 'Where would you like to place the %s? (eg \'31\' or \'3 1\')' % animal_type) if coordinates_input.lower() == 'cancel': raise CancelledActionException() x, y = parse_coordinates(coordinates_input) player.field.update_node_animals(x, y, animal_type, count) correct_input = True except ValueError as e: print e.message
def _select_field_node(self, player): node = None valid_node = False while not valid_node: coordinates_input = raw_input( 'Write the coordinates of the field to sow: (eg \'31\' or \'3 1\')' ) if coordinates_input.lower() == 'cancel': raise CancelledActionException() x, y = parse_coordinates(coordinates_input) # make them select a field node try: node = player.field.get_node_by_coordinate(x, y) valid_node = self._is_node_valid(node) except ValueError as e: print e.message return node
def process(self, player, **kwargs): player.field.draw() correct_input = False while not correct_input: try: coordinates_input = raw_input( 'Write the coordinates of the field to plow: (eg \'31\' or \'3 1\')' ) if coordinates_input.lower() == 'cancel': raise CancelledActionException() x, y = parse_coordinates(coordinates_input) player.field.add_item_to_node(x, y, PlowedFieldItem()) correct_input = True except ValueError as e: print e.message print 'Plowed a field.' player.field.draw()
def process(self, player, **kwargs): player.field.draw() correct_input = False num_stables = 0 while not correct_input: num_stables = raw_input('How many stables to build?') if num_stables == 'cancel': raise CancelledActionException() if is_whole_number(num_stables): num_stables = int(num_stables) correct_input = True else: print '%s is not a whole number, please try again.' % num_stables if not self.has_resources_for_stables(num_stables, player): raise CancelledActionException( 'Need %s wood for %s stables; you have %s wood.' % (2 * num_stables, num_stables, player.wood)) stables_built = 0 while stables_built != num_stables: try: coordinates_input = raw_input( 'Write the coordinates of stables %s: (eg \'31\' or \'3 1\')' ) if coordinates_input.lower() == 'cancel': raise CancelledActionException() x, y = parse_coordinates(coordinates_input) player.field.add_item_to_node(x, y, StableItem()) stables_built += 1 except ValueError as e: print e.message self.adjust_player_resources(num_stables, player) print 'Built %s stables.' % num_stables player.field.draw()