As I said in a comment, I think you should make the two functions in methods of class BoardHandler
. This will give you better encapsulation and it's fairly easy to do, here's how:
class BoardHandler:
def __init__ (self, size, board):
self.size = size
self.board = board
def ask_size(self):
try:
self.size = int(input("Which size would you want?"))
except ValueError:
print("Wrong! try again")
ask_size()
def getNewBoard(self):
board=[]
for i in range(self.size):
board.append([' ']* self.size)
self.board = board
def resetBoard(self):
for x in range(self.size):
for y in range(self.size):
self.board[x][y] = ' '
n=int(size/2-1)
self.board[n][n] = 'B'
self.board[n+1][n] = 'W'
self.board[n][n+1] = 'W'
self.board[n+1][n+1] = 'B'
def drawBoard(self):
HLINE = ' ----------------------------------------'
for y in range(self.size):
print(y+1, end=' ')
for x in range(Q):
print('| %s' % (self.board[x][y]), end=' ')
print('|')
print(HLINE)
If you want to keep them outside the class for some reason, you will need to modify each of them to accept a BoardHandler
class instance as an argument:
def resetBoard(board_handler):
for x in range(board_handler.size):
for y in range(board_handler.size):
board_handler.board[x][y] = ' '
n=int(board_handler.size/2-1)
board[n][n] = 'B'
board[n+1][n] = 'W'
board[n][n+1] = 'W'
board[n+1][n+1] = 'B'
def drawBoard(board_handler):
HLINE = ' ----------------------------------------'
for y in range(board_handler.size):
print(y+1, end=' ')
for x in range(Q):
print('| %s' % (board_handler.board[x][y]), end=' ')
print('|')
print(HLINE)
This assumes your program creates a single BoardHandler
class instance, and does all operations to that object.