Hi Guys,
I am making a board game, where there is a 3x3 grid and the user enters a row and column and it should put an x in that spot on the grid and ask for the user for another location, until they enter 0 to quit. Here is what I have so far. I've built the grid, now I need to figure out how to modify it. Could someone point me in the right direction? Thanks!
import sys
class Board:
SIZE = 3
grid = []
def __init__(self):
# Create the grid and set by default each location to an empty space.
for rowIndex in range(self.SIZE):
self.grid.append([])
for columnIndex in range(self.SIZE):
aPiece = Piece(Piece.EMPTY_MARK)
self.grid[rowIndex].append(aPiece)
def displayConsole(self):
print()
for rowIndex in range(self.SIZE):
print(' - - - ')
for columnIndex in range(self.SIZE):
sys.stdout.write("|")
self.grid[rowIndex][columnIndex].displayConsole()
print('|')
print(' - - - ')
def markSquare(self, rowIndex, columnIndex) :
self.grid[rowIndex][columnIndex] = Piece(Piece.X_MARK)
class Piece:
EMPTY_MARK = ' '
X_MARK = 'X'
def __init__(self, anAppearance):
self.appearance = anAppearance
def displayConsole(self):
sys.stdout.write(self.appearance)
class Move:
def main():
aBoard = Board()
aBoard.displayConsole()
aMove = Move()
main()