diff --git a/src/gui/boardview.py b/src/gui/boardview.py new file mode 100644 --- /dev/null +++ b/src/gui/boardview.py @@ -0,0 +1,49 @@ +import tkinter as tk + +import go + + +## Handles and presents the game state as detected by the program. +class BoardView(tk.Canvas): + def __init__(self, master=None): + tk.Canvas.__init__(self, master) + self.configure(width=360,height=360,background="#ffcc00") + + self.drawGrid() + + self.grid() + + def redrawState(self,gameState): + # !! will need to remove old stones or redraw the widget completely + for r,row in enumerate(gameState): + for c,point in enumerate(row): + self.drawStone(r,c,point) + + self.grid() + + def drawGrid(self): + for i in range(19): + self.create_line(18,18*(i+1),360-18,18*(i+1),fill="#000000") # rows + self.create_line(18*(i+1),18,18*(i+1),360-18,fill="#000000") # cols + + self.drawStars() + + def drawStars(self): + for r in range(4,19,6): + for c in range(4,19,6): + self.create_oval(r*18-2,c*18-2,r*18+2,c*18+2,fill='#000000') + + ## Draws a stone at provided coordinates. + # + # For an unknown color draws nothing and returns False. + # + # @param r row coordinate, [0-18], counted from top + # @param c column coordinate, [0-18], counted from left + # @param color color indicator, go.BLACK or go.WHITE + def drawStone(self,r,c,color): + if color==go.BLACK: hexCode='#000000' + elif color==go.WHITE: hexCode='#ffffff' + else: return False + r+=1 + c+=1 + self.create_oval(c*18-9,r*18-9,c*18+9,r*18+9,fill=hexCode)