SIZE = 40
WIDTH = SIZE*15
HEIGHT = SIZE*15
board = [[" "for i in range(15)]for j in range(15)]
chesses = []
turn = "b"
lastturn="w"
def draw():
screen.fill((210,180,140))
for i in range(15):
screen.draw.line((20,SIZE*i+20),(580,SIZE*i+20),(0,0,0))
screen.draw.line((SIZE*i+20,20),(SIZE*i+20,580),(0,0,0))
for chess in chesses:
chess.draw()
if len(chesses)>0:
screen.draw.rect(Rect(chesses[-1].topleft,(36,36)),(255,255,255))
if check():
if lastturn == "b" :
screen.draw.text("Black Win!",center=(WIDTH//2,HEIGHT//2),fontsize=100,color="red")
if lastturn == "w":
screen.draw.text("White Win!",center=(WIDTH//2,HEIGHT//2),fontsize=100,color="red")
def on_mouse_down(pos,button):
global turn,lastturn
if button == mouse.LEFT:
col =pos[0]//SIZE
row =pos[1]//SIZE
if board[col][row] != " ":
return
if turn =="b":
chess = Actor("goblack",(col*SIZE+20,row*SIZE+20))
if turn =="w":
chess = Actor("gowhite",(col*SIZE+20,row*SIZE+20))
chesses.append(chess)
board[col][row] = turn
lastturn=turn
if turn =="b":
turn ="w"
else:
turn="b"
elif button == mouse.RIGHT :
if len(chesses)<2:
return
for i in range(2):
chess = chesses.pop()
col=int(chess.x-20)//SIZE
row=int(chess.y-20)//SIZE
board[col][row]=" "
def check():
a=lastturn
for i in range(11):
for j in range(11):
if board[i][j] == a and board[i+1][j+1] == a and board[i+2][j+2] == a and board[i+3][j+3] == a and board[i+4][j+4] == a :
return True
for i in range(11):
for j in range(4,15):
if board[i][j] == a and board[i+1][j-1] == a and board[i+2][j-2] == a and board[i+3][j-3] == a and board[i+4][j-4] == a :
return True
for i in range(15):
for j in range(11):
if board[i][j] == a and board[i][j+1] == a and board[i][j+2] == a and board[i][j+3] == a and board[i][j+4] == a :
return True
for i in range(11):
for j in range(15):
if board[i][j] == a and board[i+1][j] == a and board[i+2][j] == a and board[i+3][j] == a and board[i+4][j] == a :
return True
def update():
if check():
sounds.win.play()