看看呐,点一点也好啊🤣
#!python3
# -*- coding: utf-8 -*-
import pygame
import game
ROWS = 17
SIDE = 30
SCREEN_WIDTH = ROWS * SIDE
SCREEN_HEIGHT = ROWS * SIDE
EMPTY = -1
BLACK = (0,0,0)
WHITE = (255, 255, 255)
DIRE = [(1, 0), (0, 1), (1, 1), (1, -1)]
class Gobang(game.Game):
def __init__(self, title, size, fps=15):
super(Gobang, self).__init__(title, size, fps)
self.board = [[EMPTY for i in range(ROWS)] for j in range(ROWS)]
self.select = (-1, -1)
self.black = True
self.draw_board()
self.bind_click(1, self.click)
def click(self, x, y):
if self.end:
return
i, j = y // SIDE, x // SIDE
if self.board[i][j] != EMPTY:
return
self.board[i][j] = BLACK if self.black else WHITE
self.draw_chess(self.board[i][j], i, j)
self.black = not self.black
chess = self.check_win()
if chess:
self.end = True
i, j = chess[0]
winer = "Black"
if self.board[i][j] == WHITE:
winer = "White"
pygame.display.set_caption("五子棋 ---- %s win!" % (winer))
for c in chess:
i, j = c
self.draw_chess((100, 255, 255), i, j)
self.timer.tick(5)
def check_win(self):
for i in range(ROWS):
for j in range(ROWS):