- 新增 jiyi.py 文件,实现字母翻牌记忆游戏功能 - 添加 youxijiemian.py 文件,创建游戏开始界面 - 使用 turtle 和 tkinter 模块分别实现游戏和界面 - 支持选择不同难度的游戏模式
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
import pgzrun
|
||
import random
|
||
|
||
# 设置窗口
|
||
WIDTH = 1000 # 窗口的宽度
|
||
HEIGHT = 725 # 窗口的高度
|
||
|
||
def draw():
|
||
screen.blit('火眼金睛.png', (0, 0))
|
||
for grid in grids:
|
||
screen.draw.filled_rect(Rect(grid['pos'], (side, side)), 'white')
|
||
|
||
def update():
|
||
pass
|
||
|
||
def base_color():
|
||
"""生成随机基础颜色"""
|
||
return (random.randint(0, 255),
|
||
random.randint(0, 255),
|
||
random.randint(0, 255))
|
||
|
||
def dif_color(base):
|
||
"""
|
||
参数:
|
||
base:表示基础颜色的元组,格式为(r,g,b)
|
||
"""
|
||
r = min(base[0] + random.randint(20, 30), 255)
|
||
g = min(base[1] + random.randint(20, 30), 255)
|
||
b = min(base[2] + random.randint(20, 30), 255)
|
||
return (r, g, b)
|
||
|
||
# 初始为3×3的矩阵
|
||
n = 3
|
||
# 根据格子数量计算格子边长和间距
|
||
side = 700 // n * 0.9
|
||
space = 700 // n * 0.1
|
||
# 创建列表grids,后面存储每个方格信息
|
||
grids = []
|
||
for row in range(n): # 遍历行
|
||
for col in range(n): # 遍历列
|
||
info = {
|
||
'pos': (space + col * (side + space), space + row * (side + space)),
|
||
'color': 'white' # 测试用,后续及时更新对应颜色
|
||
}
|
||
grids.append(info)
|
||
|
||
# 启动游戏
|
||
pgzrun.go() |