sairate 2cd753d3d9 feat(第7讲 字母卡牌): 实现记忆游戏并添加开始界面
- 新增 jiyi.py 文件,实现字母翻牌记忆游戏功能
- 添加 youxijiemian.py 文件,创建游戏开始界面
- 使用 turtle 和 tkinter 模块分别实现游戏和界面
- 支持选择不同难度的游戏模式
2025-06-29 09:06:19 +08:00

48 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()