def __single_turn(self): """ Note - this function is here to guide you and it is *not mandatory* to implement it. The logic defined by this function must be implemented but if you wish to do so in another function (or some other functions) it is ok. The function runs one round of the game : 1. gh.report board to the screen 2. Get user's input of: what color car to move, and what direction to move it. 2.a. Check the the input is valid. If not, gh.report an error message and return to step 2. 2. Move car according to user's input. If movement failed (trying to move out of board etc.), return to step 2. 3. Report to the user the result of current round () """ # Asking to choose a car and a direction until the user enter valid # data while True: color = input(MSG_CHOOSE_CAR) for car in self.__board.cars: if car.color == color: direction = gh.get_direction() while not self.__check_direction(car, direction) or \ direction not in Direction.ALL_DIRECTIONS: direction = gh.get_direction() return self.__board.move(car, direction) else: # If we still return nothing, that's mean that the car # doesn't exist, so print a message and asking again gh.report(MSG_NOT_A_CAR)
def single_turn(self): """ The function runs one round of the game : 1. Print board to the screen 2. Get user's input of: what color car to move, and what direction to move it. 3. Move car according to user's input. If movement failed the respective message will be printed, return False. 4. Report to the user result of current round by printing the board """ color_input = self.get_color_input() direction_input = gh.get_direction() move_validity = board.move(board.get_cars_dict()[color_input], direction_input) if not move_validity: return False else: print(board) return True
def __single_turn(self): """ Note - this function is here to guide you and it is *not mandatory* to implement it. The logic defined by this function must be implemented but if you wish to do so in another function (or some other functions) it is ok. The function runs one round of the game : 1. Print board to the screen 2. Get user's input of: what color car to move, and what direction to move it. 2.a. Check the the input is valid. If not, print an error message and return to step 2. 2. Move car according to user's input. If movement failed (trying to move out of board etc.), return to step 2. 3. Report to the user the result of current round () """ # implement your code here print(self.board) color_legal = False """keep runing the turn until the user put a valid color, and then move the car to the desired location, if succeed to move the car return true, else return false""" while not color_legal: print("what color is the car that you want to move?") car_color_want_to_move = input() for car in self.board.cars: if car.color == car_color_want_to_move: the_car_we_want_to_move = car color_legal = True if color_legal is False: print(ERROR_MSG_NO_COLOR_ON_BOARD) directionn = gh.get_direction() if board.move(the_car_we_want_to_move, directionn): return True else: # print("There was a problem") return False
def __single_turn(self): """ Note - this function is here to guide you and it is *not mandatory* to implement it. The logic defined by this function must be implemented but if you wish to do so in another function (or some other functions) it is ok. The function runs one round of the game : 1. Print board to the screen 2. Get user's input of: what color car to move, and what direction to move it. 2.a. Check the the input is valid. If not, print an error message and return to step 2. 2. Move car according to user's input. If movement failed (trying to move out of board etc.), return to step 2. 3. Report to the user the result of current round () """ print(self.board) color = input("What color car would you like to move?") while not self.board.move(color, gh.get_direction()): print("Illegal move, try again") color = input("What color car would you like to move?")
def single_turn(self): """ Note - this function is here to guide you and it is *not mandatory* to implement it. The logic defined by this function must be implemented but if you wish to do so in another function (or some other functions) it is ok. The function runs one round of the game : 1. Print board to the screen 2. Get user's input of: what color car to move, and what direction to move it. 2.a. Check the the input is valid. If not, print an error message and return to step 2. 2. Move car according to user's input. If movement failed (trying to move out of board etc.), return to step 2. 3. Report to the user the result of current round () """ print(self.__board) car_color_to_move = self.get_color_input() car = self.__board.get_car_by_color(car_color_to_move) while car == False: # while the given color has no corresponding car on the board print(Game.MESSAGE_CAR_NOT_ON_BOARD.format(car_color_to_move)) car_color_to_move = self.get_color_input() car = self.__board.get_car_by_color(car_color_to_move) direction_to_move = gh.get_direction() was_able_to_move = self.__board.move(car, direction_to_move) if not was_able_to_move: print(Game.MESSAGE_CANT_MOVE_CAR) return was_able_to_move