So I am making a game of Battleship and currently have a grid that is defined in the class init function. The size of the grid is square and gets its size from an argument as such:
class Board:
def __init__(self, size):
self.size = size
self._grid = [['.']*self.size]*self.size
So with self._grid, I plan to print out this 2D list. The problem I am having is replacing a '.' with a letter to represent a ship. So:
def add_ship(self):
self._grid[1][5] = 'B' #this is to determine a Battleship with length of one for now.
def print(self):
# prints out content within game board.
for i in range(self.size):
for j in range(self.size):
print(self._grid[i][j] +' ', end='')
With add_ship, I plan to change elements within the gird. With print, I want to print out the grid. The main problem is that it is not changing element [1][5], but instead changes the entire column. Any tips on another way to do this? Thanks!