youbbs
youbbs
937 0 0

用 Python + PyGame 编写国际象棋游戏

这是用 PyGame 国际象棋的一个版本,棋子不受 8x8 网格的限制,而是可以移动到棋盘上的任何位置。 点击一块后,它可以移动到的区域以绿色突出显示,而敌人可以移动到的区域以红色突出显示。 拖动棋子来移动它,要确认移动,请再次单击棋子或按回车键。 要取消移动,请按退出键或单击棋子的任意位置。

用 Python + PyGame 编写国际象棋

import pygame
import math
from pygame import gfxdraw


def draw_circle(surface, x, y, radius, color):
    gfxdraw.aacircle(surface, x, y, radius, color)
    gfxdraw.filled_circle(surface, x, y, radius, color)

def draw_circle_outline(surface, x, y, radius, color):
    gfxdraw.aacircle(surface, x, y, radius, color)
    gfxdraw.circle(surface, x, y, radius, (255-color[0],255-color[1],255-color[2]))

def getpolygon(origin, radius, N, start=0, end=None):
    out = []
    x, y = origin
    Nf = float(N)
    if end is None:
        end = TAU
    for i in range(N):
        xp = x + radius * math.sin(end * i / Nf + start)
        yp = y - radius * math.cos(end * i / Nf + start)
        out.append((xp, yp))
    return 

一个 1235 行的文件完成一个简单的游戏!

PyGame 国际象棋游戏

https://github.com/ehulinsky/AnalogChess

0

See Also

Nearby


Discussion

Login Topics