Files
@ f85a79f2fd95
Branch filter:
Location: OneEye/src/gui/boardview.py - annotation
f85a79f2fd95
1.8 KiB
text/x-python
added JSON config file
9fa3f70d50ba d138366bd4bb 4b4cae6939e8 4b4cae6939e8 4b4cae6939e8 9fa3f70d50ba 4b4cae6939e8 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba d138366bd4bb 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 4b4cae6939e8 9fa3f70d50ba 4b4cae6939e8 4b4cae6939e8 d138366bd4bb 4b4cae6939e8 4b4cae6939e8 9fa3f70d50ba 4b4cae6939e8 9fa3f70d50ba 9fa3f70d50ba 4b4cae6939e8 9fa3f70d50ba 9fa3f70d50ba 4b4cae6939e8 9fa3f70d50ba 4b4cae6939e8 9fa3f70d50ba d138366bd4bb d138366bd4bb d138366bd4bb d138366bd4bb 9fa3f70d50ba 9fa3f70d50ba d138366bd4bb 4b4cae6939e8 4b4cae6939e8 4b4cae6939e8 4b4cae6939e8 4b4cae6939e8 4b4cae6939e8 4b4cae6939e8 4b4cae6939e8 9fa3f70d50ba d138366bd4bb d138366bd4bb d138366bd4bb d138366bd4bb d138366bd4bb d138366bd4bb 4b4cae6939e8 d138366bd4bb 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba d138366bd4bb | from .resizablecanvas import ResizableCanvas
from go import BLACK,WHITE
## Handles and presents the game state as detected by the program.
class BoardView(ResizableCanvas):
def __init__(self, master=None):
super().__init__(master)
self.configure(width=360,height=360,background="#ffcc00")
self._padding=18
self._cellWidth=(self._width-2*self._padding)/18
self._cellHeight=(self._height-2*self._padding)/18
self._drawGrid()
def redrawState(self,gameState):
self.delete("black","white")
for r,row in enumerate(gameState):
for c,point in enumerate(row):
self._drawStone(r, c, point)
def _drawGrid(self):
padding=self._padding
for i in range(19):
self.create_line(padding,18*i+padding,self._width-padding,18*i+padding,tags="row",fill="#000000") # rows
self.create_line(18*i+padding,padding,18*i+padding,self._height-padding,tags="col",fill="#000000") # cols
self._drawStars()
def _drawStars(self):
radius=2
for r in range(3,19,6):
for c in range(3,19,6):
x=c*self._cellHeight+self._padding
y=r*self._cellWidth+self._padding
self.create_oval(x-radius,y-radius,x+radius,y+radius,tags="star",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==BLACK:
hexCode='#000000'
tag="black"
elif color==WHITE:
hexCode='#ffffff'
tag="white"
else: return False
x=c*self._cellWidth+self._padding
y=r*self._cellHeight+self._padding
radius=self._cellWidth/2
self.create_oval(x-radius,y-radius,x+radius,y+radius,tags=tag,fill=hexCode)
|