Guest User

Untitled

a guest
Dec 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. [['_', '_', '_', '_', '_', '_'], ['_', '_', '_', '_', '_', '_'], ['_', '_', '_', '_', '_', '_'], ['_', '_', '_', '_', '_', '_'], ['_', '_', '_', '_', '_', '_'], ['_', '_', '_', '_', '_', '_']]
  2.  
  3. [['_', '_', '_', 'R', '_', '_'], ['_', '_', '_', 'R', '_', '_'], ['_', '_', '_', '_', '_', '_'], ['_', '_', '_', '_', '_', '_'], ['_', '_', '_', '_', '_', '_'], ['_', '_', '_', '_', '_', '_']]
  4.  
  5. Class Board():
  6.  
  7. def __init__(self, cars, exit_board=(5,3), size=6):
  8.  
  9. """
  10. Initialize a new Board object.
  11. :param cars: A list (@or dictionary) of cars. @can be empty
  12. :param size: Size of board (Default size is 6).
  13. """
  14.  
  15. self.cars= cars
  16. self.exit_board=exit_board
  17. self.size=size
  18. self.board = [['_']*size]*size
  19.  
  20. def add_car(self, car):
  21.  
  22. """
  23. Add a single car to the board.
  24. :param car: A car object
  25. :return: True if a car was succesfuly added, or False otherwise.
  26. """
  27.  
  28. added=False
  29. #for car in self.cars:
  30. x,y=car.get_location()[0], car.get_location()[1]
  31. if car.get_orientation() == Direction.HORIZONTAL:
  32. for i in range(car.get_length()):
  33. self.board[y][x+i] = car.get_color()
  34. added=True
  35. else:
  36. for i in range(car.get_length()):
  37. self.board[y+i][x] = car.get_color()
  38. added=True
  39.  
  40. return added
  41.  
  42. red_car = Car('R',2,(0,3),0)
  43. self.board.add_car(red_car)
Add Comment
Please, Sign In to add comment