import pygame, copy, random, sys
from pygame.locals import * # 键盘获取
SMALLBOXSIZE = 60 # 小盒子尺寸
MEDIUMBOXSIZE = 20 # 中等大小的盒子
LARGEBOXSIZE = 11 # 大盒子尺寸
SMALLBOARDSIZE = 6 # 小模板的尺寸
MEDIUMBOARDSIZE = 17 # 中模板的尺寸
LARGEBOARDSIZE = 30 # 大模板的尺寸
SMALLMAXLIFE = 10 # 小的生命条
MEDIUMMAXLIFE = 30 # 中的生命条
LARGEMAXLIFE = 64 # 大的生命条
FPS = 30
WINDOWWIDTH = 640 # 窗口的宽度
WINDOWHEIGHT = 480 # 窗口的高度
boxSize = MEDIUMBOXSIZE # 盒子的大小
PALETTEGAPSIZE = 15 # 调色板间隙的大小
PALETTESIZE = 45 # 调色板的大小
# 这里的参数只要不是相等的都是可以随便设的
EASY = 0 # 容易
MEDIUM = 1 # 普通
HARD = 2 # 困难
difficulty = MEDIUM # 游戏以普通的难度开始
maxLife = MEDIUMMAXLIFE
boardWidth = MEDIUMBOARDSIZE # 盒子是正方形所以选普通大小
boardHeight = MEDIUMBOARDSIZE
# 色彩搭配
# R G B
WHITE = (255, 255, 255)
DARKGRAY = ( 70, 70, 70)
BLACK = ( 0, 0, 0)
RED = (255, 0, 0)
GREEN = ( 0, 255, 0)
BLUE = ( 0, 0, 255)
YELLOW = (255, 255, 0)
ORANGE = (255, 128, 0)
PURPLE = (255, 0, 255)
# 每个方案中的第一种颜色是背景色,接下来的六种是调色板颜色。
# 配色方案
COLORSCHEMES = (((150, 200, 255), RED, GREEN, BLUE, YELLOW, ORANGE, PURPLE),
((0, 155, 104), (97, 215, 164), (228, 0, 69), (0, 125, 50), (204, 246, 0), (148, 0, 45), (241, 109, 149)),
((195, 179, 0), (255, 239, 115), (255, 226, 0), (147, 3, 167), (24, 38, 176), (166, 147, 0), (197, 97, 211)),
((85, 0, 0), (155, 39, 102), (0, 201, 13), (255, 118, 0), (206, 0, 113), (0, 130, 9), (255, 180, 115)),
((191, 159, 64), (183, 182, 208), (4, 31, 183), (167, 184, 45), (122, 128, 212), (37, 204, 7), (88, 155, 213)),
((200, 33, 205), (116, 252, 185), (68, 56, 56), (52, 238, 83), (23, 149, 195), (222, 157, 227), (212, 86, 185)))
for i in range(len(COLORSCHEMES)):
assert len(COLORSCHEMES[i]) == 7, 'Color scheme %s does not have exactly 7 colors.' % (i)
bgColor = COLORSCHEMES[0][0]
paletteColors = COLORSCHEMES[0][1:] # 调色板的颜色 取值从下标值为一的开始切片
def main():
global FPSCLOCK, display_surf, logo_image, spot_image, settings_image, settings_button_image, reset_button_image
# 初始化
pygame.init()
FPSCLOCK = pygame.time.Clock()
display_surf = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT)) # 窗口的大小默认必须传元组
# load images
logo_image = pygame.image.load("inkspilllogo.png")
spot_image = pygame.image.load("inkspillspot.png")
settings_image = pygame.image.load("inkspillsettings_A.png")
settings_button_image = pygame.image.load('inkspillsettingsbutton.png')
reset_button_image = pygame.image.load('inkspillresetbutton.png')
pygame.display.set_caption('Ink Spill')
# pygame.display.set_caption('颜色溢出')
mousex = 0
mousey = 0
main_board = generateRandomVoard(boardWidth, boardHeight, difficulty)
life = maxLife # 把最大生命值赋值给当前生命
last_palette_clicked = None
while True:
paletteClicked = None # 调色板点击
resetGame = False # 重置游戏
# 绘制屏幕 把设定好的颜色初始值传入进来
d