def draw(self, my_board: game_board.GameBoard, their_board: game_board.GameBoard): """ Add sprites to the game board's to indicate ship positions, guesses, hits, etc """ for my_ship in self._my_ships: my_ship.draw(my_board) for miss in self._their_misses: my_board.add_sprite(sprites.miss, miss) for hit in self._their_hits: my_board.add_sprite(sprites.hit, hit) # draw hit indicators on their board for miss in self._my_misses: their_board.add_sprite(sprites.miss, miss) for their_ship in self._sunk_ships: their_ship.draw(their_board) for hit in self._my_hits: their_board.add_sprite(sprites.hit, hit)
def draw(self, board: game_board.GameBoard): """ Draw the ship to the board. Use the GameBoard.add_sprite method Make sure the bow and stern are the correct orientation! For example to add a vertical ship's bow to location B4: board.add_sprite(sprites.ship_top,(1,4)) """ # --------- BEGIN YOUR CODE ---------- if self.is_vertical is True: for i in range(self.length): if i == 0: board.add_sprite(sprites.ship_top,(self.row + i, self.col)) elif i == (self.length - 1): board.add_sprite(sprites.ship_bottom, (self.row + i, self.col)) else: board.add_sprite(sprites.ship_vertical, (self.row + i, self.col)) if self.is_vertical is False: for i in range(self.length): if i == 0: board.add_sprite(sprites.ship_left,(self.row, self.col + i)) elif i == (self.length - 1): board.add_sprite(sprites.ship_right, (self.row, self.col + i)) else: board.add_sprite(sprites.ship_horizontal, (self.row, self.col + i))