续上一篇pygame实现俄罗斯方块_pygame 俄罗斯方块_忆林之海的博客-CSDN博客的简单版俄罗斯方块,这次有了大量的改进。粘贴下载配置文件即可运行,将代码与material文件放在同一文件夹下。你可以直接下载安装包体验哦。安装包放在结尾了。
在本次加入了一些美化文件之后,使我们的小游戏更加具有可玩性。操作更流畅,可以根据自己的操作习惯修改操作设置,支持全屏操作,有简单的皮肤选择功能,当然你也可以自己做一些皮肤,修改一下文件中的图片就行,注意图片大小。
尝试想写一个简单的机器对战,最后能力不足还是没成功,只简单完成了40行挑战,120秒积分挑战。
import os, csv
import pygame, sys, random, time
import multiprocessing
from threading import Thread
pygame.init()
pygame.mixer.init()
pygame.display.set_caption('俄罗斯方块1.0')
# 窗口数据
rob = None
Width = 500
Height = 700
width = Width
height = Height
start_time=0
end_time = time.time()
c_l = [width,height ]
screen1 = pygame.display.set_mode((width, height), flags=pygame.HWSURFACE | pygame.FULLSCREEN) # 屏幕大小
c_s = pygame.display.Info() # 获取屏幕尺寸
c_set = [1, 1, 1, 1] # 音效、投影、全屏控制
screen1 = pygame.display.set_mode((width, height), flags=pygame.HWSURFACE)
multipl = 1 # 图形放大比例
c_dif = [0, 0] # 图形在窗口中的位置
word_size = [int(35 * multipl // 1), int(200 * multipl // 1)] # 字体尺寸
size = round(30 * multipl) # 方块规格
sore = 10 # 分数单位
sores = [0, 0, 0, 0, 0] # 记录总分,T旋数,行数/时间
leve = 1 # 速度控制
lock = 0.3 # 控制
sensitivity = 0.1 # 按键灵敏度
c_isd = [1]
d_isin = {
"back": [(0, 0), (80, 50)],
'options': [(125, 150), (375, 190)],
'pause': [(450, 0), (500, 30)]
} # 点击位置字典
'''主题字典'''
d_skin = {"暗黑主题": "material/dark/", "蛋蛋畅享版": "material/dan/"}
# 颜色顺序:排行榜(名称,分数),运行得分,操作界面(2),结束得分,皮肤选择界面(可选字样,,当前,可选)
d_colors = {
"暗黑主题": [(0, 0, 0), (255, 255, 255), (0, 0, 0), (0, 0, 157), (243, 151, 0), (0, 0, 0), (0, 0, 0), (243, 151, 0),
(243, 151, 51)],
"蛋蛋畅享版": [(249, 63, 112), (255, 255, 255), (255, 255, 255), (249, 63, 112), (243, 151, 0), (255, 255, 255),
(34, 171, 56), (243, 151, 0), (34, 171, 56)],}
word_color = d_colors["暗黑主题"]
path = d_skin["暗黑主题"]
# 操作设置
left = pygame.K_LEFT
right = pygame.K_RIGHT
down = pygame.K_DOWN
spi_r = pygame.K_UP
spi_l = pygame.K_a
change = pygame.K_s
plunge = pygame.K_d
pau = pygame.K_SPACE
keys = [left, right, down, spi_l, spi_r, change, plunge]
# 方块移动控制
c_left = 0
c_right = 0
c_down = 0
# 初始方块产生随机函数
# 2,4,6,7,19,14,16
c_list = (2, 4, 6, 7, 7, 19, 14, 16, 2, 6, 4, 7, 7, 14, 14, 14, 16, 16, 16)
ch1 = [c_list[random.randint(0, len(c_list) - 1)] for i in range(4)]
while ch1[3] == ch1[2] and ch1[3] == ch1[1]:
ch1[3] = c_list[random.randint(0, len(c_list) - 1)]
ch1.append(0)
ch1.append(0)
filled = [] # 落地方块储存
n = [0] # 控制是否能当前手中方块0可控制
control = [1] # 控制游戏结束
start = [0, 0, 0, 0, 0] # 控制游戏开始
c_op = 0
pause = 0
set1 = [0, 0] # 用于储存上一个set, 方便T旋的计算
origin = [round(10 * multipl), round(10 * multipl)] # 原点位置
set = [4 * size + origin[0], origin[1] - 2 * size] # 初始生成方块位置
# 音乐引入
music1 = pygame.mixer.Sound(path + 'musics\\theme.mp3') # 背景音
m_allclear = pygame.mixer.Sound(path + 'musics\\allclear.mp3')
m_one = pygame.mixer.Sound(path + 'musics\\clear.mp3') # 单消
m_t = pygame.mixer.Sound(path + 'musics\\clear_t.mp3') # T旋
m_tention = pygame.mixer.Sound(path + 'musics\\tention.mp3') # 紧张
m_four = pygame.mixer.Sound(path + '\musics\\clear_four.mp3') # 四消
m_downed = pygame.mixer.Sound(path + 'musics\\downed.mp3') # 落地
m_lock = pygame.mixer.Sound(path + 'musics\\lock.mp3') # 不能旋转
im_square = pygame.image.load(path + "phto\\square.png")
im_square = pygame.transform.rotozoom(im_square, 0, multipl)
im = pygame.image.load(path + "phto\\main_ground.png")
im = pygame.transform.rotozoom(im, 0, multipl)
screen = pygame.image.load(path + "phto\\main_ground.png")
screen = pygame.transform.rotozoom(screen, 0, multipl)
im_start = pygame.image.load(path + "phto\\start_ground.png")
im_start = pygame.transform.rotozoom(im_start, 0, multipl)
im_start2 = pygame.image.load(path + "phto\\game_s_w.png")
im_start2 = pygame.transform.rotozoom(im_start2, 0, multipl)
im_start3 = pygame.image.load(path + "phto\\game_s_y.png")
im_start3 = pygame.transform.rotozoom(im_start3, 0, multipl)
im_quit = pygame.image.load(path + "phto\\quit.png")
im_quit = pygame.transform.rotozoom(im_quit, 0, multipl)
im_continue = pygame.image.load(path + "phto\\continue.png")
im_continue = pygame.transform.rotozoom(im_continue, 0, multipl)
im_pause = pygame.image.load(path + "phto\\pause.png")
im_pause = pygame.transform.rotozoom(im_pause, 0, multipl)
im_set = pygame.image.load(path + "phto\\ground.png")
im_set = pygame.transform.rotozoom(im_set, 0, multipl)
f = pygame.font.Font(path + "font/set.ttf", word_size[0])
f1 = pygame.font.Font(path + "font/set.ttf", word_size[1])
face = pygame.Surface((size, size), flags=pygame.HWSURFACE) # 基础方块的绘制
face.blit(im_square, (0, 0))
face1 = pygame.Surface((size, size), flags=pygame.HWSURFACE) # 基础方块的投影绘制
face1.blit(im_square, (0, 0))
face1.set_alpha(80)
clock = pygame.time.Clock()
game40 = None
"""机器人数据"""
c_right_roboot = 0
c_left_roboot = 0
c_down_roboot = 0
ch1_roboot = [c_list[random.randint(0, len(c_list) - 1)] for i in range(4)]
while ch1_roboot[3] == ch1_roboot[2] and ch1_roboot[3] == ch1_roboot[1]:
ch1_roboot[3] = c_list[random.randint(0, len(c_list) - 1)]
ch1_roboot.append(0)
ch1_roboot.append(0)
multipl_roboot = 0.3
sores_roboot = [0, 0, 0, 0, 0]
size_roboot = int(30 * multipl_roboot)
origin_roboot = [int(origin[0] * multipl_roboot), int(origin[1] * multipl_roboot)]
set_roboot = [size_roboot * 4+origin_roboot[0], size_roboot * (-2)+origin_roboot[1]]
set_roboot1 = [0, 0]
filled_roboot = []
# manger = multiprocessing.Manager()
# sharefilled1 = manger.list()
# sharefilled2 = manger.list()
im_square_roboot = pygame.image.load(path + "phto\\square.png")
im_square_roboot = pygame.transform.rotozoom(im_square_roboot, 0, multipl_roboot)
im_roboot = pygame.image.load(path + "phto\\main_ground.png")
im_roboot = pygame.transform.rotozoom(im_roboot, 0, multipl_roboot)
screen_roboot = pygame.image.load(path + "phto\\main_ground.png")
screen_roboot = pygame.transform.rotozoom(screen_roboot, 0, multipl_roboot)
face_roboot = pygame.Surface((size_roboot, size_roboot), flags=pygame.HWSURFACE) # 基础方块的绘制
face_roboot.blit(im_square, (0, 0))
face1_roboot = pygame.Surface((size_roboot, size_roboot), flags=pygame.HWSURFACE) # 基础方块的投影绘制
face1_roboot.blit(im_square_roboot, (0, 0))
face1_roboot.set_alpha(80)
f_roboot = pygame.font.Font(path + "font/set.ttf", word_size[0])
f1_roboot = pygame.font.Font(path + "font/set.ttf", word_size[1])
control_roboot = [1]
# 皮肤选择
def c_skin():
global path, im
c = 1
while c == 1:
im_skin = pygame.image.load(path + "phto/ground.png")
im_skin = pygame.transform.rotozoom(im_skin, 0, multipl)
d = 0
lis_k = [i for i in d_skin.keys()]
lis_v = [i for i in d_skin.values()]
for i in range(len(lis_v)):
if lis_v[i] == path:
f_np = f.render("当前主题:" + lis_k[i], True, word_color[7])
f_ap = f.render("可选主题:", True, word_color[6])
for i in range(4):
d_color(18, face)
im.blit(face, forms(18, (4 * size + origin[0], 5 * size + origin[1]))[i])
im_skin.blit(pygame.transform.rotozoom(im, 0, 0.2), (30 * multipl, (180 - 50) * multipl))
im_skin.blit(f_np, (130 * multipl, (180 - 50) * multipl))
im_skin.blit(f_ap, (130 * multipl, (180 + 50) * multipl))
im = pygame.transform.rotozoom(pygame.image.load(path + "phto/main_ground.png"), 0, multipl)
for i in d_skin.keys():
d += 1
fs = f.render(i, True, word_color[8])
im_skin.blit(fs, (130 * multipl, (230 + d * 50) * multipl))
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
c = 0
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((0, 0), (4 * 30, 3 * 30)):
c = 0
for i in range(len(lis_k)):
if isin((130, 230 + (i + 1) * 50), (130 + 6 * 50, 230 + (i + 2) * 50)):
# if inp(im_skin,(120,230-50-10)):
try:
skin(i)
except:
print("找不到主题对应的资源")
screen1.blit(im_skin, c_dif)
pygame.display.flip()
def skin(c):
global path, word_color, aph
global music1, m_allclear, f, f1, m_one, m_t, m_tention, m_four, m_downed, m_lock, screen1, screen, face, im_square, im_set, im_quit, im_pause, im_start, im_start3, im_continue, im_start2, im, face1, screenset, origin
lis_k = [i for i in d_skin.keys()]
aph = 80
for i in range(len(lis_k)):
if c == i:
if c == 1:
aph = 150
path = d_skin[lis_k[i]]
word_color = d_colors[lis_k[i]]
# screen_c()
music1.stop()
music1 = pygame.mixer.Sound(path + 'musics\\theme.mp3') # 背景音
if c_set[1] == 1:
music1.play(-1)
m_allclear = pygame.mixer.Sound(path + 'musics\\allclear.mp3')
m_one = pygame.mixer.Sound(path + 'musics\\clear.mp3') # 单消
m_t = pygame.mixer.Sound(path + 'musics\\clear_t.mp3') # T旋
m_tention = pygame.mixer.Sound(path + 'musics\\tention.mp3') # 紧张
m_four = pygame.mixer.Sound(path + '\musics\\clear_four.mp3') # 四消
m_downed = pygame.mixer.Sound(path + 'musics\\downed.mp3') # 落地
m_lock = pygame.mixer.Sound(path + 'musics\\lock.mp3') # 不能旋转
im_square = pygame.image.load(path + "phto\\square.png")
im_square = pygame.transform.rotozoom(im_square, 0, multipl)
im = pygame.image.load(path + "phto\\main_ground.png")
im = pygame.transform.rotozoom(im, 0, multipl)
screen = pygame.image.load(path + "phto\\main_ground.png")
screen = pygame.transform.rotozoom(screen, 0, multipl)
im_start = pygame.image.load(path + "phto\\start_ground.png")
im_start = pygame.transform.rotozoom(im_start, 0, multipl)
im_start2 = pygame.image.load(path + "phto\\game_s_w.png")
im_start2 = pygame.transform.rotozoom(im_start2, 0, multipl)
im_start3 = pygame.image.load(path + "phto\\game_s_y.png")
im_start3 = pygame.transform.rotozoom(im_start3, 0, multipl)
im_quit = pygame.image.load(path + "phto\\quit.png")
im_quit = pygame.transform.rotozoom(im_quit, 0, multipl)
im_continue = pygame.image.load(path + "phto\\continue.png")
im_continue = pygame.transform.rotozoom(im_continue, 0, multipl)
im_pause = pygame.image.load(path + "phto\\pause.png")
im_pause = pygame.transform.rotozoom(im_pause, 0, multipl)
im_set = pygame.image.load(path + "phto\\ground.png")
im_set = pygame.transform.rotozoom(im_set, 0, multipl)
face = pygame.Surface((size, size), flags=pygame.HWSURFACE) # 基础方块的绘制
face.blit(im_square, (0, 0))
face1 = pygame.Surface((size, size), flags=pygame.HWSURFACE) # 基础方块的投影绘制
face1.blit(im_square, (0, 0))
face1.set_alpha(aph)
f = pygame.font.Font(path + "font/set.ttf", word_size[0])
f1 = pygame.font.Font(path + "font/set.ttf", word_size[1])
# 全屏控制函数
def screen_c():
global set, c_l, c_s, f, f1, c_dif, width, height, multipl, size, screen1, word_size, screen, face, im_square, im_set, im_quit, im_pause, im_start, im_start3, im_continue, im_start2, im, face1, screenset, origin
if c_set[3] == 1:
screen1 = pygame.display.set_mode((width, height), flags=pygame.HWSURFACE | pygame.FULLSCREEN) # 屏幕大小
c_l[0] = c_s.current_w
c_l[1] = c_s.current_h
multipl = min(round(c_l[0] / width, 1), round(c_l[1] / height, 1))
for i in filled:
i[0] = round(i[0] * multipl)
i[1] = round(i[1] * multipl)
width = round(width * multipl)
height = round(height * multipl)
c_dif[0] = (c_l[0] - width) / 2
c_dif[1] = (c_l[1] - height) / 2
set[0] = int(set[0] * multipl)
set[1] = int(set[1] * multipl)
origin[0] = int(10 * multipl)
origin[1] = int(10 * multipl)
if c_set[3] == 0:
set[0] = round(set[0] / multipl)
set[1] = round(set[1] / multipl)
origin[0] = int(origin[0] / multipl)
origin[1] = int(origin[1] / multipl)
for i in filled:
i[0] = round(i[0] / multipl)
i[1] = round(i[1] / multipl)
width = Width
height = Height
c_l[0] = width
c_l[1] = 700
multipl = 1
c_dif[0] = 0
c_dif[1] = 0
size = int(30 * multipl) # 方块规格
word_size = [int(35 * multipl // 1), int(200 * multipl // 1)]
im_square = pygame.image.load(path + "phto\\square.png")
im_square = pygame.transform.rotozoom(im_square, 0, multipl)
im = pygame.image.load(path + "phto\\main_ground.png")
im = pygame.transform.rotozoom(im, 0, multipl)
screen = pygame.image.load(path + "phto\\main_ground.png")
screen = pygame.transform.rotozoom(screen, 0, multipl)
im_start = pygame.image.load(path + "phto\\start_ground.png")
im_start = pygame.transform.rotozoom(im_start, 0, multipl)
im_start2 = pygame.image.load(path + "phto\\game_s_w.png")
im_start2 = pygame.transform.rotozoom(im_start2, 0, multipl)
im_start3 = pygame.image.load(path + "phto\\game_s_y.png")
im_start3 = pygame.transform.rotozoom(im_start3, 0, multipl)
im_quit = pygame.image.load(path + "phto\\quit.png")
im_quit = pygame.transform.rotozoom(im_quit, 0, multipl)
im_continue = pygame.image.load(path + "phto\\continue.png")
im_continue = pygame.transform.rotozoom(im_continue, 0, multipl)
im_pause = pygame.image.load(path + "phto\\pause.png")
im_pause = pygame.transform.rotozoom(im_pause, 0, multipl)
im_set = pygame.image.load(path + "phto\\ground.png")
im_set = pygame.transform.rotozoom(im_set, 0, multipl)
face = pygame.Surface((size, size), flags=pygame.HWSURFACE) # 基础方块的绘制
face.blit(im_square, (0, 0))
face1 = pygame.Surface((size, size), flags=pygame.HWSURFACE) # 基础方块的投影绘制
face1.blit(im_square, (0, 0))
face1.set_alpha(80)
f = pygame.font.Font(path + "font/set.ttf", word_size[0])
f1 = pygame.font.Font(path + "font/set.ttf", word_size[1])
# point = [(size/30,0),(size-size/30,0),(0,size/30),(0,size-size/30),(size/30,size),(size-size/30,size),(size,size-size/30),(size,size/30)]
# face2 = pygame.draw.polygon()
if c_set[3] == 0:
screen1 = pygame.display.set_mode((width, height))
pygame.display.flip()
# 游戏设置界面
def set_update():
c = 0
s = 0
key1 = 0
w_fu = "辅助投影:开"
a_music = "背景音乐:开"
b_music = "音 效:开"
s_en = "全 屏:开"
if c_set[0] == 0:
w_fu = "辅助投影:关"
if c_set[1] == 0:
a_music = "背景音乐:关"
if c_set[2] == 0:
b_music = "音 效:关"
while c == 0:
im_set = pygame.image.load(path + "phto\\ground.png")
im_set = pygame.transform.rotozoom(im_set, 0, multipl)
m = im_set
d = d1 = 0
d_keys = {"左 移": left, "右 移": right, "下 移": down, "强 降": plunge, "保 留": change, "左 旋": spi_l,
"右 旋": spi_r}
for k, v in d_keys.items():
d += 1
m.blit(f.render(str(k) + ":" + pygame.key.name(v), True, word_color[3]),
(100 * width / Width, (80 + 50 * d - 50) * height / Height))
if s == 0:
for e in pygame.event.get():
if e.type == pygame.QUIT:
isquit()
if e.type == pygame.MOUSEBUTTONDOWN:
sn = [key for key in d_keys.keys()]
for i in range(len(sn)):
if isin((180, 90 + i * 50), (180 + 50 + 90, 90 + i * 50 + 30)):
key2 = d_keys[sn[i]]
for key in d_keys.values():
d1 += 1
if key2 == key:
m.blit(f.render(" ", True, (255, 0, 0), (255, 255, 255)),
((180 + 50) * width / Width, (80 + 50 * d1 - 50) * height / Height))
key1 = key
s = 1
d1 = 0
if isin((0, 0), (4 * 30, 3 * 30)):
c = 1
if isin((180, 80 + 50 * 7), (280, 80 + 50 * 9 - 50)):
if c_set[0] == 0:
c_set[0] = 1
w_fu = "辅助投影:开"
else:
c_set[0] = 0
w_fu = "辅助投影:关"
if isin((180, 130 + 50 * 7), (280, 80 + 50 * 7 + 100)):
if c_set[1] == 0:
c_set[1] = 1
a_music = "背景音乐:开"
music1.play(-1)
else:
c_set[1] = 0
a_music = "背景音乐:关"
music1.stop()
if isin((180, 180 + 50 * 7), (280, 80 + 50 * 7 + 150)):
if c_set[2] == 0:
c_set[2] = 1
b_music = "音 效:开"
else:
c_set[2] = 0
b_music = "音 效:关"
if isin((180, 180 + 50 * 8), (280, 80 + 50 * 8 + 150)):
if c_set[3] == 1:
c_set[3] = 0
s_en = "全 屏:关"
screen_c()
else:
c_set[3] = 1
s_en = "全 屏:开"
screen_c()
m.blit(f.render(w_fu, True, word_color[4]),
((100 - 7) * width / Width, (80 + 50 * 7) * height / Height))
m.blit(f.render(a_music, True, word_color[4]),
((100 - 7) * width / Width, (80 + 50 + 50 * 7) * height / Height))
m.blit(f.render(b_music, True, word_color[4]),
(100 * width / Width, (80 + 100 + 50 * 7) * height / Height))
m.blit(f.render(s_en, True, word_color[4]), (100 * width / Width, (80 + 100 + 50 * 8) * height / Height))
screen1.blit(m, c_dif)
pygame.display.flip()
if s == 1:
s = 0
c_operation(key1)
def c_operation(a):
global left, right, down, spi_l, spi_r, change, plunge, again
c = 1 # 判断循环继续否
m = 0 # 判断更改的键位
for i in left, right, down, spi_l, spi_r, change, plunge:
m += 1
if a == i:
while c == 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.KEYDOWN:
c = 0
if m == 1:
left = event.key
if m == 2:
right = event.key
if m == 3:
down = event.key
if m == 4:
spi_l = event.key
if m == 5:
spi_r = event.key
if m == 6:
change = event.key
if m == 7:
plunge = event.key
if event.type == pygame.MOUSEBUTTONDOWN:
c = 0
# 数据清零
def data_clear():
global leve, lock
filled.clear()
leve = 1
lock = 0.3
n[0] = 0
for i in range(len(sores_roboot)):
sores[i] = 0
for i in range(len(sores)):
sores[i] = 0
set[0] = origin[0] + 4 * size
set[1] = origin[1] + 0
ch1[4] = 0
ch1[0] = c_list[random.randint(0, len(c_list) - 1)]
ch1[1] = c_list[random.randint(0, len(c_list) - 1)]
ch1[2] = c_list[random.randint(0, len(c_list) - 1)]
ch1[3] = c_list[random.randint(0, len(c_list) - 1)]
# 点击区域判断
def isin(a1, a2):
if type(a1) == tuple:
a1 = list(a1)
if type(a2) == tuple:
a2 = list(a2)
a1[0] *= multipl
a1[1] *= multipl
a2[0] *= multipl
a2[1] *= multipl
a1[0] += c_dif[0]
a1[1] += c_dif[1]
a2[0] += c_dif[0]
a2[1] += c_dif[1]
if pygame.mouse.get_pos()[0] <= a2[0] and pygame.mouse.get_pos()[0] >= a1[0] and pygame.mouse.get_pos()[1] <= a2[
1] and pygame.mouse.get_pos()[1] >= a1[1]:
return True
else:
return False
# 方块颜色控制
def d_color(c, face=face):
a = -1
colors = ((0, 160, 233), (34, 172, 56), (230, 0, 18), (146, 7, 131), (235, 97, 0), (0, 71, 157), (243, 152, 0))
if c == 1 or c == 2 or c == -2:
a = 0
face.fill(colors[0])
if c == 3 or c == 4:
face.fill(colors[1])
a = 1
if c == 5 or c == 6:
a = 2
face.fill(colors[2])
if c >= 7 and c <= 10:
a = 3
face.fill(colors[3])
if c >= 11 and c <= 14:
a = 4
face.fill(colors[4])
if c >= 15 and c <= 18:
a = 5
face.fill(colors[5])
if c == 19:
a = 6
face.fill(colors[6])
pygame.draw.rect(face, colors[a], [0, 0, size, size], 1)
face.blit(im_square, (0, 0))
# 判断碰撞情况
def isc_l():
for i in filled:
for k in range(4):
if (i[0] == forms(ch1[0], set)[k][0] and i[1] == forms(ch1[0], set)[k][1]) or \
forms(ch1[0], set)[4][0] < origin[0] or forms(ch1[0], set)[5][0] > 9 * size + \
origin[0] or forms(ch1[0], set)[5][1] > 19 * size + origin[1]:
set[1] += size
set[0] -= size
for i in filled:
for j in range(4):
for k in range(4):
if (i[0] == forms(ch1[0], set)[k][0] and i[1] ==
forms(ch1[0], set)[k][1]) or forms(ch1[0], set)[4][0] < origin[0] or \
forms(ch1[0], set)[5][0] > 9 * size + origin[0] or forms(ch1[0], set)[5][
1] > 19 * size + origin[1]:
set[0] += 2 * size
for i in filled:
for j in range(4):
for k in range(4):
if (i[0] == forms(ch1[0], set)[k][0] and i[1] ==
forms(ch1[0], set)[k][1]) or forms(ch1[0], set)[4][0] < \
origin[0] or forms(ch1[0], set)[5][0] > 9 * size + \
origin[0] or forms(ch1[0], set)[5][1] > 19 * size + origin[1]:
set[1] -= size
set[0] -= size
set[1] -= size
set[0] += size
for i in filled:
for j in range(4):
for k in range(4):
if (i[0] == forms(ch1[0], set)[k][0] and
i[1] ==
forms(ch1[0], set)[k][1]) or forms(ch1[0], set)[4][
0] < \
origin[0] or forms(ch1[0], set)[5][
0] > 9 * size + \
origin[0] or forms(ch1[0], set)[5][
1] > 19 * size + origin[1]:
set[0] -= size
set[1] += size
set[0] += size
set[1] += 2 * size
for i in filled:
for j in range(4):
for k in range(4):
if (i[0] ==
forms(ch1[0], set)[
k][0] and
i[1] ==
forms(ch1[0], set)[k][1]) or \
forms(ch1[0], set)[4][0] < \
origin[0] or \
forms(ch1[0], set)[5][
0] > 9 * size + origin[0] or \
forms(ch1[0], set)[5][
1] > 19 * size + origin[1]:
set[0] -= size
set[1] -= 2 * size
spin(0)
m_lock.play()
def isc_r():
for i in filled:
for k in range(4):
if (i[0] == forms(ch1[0], set)[k][0] and i[1] == forms(ch1[0], set)[k][1]) or \
forms(ch1[0], set)[4][0] < origin[0] or forms(ch1[0], set)[5][0] > 9 * size + origin[0] or \
forms(ch1[0], set)[5][1] > 19 * size + origin[1]:
set[1] += size
set[0] += size
for i in filled:
for j in range(4):
for k in range(4):
if (i[0] == forms(ch1[0], set)[k][0] and i[1] == forms(ch1[0], set)[k][1]) or \
forms(ch1[0], set)[4][0] < origin[0] or forms(ch1[0], set)[5][0] > 9 * size + \
origin[0] or forms(ch1[0], set)[5][1] > 19 * size + origin[1]:
set[0] -= 2 * size
for i in filled:
for j in range(4):
for k in range(4):
if (i[0] == forms(ch1[0], set)[k][0] and i[1] ==
forms(ch1[0], set)[k][1]) or forms(ch1[0], set)[4][0] < origin[0] or \
forms(ch1[0], set)[5][0] > 9 * size + origin[0] or \
forms(ch1[0], set)[5][1] > 19 * size + origin[1]:
set[1] -= size
set[0] += size
set[1] -= size
set[0] -= size
for i in filled:
for j in range(4):
for k in range(4):
if (i[0] == forms(ch1[0], set)[k][0] and
i[1] == forms(ch1[0], set)[k][1]) or \
forms(ch1[0], set)[4][0] < origin[
0] or forms(ch1[0], set)[5][
0] > 9 * size + origin[0] or \
forms(ch1[0], set)[5][
1] > 19 * size + origin[1]:
set[1] += size
set[0] += size
set[1] += 2 * size
set[0] -= size
for i in filled:
for j in range(4):
for k in range(4):
if (i[0] ==
forms(ch1[0], set)[k][
0] and i[1] ==
forms(ch1[0], set)[k][
1]) or \
forms(ch1[0], set)[
4][0] < origin[
0] or \
forms(ch1[0], set)[
5][
0] > 9 * size + \
origin[0] or \
forms(ch1[0], set)[
5][
1] > 19 * size + \
origin[1]:
set[1] -= 2 * size
set[0] += size
set[1] -= size
for i in filled:
for j in range(4):
for k in range(
4):
if (i[
0] ==
forms(
ch1[
0],
set)[
k][
0] and
i[
1] ==
forms(
ch1[
0],
set)[
k][
1]) or \
forms(
ch1[
0],
set)[
4][
0] < \
origin[
0] or \
forms(
ch1[
0],
set)[
5][
0] > 9 * size + \
origin[
0] or \
forms(
ch1[
0],
set)[
5][
1] > 19 * size + \
origin[
1]:
set[
1] += size
spin(1)
m_lock.play()
def iscreak1():
if forms(ch1[0], set)[4][0] < origin[0]:
set[0] += size
iscreak1()
if forms(ch1[0], set)[5][0] > origin[0] + 9 * size:
set[0] -= size
iscreak1()
# 落地判断
if forms(ch1[0], set)[5][1] > origin[1] + 19 * size:
c_isd[0] = 1
set[1] -= size
if c_set[2] == 1:
m_tention.stop()
m_downed.play()
for i in range(4):
filled.append(forms(ch1[0], set)[i] + [ch1[0]])
# filled.append(copy.deepcopy(forms(ch1[0], set)))
set1[0] = set[0]
set1[1] = set[1]
ch1[5] = ch1[0]
ch1[0] = ch1[1]
ch1[1] = ch1[2]
ch1[2] = ch1[3]
ch1[3] = c_list[random.randint(0, len(c_list) - 1)]
while ch1[3] == ch1[2] and ch1[3] == ch1[1]:
ch1[3] = c_list[random.randint(0, len(c_list) - 1)]
isclear(filled)
set[0] = 4 * size + origin[0]
set[1] = origin[1] - 2 * size
while ch1[3] == ch1[2] and ch1[3] == ch1[1]:
ch1[3] = c_list[random.randint(0, len(c_list) - 1)]
n[0] = 0
if iscrash(forms(ch1[0], set), filled)[0] == 0:
c_isd[0] = 1
set[1] -= size
if c_set[2] == 1:
m_tention.stop()
m_downed.play()
for i in range(4):
filled.append(forms(ch1[0], set)[i] + [ch1[0]])
# filled.append(copy.deepcopy(forms(ch1[0], set)))
set1[0] = set[0]
set1[1] = set[1]
ch1[5] = ch1[0]
ch1[0] = ch1[1]
ch1[1] = ch1[2]
ch1[2] = ch1[3]
ch1[3] = c_list[random.randint(0, len(c_list) - 1)]
isclear(filled)
set[0] = 4 * size + origin[0]
set[1] = origin[1] - 2 * size
while ch1[3] == ch1[2] and ch1[3] == ch1[1]:
ch1[3] = c_list[random.randint(0, len(c_list) - 1)]
n[0] = 0
if forms(ch1[0], set)[4][1] < origin[1]:
set[1] += size
# 退出游戏判断
def isquit():
im_isq = pygame.image.load(path + "phto/isquit.png")
im_isq = pygame.transform.rotozoom(im_isq, 0, multipl)
c = 1
while c == 1:
screen1.blit(im_isq, (size + c_dif[0], 6 * size + c_dif[1]))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((30, 353), (137, 402)):
pygame.quit()
sys.exit()
if isin((342, 349), (462, 403)):
c = 0
# 满行判断,速度计算
def isclear(form1):
global leve, sore, lock
q = 0
sum1 = 0 # allcler
tention = 0
for j in range(20):
sum = 0
c = j * size + origin[1]
for i in form1:
if i[1] == c:
sum += i[0]
if sum == 45 * size + origin[0] * 10:
q += 1
for i in form1:
if i[1] == c:
i[1] = size * 30
if i[1] < c:
i[1] += size
for x in range(20):
sum1 = 1
n = x * size + origin[1]
for o in form1:
if o[1] == n:
sum1 = 0
for i in form1:
if i[1] >= 25 * size:
form1.remove(i)
for j in range(5):
c = j * size + origin[1]
for i in form1:
if i[1] == c:
tention = 1
if sum1 == 1:
q = 5
a = 1
if iscrash(forms(0, [set1[0], set1[1] - size + q * size]), form1)[0] == 0:
a = 0
b = 1
if iscrash(forms(-1, [set1[0], set1[1] - 3 * size + q * size]), form1)[0] == 0:
b = 0
# 分数计算
sores[2] += q
sq = 0
if q != 0:
if c_set[2] == 1:
m_tention.stop()
m_one.play()
sq += sore + (q - 1) * sore
if q == 3:
if c_set[2] == 1:
m_tention.stop()
m_one.play(1)
if q == 4:
sq += 5 * sore
if c_set[2] == 1:
m_tention.stop()
m_four.play()
if q == 2 and ch1[5] == 9 and a == 0: # Tspin
sq += 5 * sore
sores[1] += 1
if c_set[2] == 1:
m_tention.stop()
m_t.play()
if q == 1 and ch1[5] == 9 and a == 0: # Tspin
sq += 3 * sore
sores[1] += 1
if c_set[2] == 1:
m_tention.stop()
m_t.play()
if q == 3 and (ch1[5] == 8 or ch1[5] == 10) and b == 0: # Tspin3
sq += 7 * size
sores[1] += 1
if c_set[2] == 1:
m_tention.stop()
m_t.play()
if q == 2 and (ch1[5] == 8 or ch1[5] == 10) and b == 0: # Tspin3
sq += 5 * sore
sores[1] += 1
if c_set[2] == 1:
m_tention.stop()
m_t.play()
if q == 5:
sq += sore
m_tention.stop()
m_allclear.play()
if tention == 1 and control[0] == 1:
tention = 0
if c_set[2] == 1:
m_tention.play()
sores[0] += sq
if sq != 0:
sor = f.render("+" + str(int(sq)), True, (255, 255, 255))
screen.blit(sor, (width / Width * 330 + size, 50 * height / Height - size))
# 速度计算
if sores[0] < 100:
leve = 1
if sores[0] >= 100 and sores[0] < 500:
leve = 0.8
if sores[0] >= 500 and sores[0] < 1000:
leve = 0.6
sore = 15
if sores[0] >= 1000 and sores[0] < 2000:
leve = 0.4
sore = 20
if sores[0] >= 2000 and sores[0] < 5000:
leve = 0.2
sore = 30
lock = 0.7
if sores[0] >= 5000:
leve = 0
sore = 50
lock = 0.8
# 碰撞判断
def iscrash(form, form1):
a, b, m, n = 10, 10, 10, 10
# 上下碰撞
for i in form1:
for j in range(4):
if i[0] == form[j][0] and i[1] - form[j][1] == 0:
a = 0
for i in form1:
for j in range(4):
if i[0] - form[j][0] == 0 and i[1] - form[j][1] == size:
n = 0
# 碰right
for i in form1:
for j in range(4):
if i[0] - form[j][0] == 0 and i[1] - form[j][1] == 0:
b = 1
# 碰left
for i in form1:
for j in range(4):
if form[j][0] - i[0] == 0 and i[1] - form[j][1] == 0:
m = 2
return a, b, m, n
# 方块旋转
def spin(a):
if a == 0: # 右旋
if ch1[0] == 1:
ch1[0] = 2
return ch1[0]
if ch1[0] == -2:
ch1[0] = 1
return ch1[0]
if ch1[0] == 2:
ch1[0] = 1
return ch1[0]
if ch1[0] == 3:
ch1[0] = 4
return ch1[0]
if ch1[0] == 4:
ch1[0] = 3
return ch1[0]
if ch1[0] == 5:
ch1[0] = 6
return ch1[0]
if ch1[0] == 6:
ch1[0] = 5
return ch1[0]
if ch1[0] == 7:
ch1[0] = 8
return ch1[0]
if ch1[0] == 8:
ch1[0] = 9
return ch1[0]
if ch1[0] == 9:
ch1[0] = 10
return ch1[0]
if ch1[0] == 10:
ch1[0] = 7
return ch1[0]
if ch1[0] == 11:
ch1[0] = 12
return ch1[0]
if ch1[0] == 12:
ch1[0] = 13
return ch1[0]
if ch1[0] == 13:
ch1[0] = 14
return ch1[0]
if ch1[0] == 14:
ch1[0] = 11
return ch1[0]
if ch1[0] == 15:
ch1[0] = 16
return ch1[0]
if ch1[0] == 16:
ch1[0] = 17
return ch1[0]
if ch1[0] == 17:
ch1[0] = 18
return ch1[0]
if ch1[0] == 18:
ch1[0] = 15
return ch1[0]
if ch1[0] == 19:
ch1[0] = 19
return ch1[0]
if a == 1: # 左旋
if ch1[0] == 1:
ch1[0] = -2
return ch1[0]
if ch1[0] == -2:
ch1[0] = 1
return ch1[0]
if ch1[0] == 2:
ch1[0] = 1
return ch1[0]
if ch1[0] == 3:
ch1[0] = 4
return ch1[0]
if ch1[0] == 4:
ch1[0] = 3
return ch1[0]
if ch1[0] == 5:
ch1[0] = 6
return ch1[0]
if ch1[0] == 6:
ch1[0] = 5
return ch1[0]
if ch1[0] == 7:
ch1[0] = 10
return ch1[0]
if ch1[0] == 10:
ch1[0] = 9
return ch1[0]
if ch1[0] == 9:
ch1[0] = 8
return ch1[0]
if ch1[0] == 8:
ch1[0] = 7
return ch1[0]
if ch1[0] == 11:
ch1[0] = 14
return ch1[0]
if ch1[0] == 14:
ch1[0] = 13
return ch1[0]
if ch1[0] == 13:
ch1[0] = 12
return ch1[0]
if ch1[0] == 12:
ch1[0] = 11
return ch1[0]
if ch1[0] == 15:
ch1[0] = 18
return ch1[0]
if ch1[0] == 18:
ch1[0] = 17
return ch1[0]
if ch1[0] == 17:
ch1[0] = 16
return ch1[0]
if ch1[0] == 16:
ch1[0] = 15
return ch1[0]
if ch1[0] == 19:
ch1[0] = 19
return ch1[0]
def move():
global pause, c_key, c_left, c_right, c_down, rob, sensitivity
# 获取键盘事件
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
# 按键操作
if event.type == pygame.KEYDOWN:
if event.key == left:
c_left = 1
elif event.key == right:
c_right = 1
elif event.key == down:
c_down = 1
elif event.key == spi_r:
spin(0)
isc_r()
iscreak1()
elif event.key == spi_l:
spin(1)
isc_l()
iscreak1()
elif event.key == change:
if n[0] == 0:
if ch1[4] == 0:
if ch1[0] == 19:
ch1[4] = 19
if ch1[0] >= 1 and ch1[0] <= 2:
ch1[4] = 2
if ch1[0] >= 3 and ch1[0] <= 4:
ch1[4] = 4
if ch1[0] >= 5 and ch1[0] <= 6:
ch1[4] = 6
if ch1[0] >= 7 and ch1[0] <= 10:
ch1[4] = 7
if ch1[0] >= 11 and ch1[0] <= 14:
ch1[4] = 14
if ch1[0] >= 15 and ch1[0] <= 18:
ch1[4] = 16
ch1[0] = ch1[1]
ch1[1] = ch1[2]
ch1[2] = ch1[3]
ch1[3] = c_list[random.randint(0, 6)]
set[0] = 4 * size + origin[0]
set[1] = origin[1] + 0
n[0] = 1
else:
v = ch1[0]
ch1[0] = ch1[4]
if v == 19:
ch1[4] = 19
if v >= 1 and v <= 2:
ch1[4] = 2
if v >= 3 and v <= 4:
ch1[4] = 4
if v >= 5 and v <= 6:
ch1[4] = 6
if v >= 7 and v <= 10:
ch1[4] = 7
if v >= 11 and v <= 14:
ch1[4] = 14
if v >= 15 and v <= 18:
ch1[4] = 16
set[0] = 4 * size + origin[0]
set[1] = origin[1] + 0
n[0] = 1
elif event.key == plunge:
a = 20 * size - forms(ch1[0], set)[5][1] + origin[1]
for i in filled:
for k in range(4):
if i[0] == forms(ch1[0], set)[k][0]:
if a > i[1] - forms(ch1[0], set)[k][1] and i[1] - forms(ch1[0], set)[k][
1] > 0:
a = i[1] - forms(ch1[0], set)[k][1]
set[1] += a
iscreak1()
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
c_left = 0
if event.key == pygame.K_RIGHT:
c_right = 0
if event.key == pygame.K_DOWN:
c_down = 0
# 鼠标操作
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((470, 0), (500, 30)):
self.p_operation()
if not isin((0, 0), (500, 700)):
self.p_operation()
move1()
iscreak1()
# 方块类型函数
def forms(c, a, size=size):
if c == -1:
x0 = 0
y0 = 0
x1 = 0
y1 = 0
x2 = 0
y2 = 0
x3 = 0
y3 = 0
if c == 0:
x0 = 0
y0 = 0
x1 = 0
y1 = 0
x2 = -1
y2 = 0
x3 = 1
y3 = 0
# 长条
if c == 1:
x0 = 0
y0 = 0
x1 = 0
y1 = -1
x2 = 0
y2 = -2
x3 = 0
y3 = 1
if c == -2:
x0 = 0
y0 = 0
x1 = -1
y1 = 0
x2 = 1
y2 = 0
x3 = -2
y3 = 0
if c == 2: # 横条
x0 = 0
y0 = 0
x1 = -1
y1 = 0
x2 = 1
y2 = 0
x3 = 2
y3 = 0
# S
if c == 3:
x0 = 0
y0 = 0
x1 = 1
y1 = 0
x2 = 0
y2 = -1
x3 = 1
y3 = 1
if c == 4:
x0 = 0
y0 = 0
x1 = 1
y1 = 0
x2 = 0
y2 = 1
x3 = -1
y3 = 1
# Z
if c == 5:
x0 = 0
y0 = 0
x1 = -1
y1 = 0
x2 = 0
y2 = -1
x3 = -1
y3 = 1
if c == 6:
x0 = 0
y0 = 0
x1 = -1
y1 = 0
x2 = 0
y2 = 1
x3 = 1
y3 = 1
# T
if c == 7:
x0 = 0
y0 = 0
x1 = 1
y1 = 0
x2 = 0
y2 = -1
x3 = -1
y3 = 0
if c == 8:
x0 = 0
y0 = 0
x1 = 0
y1 = -1
x2 = 0
y2 = 1
x3 = 1
y3 = 0
if c == 9:
x0 = 0
y0 = 0
x1 = -1
y1 = 0
x2 = 0
y2 = 1
x3 = 1
y3 = 0
if c == 10:
x0 = 0
y0 = 0
x1 = 0
y1 = 1
x2 = 0
y2 = -1
x3 = -1
y3 = 0
# L
if c == 11:
x0 = 0
y0 = 0
x1 = 0
y1 = -1
x2 = 0
y2 = 1
x3 = 1
y3 = 1
if c == 12:
x0 = 0
y0 = 0
x1 = -1
y1 = 0
x2 = 1
y2 = 0
x3 = -1
y3 = 1
if c == 13:
x0 = 0
y0 = 0
x1 = 0
y1 = -1
x2 = 0
y2 = 1
x3 = -1
y3 = -1
if c == 14:
x0 = 0
y0 = 0
x1 = -1
y1 = 0
x2 = 1
y2 = 0
x3 = 1
y3 = -1
# J
if c == 15:
x0 = 0
y0 = 0
x1 = 0
y1 = -1
x2 = 0
y2 = 1
x3 = -1
y3 = 1
if c == 16:
x0 = 0
y0 = 0
x1 = -1
y1 = -1
x2 = -1
y2 = 0
x3 = 1
y3 = 0
if c == 17:
x0 = 0
y0 = 0
x1 = 0
y1 = 1
x2 = 0
y2 = -1
x3 = 1
y3 = -1
if c == 18:
x0 = 0
y0 = 0
x1 = -1
y1 = 0
x2 = 1
y2 = 0
x3 = 1
y3 = 1
# 田
if c == 19:
x0 = 0
y0 = 0
x1 = 0
y1 = 1
x2 = -1
y2 = 0
x3 = -1
y3 = 1
mx = max(x0, x1, x2, x3)
my = max(y0, y1, y2, y3)
mx1 = min(x0, x1, x2, x3)
my1 = min(y0, y1, y2, y3)
Z = [[x0 * size + a[0], y0 * size + a[1]], [x1 * size + a[0], y1 * size + a[1]],
[x2 * size + a[0], y2 * size + a[1]], [x3 * size + a[0], y3 * size + a[1]],
[mx1 * size + a[0], my1 * size + a[1]], [mx * size + a[0], my * size + a[1]], c]
return Z
# 方块移动控制函数
def move1():
global c_left, c_right, c_down
if c_left:
set[0] -= size
if sensitivity==0:
c_left=0
if iscrash(forms(ch1[0], set), filled)[2] == 2:
set[0] += size
iscreak1()
time.sleep(sensitivity)
if c_right:
set[0] += size
if sensitivity==0:
c_right=0
if iscrash(forms(ch1[0], set), filled)[1] == 1:
set[0] -= size
iscreak1()
time.sleep(sensitivity)
if c_down:
set[1] += size
if sensitivity==0:
c_down=0
iscreak1()
time.sleep(sensitivity + 0.02)
def rank_chang():
c = 1
while c == 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.MOUSEBUTTONDOWN:
if isin(d_isin['back'][0], d_isin['back'][1]):
c = 0
for i in range(3):
if isin((d_isin['options'][0][0], d_isin['options'][0][1] + i * 60),
(d_isin['options'][1][0], d_isin['options'][1][1] + i * 60)):
if i == 0:
p = Classic()
p.rank_list()
if i == 1:
p = Line40()
p.rank_list40()
if i == 2:
p = Integral12()
p.rank_list()
face_chang = pygame.image.load(path + "phto/rank_change.png")
face_chang = pygame.transform.rotozoom(face_chang, 0, multipl)
font1 = f.render("经典模式榜单", True, word_color[1])
font2 = f.render("40行榜单", True, word_color[1])
font3 = f.render("120秒积分榜单", True, word_color[1])
# [(125, 150), (375, 210)]
face_chang.blit(font1, (width / 4, height / 5))
face_chang.blit(font2, (width / 4, height / 5 + 2 * size))
face_chang.blit(font3, (width / 4, height / 5 + 4 * size))
screen1.blit(face_chang, c_dif)
pygame.display.flip()
# 模式选择
def model_change():
c = 1
while c == 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.MOUSEBUTTONDOWN:
if isin(d_isin['back'][0], d_isin['back'][1]):
c = 0
for i in range(3):
if isin((d_isin['options'][0][0], d_isin['options'][0][1] + i * 60),
(d_isin['options'][1][0], d_isin['options'][1][1] + i * 60)):
start[1] = i + 1
c = 0
break
face_chang = pygame.image.load(path + "phto/model_change.png")
face_chang = pygame.transform.rotozoom(face_chang, 0, multipl)
font1 = f.render("经典模式", True, word_color[1])
font2 = f.render("40行挑战", True, word_color[1])
font3 = f.render("120秒积分赛", True, word_color[1])
# [(125, 150), (375, 210)]
face_chang.blit(font1, (width / 4, height / 5))
face_chang.blit(font2, (width / 4, height / 5 + 2 * size))
face_chang.blit(font3, (width / 4, height / 5 + 4 * size))
screen1.blit(face_chang, c_dif)
pygame.display.flip()
def start_update1():
while 1:
start[0] = 0
start[1] = 0
s_operation1()
im_start = pygame.image.load(path + "phto\\start_ground.png")
im_start = pygame.transform.rotozoom(im_start, 0, multipl)
im_start.blit(im_continue, (width / 5 + 1 * size, height / 2 - 2.5 * size))
screen1.blit(im_start, c_dif)
pygame.display.flip()
if start[1] == -1:
break
if start[1] == 3:
game_main12()
if start[1] == 1:
game_main()
if start[1] == 2:
game_main40()
if start[0] == 2:
set_update()
if start[0] == 3:
rank_chang()
# 游戏开始有缓存操作
def s_operation1():
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
start[1] = -1
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((332, 10), (491, 62)):
start[0] = 3
if isin((163, 277), (392, 347)):
start[1] = -1
if isin((163, 372), (392, 442)):
data_clear()
model_change()
if isin((163, 464), (392, 530)):
start[0] = 2
if isin((370, 90), (498, 138)):
c_skin()
if isin((163, 559), (390, 626)):
isquit()
# 游戏开始界面
def start_update():
while 1:
# c_operation()
start[1] = -1
start[0] = 0
s_operation()
time.sleep(0.01)
# 开始界面,开始按钮的闪烁
screen1.blit(im_start, c_dif)
im_start.blit(im_start2, (width / 5, height / 2))
pygame.display.flip()
time.sleep(0.01)
screen1.blit(im_start, c_dif)
im_start.blit(im_start3, (width / 5, height / 2))
im_start.blit(im_quit, (width / 5 + size, height / 2 + 3.5 * size))
pygame.display.flip()
# 模式控制
if start[1] == 4:
game_main_roboot()
if start[1] == 3:
game_main12()
if start[1] == 1:
game_main()
if start[1] == 2:
game_main40()
if start[0] == 2:
set_update()
if start[0] == 3:
rank_chang()
# 游戏开始界面操作
def s_operation():
global width, height, multipl, screen1
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
model_change()
if event.key == pygame.K_F11:
screen_c()
if event.key == pygame.K_1:
c_skin()
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((100, 350), (400, 425)):
model_change()
if isin((135, 459), (381, 528)):
start[0] = 2
if isin((141, 560), (366, 630)):
isquit()
if isin((332, 10), (491, 62)):
start[0] = 3
if isin((370, 90), (498, 138)):
c_skin()
def main():
screen_c()
if c_set[1] == 1:
music1.play(-1)
start_update()
# 经典模式主循环
def game_main():
gameClassic = Classic()
gameClassic.t_start = time.time()
while 1:
# clock.tick(120)
if control[0] == 1:
t1 = []
while 1:
clock.tick(120)
t = time.time()
while 1:
gameClassic.move()
gameClassic.update()
if control[0] == 0:
break
if time.time() - t >= leve:
# 锁底解决
if iscrash(forms(ch1[0], set), filled)[3] == 0 or forms(ch1[0], set)[5][1] == origin[
1] + 19 * size:
t1.append(t)
if time.time() - t1[0] >= leve + lock:
t = time.time()
set[1] += size
iscreak1()
t1.clear()
break
break
else:
t = time.time()
set[1] += size
iscreak1()
break
gameClassic.move()
gameClassic.update()
if control[0] == 0: break
if control[0] == 0:
while 1:
gameClassic.update()
if control[0] == 1: break
# 经典模式主循环机器人
def game_main_roboot():
r = RobootRun()
p = Classic()
while 1:
# clock.tick(120)
if control_roboot[0] == 1:
t1 = []
while 1:
clock.tick(120)
t = time.time()
while 1:
r.move()
r.update()
if control[0] == 0:
break
if time.time() - t >= leve:
# 锁底解决
if iscrash(forms(ch1[0], set), filled_roboot)[3] == 0 or forms(ch1[0], set)[5][1] == origin[
1] + 19 * size:
t1.append(t)
if time.time() - t1[0] >= leve + lock:
t = time.time()
set[1] += size
r.iscreak1()
t1.clear()
break
break
else:
t = time.time()
set[1] += size
r.iscreak1()
break
r.move()
r.update()
if control[0] == 0: break
if control_roboot[0] == 0:
while 1:
r.update()
if control[0] == 1: break
# 40行游戏循环
def game_main40():
global game40
game40 = Line40()
game40.t_start = time.time()
while 1:
if control[0] == 1:
t1 = []
while 1:
clock.tick(120)
t = time.time()
while 1:
game40.move40()
game40.update40()
if control[0] == 0:
break
if time.time() - t >= leve:
# 锁底解决
if iscrash(forms(ch1[0], set), filled)[3] == 0 or forms(ch1[0], set)[5][1] == origin[
1] + 19 * size:
t1.append(t)
if time.time() - t1[0] >= leve + lock:
t = time.time()
set[1] += size
iscreak1()
t1.clear()
break
break
else:
t = time.time()
set[1] += size
iscreak1()
break
game40.move40()
game40.update40()
if control[0] == 0: break
if control[0] == 0:
while 1:
game40.update40()
if control[0] == 1: break
def game_main12():
game12 = Integral12()
game12.t_start = time.time()
while 1:
if control[0] == 1:
t1 = []
while 1:
clock.tick(120)
t = time.time()
while 1:
game12.move()
game12.update()
if control[0] == 0:
break
if time.time() - t >= leve:
# 锁底解决
if iscrash(forms(ch1[0], set), filled)[3] == 0 or forms(ch1[0], set)[5][1] == origin[
1] + 19 * size:
t1.append(t)
if time.time() - t1[0] >= leve + lock:
t = time.time()
set[1] += size
iscreak1()
t1.clear()
break
break
else:
t = time.time()
set[1] += size
iscreak1()
break
game12.move()
game12.update()
if control[0] == 0: break
if control[0] == 0:
while 1:
game12.update()
if control[0] == 1: break
# 机器人
class Roboot:
c = 1
a = []
def __init__(self):
if c_isd[0] == 1:
c_isd[0] = 0
self.a = self.roboot(set, ch1)
'''自动操作算法'''
def run(self, set, ch1):
global c_left_roboot, c_right_roboot, c_down_roboot
ch1[0] = self.a[1]
c_right_roboot = 0
c_left_roboot = 0
c_down_roboot = 0
if set[0] != self.a[0][0]:
while set[0] > self.a[0][0]:
c_left_roboot = 1
break
while set[0] < self.a[0][0]:
c_right_roboot = 1
break
if set[1] < self.a[0][1] and set[0] == self.a[0][0]:
while set[1] < self.a[0][1]:
c_down_roboot = 1
break
if self.a[0][1] == set[1]:
self.c = 1
def down_s(self, set, ch1, filled):
a = 20 * size_roboot - forms(ch1, set, size_roboot)[5][1] + origin_roboot[1]
for i in filled:
for k in range(4):
if i[0] == forms(ch1, set, size_roboot)[k][0]:
if a > i[1] - forms(ch1, set, size_roboot)[k][1] and i[1] - forms(ch1, set, size_roboot)[k][1] > 0:
a = i[1] - forms(ch1, set, size_roboot)[k][1]
# set[1]+=a
return a
def d_d(self, ch):
if ch == 2 or ch == 1:
return [1, 2]
if ch == 4 or ch == 3:
return [3, 4]
if ch == 6 or ch == 5:
return [5, 6]
if ch == 7 or ch == 8 or ch == 9 or ch == 10:
return [7, 8, 10, 9]
if ch == 14 or ch == 11 or ch == 12 or ch == 13:
return [13, 11, 14, 12]
if ch == 16 or ch == 15 or ch == 17 or ch == 18:
return [17, 15, 16, 18]
if ch == 19:
return [19]
def sore1(self, set, ch1, filled):
list = self.d_d(ch1[0])
st1 = []
filled1 = []
st = set.copy()
c = 0
s_a = [0, 0]
for d in list:
a = 0
cont = 0
cc = []
f = []
for i in range(10):
st[0] = i * size_roboot + origin_roboot[0]
if self.iscreak(d, st) == 1:
continue
if self.down_s(st, d) >= a:
a = self.down_s(st, d)
st1 = st.copy()
c = d
st1[1] += a
filled1 = filled.copy()
filled1.append(forms(c, set_roboot1, size_roboot))
for j in range(int((forms(c, set_roboot1, size_roboot)[5][1] - origin_roboot[1]) / size_roboot),
int((forms(c, set_roboot1, size_roboot)[4][1] - origin_roboot[1]) / size_roboot + 1)):
sum = 0
n = j * size_roboot + origin_roboot[1]
for i in filled1:
if i[1] == n:
sum += 1
f.append([sum, set, a])
for i in f:
if i[0] >= cont:
cont = i[0]
cc[0] = i[1]
cc[1] = i[2]
print("11", cc)
if cc[1] > s_a[1]:
s_a = cc.copy()
return s_a
def roboot(self, set, ch1, filled):
if n[0] == 0:
if ch1[4] == 0:
if ch1[0] == 19:
ch1[4] = 19
if ch1[0] >= 1 and ch1[0] <= 2:
ch1[4] = 2
if ch1[0] >= 3 and ch1[0] <= 4:
ch1[4] = 4
if ch1[0] >= 5 and ch1[0] <= 6:
ch1[4] = 6
if ch1[0] >= 7 and ch1[0] <= 10:
ch1[4] = 7
if ch1[0] >= 11 and ch1[0] <= 14:
ch1[4] = 14
if ch1[0] >= 15 and ch1[0] <= 18:
ch1[4] = 16
ch1[0] = ch1[1]
ch1[1] = ch1[2]
ch1[2] = ch1[3]
ch1[3] = c_list[random.randint(0, 6)]
set[0] = 4 * size_roboot + origin_roboot[0]
set[1] = origin_roboot[1] + 0
n[0] = 1
list = self.d_d(ch1[0]) + self.d_d(ch1[4])
st1 = []
st = set.copy()
c = 0
q_sore = 0
for d in list:
q_sore1 = 20 * 100
for i in range(10):
filled1 = filled.copy()
st[0] = i * size_roboot + origin_roboot[0]
if self.iscreak(d, st) == 1:
continue
n1 = self.down_s(st, d, filled)
set_ce = st.copy()
set_ce[1] += n1
for i in range(4):
filled1.append(forms(d, set_ce, size_roboot)[i] + [d])
mm = self.isclear(filled1)
if mm[0] >= q_sore:
q_sore = mm[0]
if mm[1] <= q_sore1:
q_sore1 = mm[1]
st1 = set_ce.copy()
c = d
if c in self.d_d(ch1[4]):
v = ch1[0]
ch1[0] = ch1[4]
if v == 19:
ch1[4] = 19
if v >= 1 and v <= 2:
ch1[4] = 2
if v >= 3 and v <= 4:
ch1[4] = 4
if v >= 5 and v <= 6:
ch1[4] = 6
if v >= 7 and v <= 10:
ch1[4] = 7
if v >= 11 and v <= 14:
ch1[4] = 14
if v >= 15 and v <= 18:
ch1[4] = 16
set[0] = 4 * size_roboot + origin_roboot[0]
set[1] = origin_roboot[1] + 0
n[0] = 1
return [[st1[0], st1[1]], c]
def iscreak(self, ch1, set):
if forms(ch1, set, size_roboot)[4][0] < origin_roboot[0]:
return 1
if forms(ch1, set, size_roboot)[5][0] > origin_roboot[0] + 9 * size_roboot:
return 1
def isclear(self, form1):
sum = 0
sum1 = 0
for j in range(21):
c = j * size_roboot + origin_roboot[1]
for i in form1:
if i[1] == c:
sum += j
sum3 = 0
for j in range(10):
nn = 0
nn1 = 0
cc = 0
c = j * size_roboot + origin_roboot[0]
for k in range(20):
r = k * size_roboot + origin_roboot[1]
for i in form1:
if i[0] == c and i[1] == r:
nn1 += 1
cc = 1
if cc == 1:
nn += 1
kk = nn - nn1
sum3 += kk
for j in range(10):
c = j * size_roboot + origin_roboot[0]
t = 30
t1 = 0
q = 0
for i in form1:
if i[0] == c:
q += 1
if t >= int((i[1] - origin_roboot[1]) / size_roboot):
t = int((i[1] - origin_roboot[1]) / size_roboot)
t1 += 1
t = 19 - t
q = t - q
sum1 += q
return sum, sum3
# 机器人运行独立储存
class RobootRun:
"""
1.界面更新
2.方块
3.
"""
p = 1
# 机器人调用函数
def roboot(self, filled):
global c_left_roboot, c_right_roboot, c_down_roboot, rob, a, sensitivity
sensitivity = 0
if c_isd[0] == 1:
c_isd[0] = 0
rob = Roboot()
a = rob.roboot(set_roboot, ch1_roboot, filled)
ch1_roboot[0] = a[1]
c_right_roboot = 0
c_left_roboot = 0
c_down_roboot = 0
if set_roboot[0] != a[0][0]:
while set_roboot[0] > a[0][0]:
c_left_roboot = 1
break
while set_roboot[0] < a[0][0]:
c_right_roboot = 1
break
if set_roboot[1] < a[0][1] and set_roboot[0] == a[0][0]:
while set_roboot[1] < a[0][1]:
c_down_roboot = 1
break
def move1(self, filled):
global c_left_roboot, c_right_roboot, c_down_roboot
if c_left_roboot:
set_roboot[0] -= size_roboot
if iscrash(forms(ch1_roboot[0], set_roboot, size_roboot), filled)[2] == 2:
set_roboot[0] += size_roboot
self.iscreak1()
time.sleep(sensitivity)
if c_right_roboot:
set_roboot[0] += size_roboot
if iscrash(forms(ch1_roboot[0], set_roboot, size_roboot), filled)[1] == 1:
set_roboot[0] -= size_roboot
self.iscreak1()
time.sleep(sensitivity)
if c_down_roboot:
set_roboot[1] += size_roboot
self.iscreak1()
time.sleep(sensitivity + 0.02)
# 机器人独立储存空间
def iscreak1(self):
if forms(ch1_roboot[0], set_roboot, size_roboot)[4][0] < origin_roboot[0]:
set_roboot[0] += size_roboot
self.iscreak1()
if forms(ch1_roboot[0], set_roboot, size_roboot)[5][0] > origin_roboot[0] + 9 * size_roboot:
set_roboot[0] -= size_roboot
self.iscreak1()
# 落地判断
if forms(ch1_roboot[0], set_roboot, size_roboot)[5][1] > origin_roboot[1] + 19 * size_roboot:
c_isd[0] = 1
set_roboot[1] -= size_roboot
for i in range(4):
filled_roboot.append(forms(ch1_roboot[0], set_roboot, size_roboot)[i] + [ch1_roboot[0]])
set_roboot1[0] = set_roboot[0]
set_roboot1[1] = set_roboot[1]
ch1_roboot[5] = ch1_roboot[0]
ch1_roboot[0] = ch1_roboot[1]
ch1_roboot[1] = ch1_roboot[2]
ch1_roboot[2] = ch1_roboot[3]
ch1_roboot[3] = c_list[random.randint(0, len(c_list) - 1)]
while ch1_roboot[3] == ch1_roboot[2] and ch1_roboot[3] == ch1_roboot[1]:
ch1_roboot[3] = c_list[random.randint(0, len(c_list) - 1)]
self.isclear(filled_roboot)
set_roboot[0] = 4 * size_roboot + origin_roboot[0]
set_roboot[1] = origin_roboot[1] - 2 * size_roboot
while ch1_roboot[3] == ch1_roboot[2] and ch1_roboot[3] == ch1_roboot[1]:
ch1_roboot[3] = c_list[random.randint(0, len(c_list) - 1)]
n[0] = 0
if iscrash(forms(ch1_roboot[0], set_roboot, size_roboot), filled_roboot)[0] == 0:
c_isd[0] = 1
set_roboot[1] -= size_roboot
for i in range(4):
filled_roboot.append(forms(ch1_roboot[0], set_roboot, size_roboot)[i] + [ch1_roboot[0]])
set_roboot1[0] = set_roboot[0]
set_roboot1[1] = set_roboot[1]
ch1_roboot[5] = ch1_roboot[0]
ch1_roboot[0] = ch1_roboot[1]
ch1_roboot[1] = ch1_roboot[2]
ch1_roboot[2] = ch1_roboot[3]
ch1_roboot[3] = c_list[random.randint(0, len(c_list) - 1)]
self.isclear(filled_roboot)
set_roboot[0] = 4 * size_roboot + origin_roboot[0]
set_roboot[1] = origin_roboot[1] - 2 * size_roboot
while ch1_roboot[3] == ch1_roboot[2] and ch1_roboot[3] == ch1_roboot[1]:
ch1_roboot[3] = c_list[random.randint(0, len(c_list) - 1)]
n[0] = 0
if forms(ch1_roboot[0], set_roboot, size_roboot)[4][1] < origin_roboot[1]:
set_roboot[1] += size_roboot
# 屏幕更新函数
def update(self):
# 游戏框绘制
if self.p == 1:
self.p = 0
for i in range(3):
screen.blit(im, (0, 0))
sor11 = f1.render(str(3 - i), True, word_color[1])
screen.blit(sor11, (130 * multipl, 150 * multipl))
screen1.blit(screen, c_dif)
pygame.display.flip()
time.sleep(1)
screen.blit(im, (0, 0))
sor11 = f1.render("开始", True, word_color[1])
screen.blit(sor11, (80 * multipl, 150 * multipl))
screen1.blit(screen, c_dif)
pygame.display.flip()
time.sleep(1)
screen.blit(im, (0, 0))
# 判断游戏是否结束
if iscrash(forms(ch1[0], set), filled)[0] == 0 and forms(ch1[0], set)[0][1] <= origin[1]:
set[1] -= size
control[0] = 0
# 方块绘制
a = 19 * size - forms(ch1[0], set)[5][1] + origin[1]
for i in filled:
for k in range(4):
if i[0] == forms(ch1[0], set)[k][0]:
if a > i[1] - forms(ch1[0], set)[k][1] - size and i[1] - forms(ch1[0], set)[k][
1] - size >= 0:
a = i[1] - forms(ch1[0], set)[k][1] - size
for i in range(4): # 当前方块
d_color(forms(ch1[0], set)[6], face)
screen.blit(face, forms(ch1[0], set)[i])
if c_set[0] == 1:
for i in range(4): # 方块预降位置
d_color(forms(ch1[0], set)[6], face1)
screen.blit(face1, forms(ch1[0], (set[0], set[1] + a))[i])
# 方块预览
for i in range(4):
d_color(forms(ch1[1], set)[6], face)
screen.blit(face, forms(ch1[1], (330 * width / Width + 2 * size, 120 * height / Height + 2 * size))[i])
for i in range(4):
d_color(forms(ch1[2], set)[6], face)
screen.blit(face, forms(ch1[2], (330 * width / Width + 2 * size, 120 * height / Height+ 6 * size))[i])
for i in range(4):
d_color(forms(ch1[3], set)[6], face)
screen.blit(face, forms(ch1[3], (330 * width / Width + 2 * size, 120 * height / Height + 10 * size))[i])
if ch1[4] != 0:
for i in range(4):
d_color(forms(ch1[4], set)[6], face)
screen.blit(face, forms(ch1[4], (330 * width / Width + 2 * size, 120 * height / Height + 14 * size))[i])
# 落地方块绘制
for i in filled:
d_color(i[2], face)
screen.blit(face, i[:2])
# 分数绘制
if sores[0] >= 10000:
sor = f.render("分数:" + str(round(sores[0] / 10000, 2)) + "w", True, word_color[2])
else:
sor = f.render("分数:" + str(int(sores[0])), True, word_color[2])
screen.blit(sor, (width / Width * 330, 50 * height / Height))
# 绘制游戏结束界面并判断游戏是否继续
if control[0] == 0:
self.o_update()
self.update_roboot()
screen1.blit(screen, c_dif)
pygame.display.flip()
def update_roboot(self):
# 游戏框绘制
# if self.p == 1:
# self.p = 0
# for i in range(3):
# screen_roboot.blit(im_roboot, (0, 0))
# sor11 = f1.render(str(3 - i), True, word_color[1])
# screen_roboot.blit(sor11, (130 * self.m, 150 * self.m))
# screen1.blit(screen_roboot, c_dif)
# pygame.display.flip()
# time.sleep(1)
# screen_roboot.blit(set_roboot1, (0, 0))
# sor11 = f1.render("开始", True, word_color[1])
# screen_roboot.blit(sor11, (80 * self.m, 150 * self.m))
# screen1.blit(screen_roboot, c_dif)
# pygame.display.flip()
# time.sleep(1)
screen_roboot.blit(im_roboot, (0, 0))
# 判断游戏是否结束
if iscrash(forms(ch1_roboot[0], set_roboot, size_roboot), filled_roboot)[0] == 0 and \
forms(ch1_roboot[0], set_roboot, size_roboot)[0][1] <= origin_roboot[1]:
set_roboot[1] -= size_roboot
control_roboot[0] = 0
# 方块绘制
a = 19 * size_roboot - forms(ch1_roboot[0], set_roboot, size_roboot)[5][1] + origin_roboot[1]
for i in filled_roboot:
for k in range(4):
if i[0] == forms(ch1_roboot[0], set_roboot, size_roboot)[k][0]:
if a > i[1] - forms(ch1_roboot[0], set_roboot, size_roboot)[k][1] - size_roboot and i[1] - \
forms(ch1_roboot[0], set_roboot, size_roboot)[k][
1] - size_roboot >= 0:
a = i[1] - forms(ch1_roboot[0], set_roboot, size_roboot)[k][1] - size_roboot
for i in range(4): # 当前方块
d_color(forms(ch1_roboot[0], set_roboot, size_roboot)[6], face_roboot)
screen_roboot.blit(face_roboot, forms(ch1_roboot[0], set_roboot, size_roboot)[i])
if c_set[0] == 1:
for i in range(4): # 方块预降位置
d_color(forms(ch1_roboot[0], set_roboot, size_roboot)[6], face1_roboot)
screen_roboot.blit(face1_roboot,
forms(ch1_roboot[0], (set_roboot[0], set_roboot[1] + a), size_roboot)[i])
# 落地方块绘制
for i in filled_roboot:
d_color(i[2], face_roboot)
screen_roboot.blit(face_roboot, i[:2])
# 分数绘制
if sores[0] >= 10000:
sor = f.render("分数:" + str(round(sores_roboot[0] / 10000, 2)) + "w", True, word_color[2])
else:
sor = f.render("分数:" + str(int(sores_roboot[0])), True, word_color[2])
screen_roboot.blit(sor, (330, 50))
# 绘制游戏结束界面并判断游戏是否继续
if control_roboot[0] == 0:
self.o_update()
screen.blit(screen_roboot, (350, 0))
# 结束界面
def o_update(self):
im_over = pygame.image.load(path + "phto\\gameover.png")
im_over = pygame.transform.rotozoom(im_over, 0, multipl)
im_over.blit(f.render("得分:" + str(sores[0]), True, word_color[5]), (3 * size_roboot, 6 * size_roboot))
screen.blit(im_over, (size_roboot, 3 * size_roboot))
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((67, 413), (232, 458)):
self.p = 1
data_clear()
control[0] = 1
start_update()
if isin((264, 411), (434, 458)):
self.p = 1
data_clear()
control[0] = 1
def move(self):
# 获取键盘事件
for i in pygame.event.get():
if i.type == pygame.QUIT:
isquit()
'''机器人'''
self.roboot(filled_roboot)
self.move1(filled_roboot)
self.iscreak1()
# print(set,a)
def isclear(self, form1, ff=filled, sores=sores_roboot):
global leve, sore, lock
q = 0
sum1 = 0 # allcler
for j in range(20):
sum = 0
c = j * size_roboot + origin_roboot[1]
for i in form1:
if i[1] == c:
sum += i[0]
if sum == 45 * size_roboot + origin_roboot[0] * 10:
q += 1
for i in form1:
if i[1] == c:
i[1] = size_roboot * 30
if i[1] < c:
i[1] += size_roboot
for x in range(20):
sum1 = 1
n = x * size_roboot + origin_roboot[1]
for o in form1:
if o[1] == n:
sum1 = 0
for i in form1:
if i[1] >= 25 * size_roboot:
form1.remove(i)
for j in range(5):
c = j * size_roboot + origin_roboot[1]
for i in form1:
if i[1] == c:
tention = 1
if sum1 == 1:
q = 5
a = 1
if iscrash(forms(0, [set_roboot1[0], set_roboot1[1] - size_roboot + q * size_roboot], size_roboot), form1)[
0] == 0:
a = 0
b = 1
if iscrash(forms(-1, [set_roboot1[0], set_roboot1[1] - 3 * size_roboot + q * size_roboot], size_roboot), form1)[
0] == 0:
b = 0
# 分数计算
sores[2] += q
sq = 0
for i in ff:
i[1] -= q * size
suiji = random.randint(0, 10)
for i in range(q):
for j in range(10):
if suiji == j:
continue
ff.append([j * size + origin[0], (19 - i) * size + origin[1], 0])
if q != 0:
sq += sore * q + sore * (q - 1)
if q == 4:
sq += 5 * sore
if q == 2 and ch1_roboot[5] == 9 and a == 0: # Tspin
sq += 5 * sore
sores[1] += 1
if q == 1 and ch1_roboot[5] == 9 and a == 0: # Tspin
sq += 3 * sore
sores[1] += 1
if q == 3 and (ch1_roboot[5] == 8 or ch1_roboot[5] == 10) and b == 0: # Tspin3
sq += 7 * size_roboot
sores[1] += 1
if q == 2 and (ch1_roboot[5] == 8 or ch1_roboot[5] == 10) and b == 0: # Tspin3
sq += 5 * sore
sores[1] += 1
if q == 5:
sq += sore
sores[0] += sq
# 速度计算
if sores[0] < 100:
leve = 1
if sores[0] >= 100 and sores[0] < 500:
leve = 0.8
if sores[0] >= 500 and sores[0] < 1000:
leve = 0.6
sore = 15
if sores[0] >= 1000 and sores[0] < 2000:
leve = 0.4
sore = 20
if sores[0] >= 2000 and sores[0] < 5000:
leve = 0.2
sore = 30
lock = 0.7
if sores[0] >= 5000:
leve = 0
sore = 50
lock = 0.8
# 经典类
class Classic:
p = 1
a = []
def __init__(self):
global sensitivity
sensitivity = 0.1
data_clear()
self.t_start = 0
self.t_end = 0
self.control = 1
def rank_list(self):
o = 1
while o == 1:
im_rank = pygame.image.load(path + "phto/rank.png")
im_rank = pygame.transform.rotozoom(im_rank, 0, multipl)
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((20, 20), (127, 70)):
o = 0
try:
with open("material/word/rank_list.csv", 'r', encoding="utf-8") as fr:
reader = csv.reader(fr)
c = 0
for i in reader:
c += 1
im_rank.blit(f.render(str(i[0]), True, word_color[0]),
(3 * size, 2 * size + 1.5 * c * word_size[0]))
if i[2] != "":
im_rank.blit(f.render(i[2], True, word_color[1]),
(3 * size + 3.5 * word_size[0], 2 * size + 1.5 * c * word_size[0]))
im_rank.blit(f.render(i[1], True, word_color[1]),
(width - 3 * word_size[0], 2 * size + 1.5 * c * word_size[0]))
else:
im_rank.blit(f.render("虚位以待", True, word_color[0]),
(3 * size + 3.5 * word_size[0], 2 * size + 1.5 * c * word_size[0]))
except:
with open("material/word/rank_list.csv", 'w', encoding="utf-8", newline="") as fr:
list = [["第一名", "虚位以待", ""],
["第二名", "虚位以待", ""],
["第三名", "虚位以待", ""],
["第四名", "虚位以待", ""],
["第五名", "虚位以待", ""],
["第六名", "虚位以待", ""],
["第七名", "虚位以待", ""],
["第八名", "虚位以待", ""],
["第九名", "虚位以待", ""],
["第十名", "虚位以待", ""]]
write = csv.writer(fr)
for i in list:
write.writerow(i)
screen1.blit(im_rank, c_dif)
pygame.display.flip()
def sore_mark(self):
r_list = []
try:
with open("material/word/rank_list.csv", "r", encoding="utf-8") as fw:
reader1 = csv.reader(fw)
c = 0
for i in reader1:
if i[2] != "":
if int(i[2]) > sores[0]:
r_list.append(i)
else:
r_list.append(i)
if c != 1:
r_list.insert(-1, [i[0], str(sores[1]), str(sores[0])])
c = 1
# r_list.append([i[0],i[1],i[2]])
else:
r_list.append(i)
if c != 1:
r_list.insert(-1, [i[0], str(sores[1]), str(sores[0])])
c = 1
if c == 1:
r_list.pop()
except:
with open("material/word/rank_list.csv", 'w', encoding="utf-8", newline="") as fr:
list = [["第一名", "虚位以待", ""],
["第二名", "虚位以待", ""],
["第三名", "虚位以待", ""],
["第四名", "虚位以待", ""],
["第五名", "虚位以待", ""],
["第六名", "虚位以待", ""],
["第七名", "虚位以待", ""],
["第八名", "虚位以待", ""],
["第九名", "虚位以待", ""],
["第十名", "虚位以待", ""]]
t = ''
for j in range(len(r_list)):
if r_list[j][0] == t:
for i in range(len(r_list) - j - 1):
r_list[j + i][0] = r_list[j + 1 + i][0]
break
t = r_list[j][0]
with open("material/word/rank_list.csv", "w", encoding="utf-8", newline="")as fw:
write = csv.writer(fw)
for i in r_list:
write.writerow(i)
# 屏幕更新函数
def update(self):
# 游戏框绘制
if self.p == 1:
self.p = 0
for i in range(3):
screen.blit(im, (0, 0))
sor11 = f1.render(str(3 - i), True, word_color[1])
screen.blit(sor11, (130 * multipl, 150 * multipl))
screen1.blit(screen, c_dif)
pygame.display.flip()
time.sleep(1)
screen.blit(im, (0, 0))
sor11 = f1.render("开始", True, word_color[1])
screen.blit(sor11, (80 * multipl, 150 * multipl))
screen1.blit(screen, c_dif)
pygame.display.flip()
time.sleep(1)
screen.blit(im, (0, 0))
# 判断游戏是否结束
if iscrash(forms(ch1[0], set), filled)[0] == 0 and forms(ch1[0], set)[0][1] <= origin[1]:
set[1] -= size
control[0] = 0
# 方块绘制
a = 19 * size - forms(ch1[0], set)[5][1] + origin[1]
for i in filled:
for k in range(4):
if i[0] == forms(ch1[0], set)[k][0]:
if a > i[1] - forms(ch1[0], set)[k][1] - size and i[1] - forms(ch1[0], set)[k][
1] - size >= 0:
a = i[1] - forms(ch1[0], set)[k][1] - size
for i in range(4): # 当前方块
d_color(forms(ch1[0], set)[6], face)
screen.blit(face, forms(ch1[0], set)[i])
# 方块预降位置
if c_set[0] == 1:
for i in range(4):
d_color(forms(ch1[0], set)[6], face1)
screen.blit(face1, forms(ch1[0], (set[0], set[1] + a))[i])
# 方块预览
for i in range(4):
d_color(forms(ch1[1], set)[6], face)
screen.blit(face, forms(ch1[1], (330 * width / Width + 2 * size, 120 * height / Height + 2 * size))[i])
for i in range(4):
d_color(forms(ch1[2], set)[6], face)
screen.blit(face, forms(ch1[2], (330 * width / Width + 2 * size, 120 * height / Height+ 6 * size))[i])
for i in range(4):
d_color(forms(ch1[3], set)[6], face)
screen.blit(face, forms(ch1[3], (330 * width / Width + 2 * size, 120 * height / Height + 10 * size))[i])
if ch1[4] != 0:
for i in range(4):
d_color(forms(ch1[4], set)[6], face)
screen.blit(face, forms(ch1[4], (330 * width / Width + 2 * size, 120 * height / Height + 14 * size))[i])
# 落地方块绘制
for i in filled:
d_color(i[2], face)
screen.blit(face, i[:2])
# 分数绘制
if sores[0] >= 10000:
sor = f.render("分数:" + str(round(sores[0] / 10000, 2)) + "w", True, word_color[2])
else:
sor = f.render("分数:" + str(int(sores[0])), True, word_color[2])
screen.blit(sor, (width / Width * 330, 50 * height / Height))
# 绘制游戏结束界面并判断游戏是否继续
if control[0] == 0:
self.o_update()
screen1.blit(screen, c_dif)
pygame.display.flip()
# 结束界面
def o_update(self):
im_over = pygame.image.load(path + "phto\\gameover.png")
im_over = pygame.transform.rotozoom(im_over, 0, multipl)
im_over.blit(f.render("得分:" + str(sores[0]), True, word_color[5]), (3 * size, 6 * size))
screen.blit(im_over, (size, 3 * size))
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((67, 413), (232, 458)):
self.p = 1
self.sore_mark()
data_clear()
control[0] = 1
start_update()
if isin((264, 411), (434, 458)):
self.p = 1
data_clear()
control[0] = 1
def p_operation(self):
self.p = 1
pause = 0
while pause == 0:
for e in pygame.event.get():
if e.type == pygame.QUIT:
isquit()
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_SPACE:
pause = 1
if e.type == pygame.MOUSEBUTTONDOWN:
if isin((159, 151), (320, 193)):
pause = 1
if isin((156, 211), (321, 246)):
self.sore_mark()
pause = 1
data_clear()
if isin((152, 246), (321, 306)):
pause = 1
set_update()
if isin((156, 325), (321, 365)):
isquit()
if isin((156, 377), (321, 4118)):
pause = 1
start_update1()
screen.blit(im_pause, (width / 10, height / Height * 80))
screen1.blit(screen, c_dif)
pygame.display.flip()
def roboot(self):
global pause, c_key, c_left, c_right, c_down, rob, a, sensitivity
sensitivity = 0
if c_isd[0] == 1:
c_isd[0] = 0
rob = Roboot()
a = rob.roboot(set, ch1)
ch1[0] = a[1]
c_right = 0
c_left = 0
c_down = 0
if set[0] != a[0][0]:
while set[0] > a[0][0]:
c_left = 1
break
while set[0] < a[0][0]:
c_right = 1
break
if set[1] < a[0][1] and set[0] == a[0][0]:
while set[1] < a[0][1]:
c_down = 1
break
def move(self):
global pause, c_key, c_left, c_right, c_down, rob, sensitivity,start_time,end_time
# 获取键盘事件
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
# 按键操作
if event.type == pygame.KEYDOWN:
if event.key == left:
start_time = time.time()
c_left = 1
elif event.key == right:
start_time = time.time()
c_right = 1
elif event.key == down:
start_time = time.time()
c_down = 1
elif event.key == pau:
self.p_operation()
elif event.key == spi_r:
spin(0)
isc_r()
iscreak1()
elif event.key == spi_l:
spin(1)
isc_l()
iscreak1()
elif event.key == change:
if n[0] == 0:
if ch1[4] == 0:
if ch1[0] == 19:
ch1[4] = 19
if ch1[0] >= 1 and ch1[0] <= 2:
ch1[4] = 2
if ch1[0] >= 3 and ch1[0] <= 4:
ch1[4] = 4
if ch1[0] >= 5 and ch1[0] <= 6:
ch1[4] = 6
if ch1[0] >= 7 and ch1[0] <= 10:
ch1[4] = 7
if ch1[0] >= 11 and ch1[0] <= 14:
ch1[4] = 14
if ch1[0] >= 15 and ch1[0] <= 18:
ch1[4] = 16
ch1[0] = ch1[1]
ch1[1] = ch1[2]
ch1[2] = ch1[3]
ch1[3] = c_list[random.randint(0, 6)]
set[0] = 4 * size + origin[0]
set[1] = origin[1] + 0
n[0] = 1
else:
v = ch1[0]
ch1[0] = ch1[4]
if v == 19:
ch1[4] = 19
if v >= 1 and v <= 2:
ch1[4] = 2
if v >= 3 and v <= 4:
ch1[4] = 4
if v >= 5 and v <= 6:
ch1[4] = 6
if v >= 7 and v <= 10:
ch1[4] = 7
if v >= 11 and v <= 14:
ch1[4] = 14
if v >= 15 and v <= 18:
ch1[4] = 16
set[0] = 4 * size + origin[0]
set[1] = origin[1] + 0
n[0] = 1
elif event.key == plunge:
a = 20 * size - forms(ch1[0], set)[5][1] + origin[1]
for i in filled:
for k in range(4):
if i[0] == forms(ch1[0], set)[k][0]:
if a > i[1] - forms(ch1[0], set)[k][1] and i[1] - forms(ch1[0], set)[k][
1] > 0:
a = i[1] - forms(ch1[0], set)[k][1]
set[1] += a
iscreak1()
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
c_left = 0
end_time = time.time()
if event.key == pygame.K_RIGHT:
c_right = 0
end_time = time.time()
if event.key == pygame.K_DOWN:
c_down = 0
end_time = time.time()
# 鼠标操作
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((470, 0), (500, 30)):
self.p_operation()
if not isin((0, 0), (500, 700)):
self.p_operation()
end_time=time.time()
if end_time-start_time>=0.2 and (c_left==1 or c_right==1 or c_down==1):
start_time=time.time()
sensitivity = 0.1
move1()
print(time.time())
else:
sensitivity = 0
move1()
iscreak1()
# 40行类
class Line40(Classic):
def __init__(self):
global sensitivity
data_clear()
self.p = 1
sensitivity = 0.08
self.t_start = 0
self.t_end = 0
self.control = 1
def update40(self):
# 游戏框绘制
if self.p == 1:
self.p = 0
tt = time.time()
for i in range(3):
screen.blit(im, (0, 0))
sor11 = f1.render(str(3 - i), True, word_color[1])
screen.blit(sor11, (130 * multipl, 150 * multipl))
screen1.blit(screen, c_dif)
pygame.display.flip()
time.sleep(1)
screen.blit(im, (0, 0))
sor11 = f1.render("开始", True, word_color[1])
screen.blit(sor11, (80 * multipl, 150 * multipl))
screen1.blit(screen, c_dif)
pygame.display.flip()
time.sleep(1)
self.t_start += time.time() - tt
screen.blit(im, (0, 0))
# 判断游戏是否结束
if sores[2] >= 40:
control[0] = 0
if iscrash(forms(ch1[0], set), filled)[0] == 0 and forms(ch1[0], set)[0][1] <= origin[1]:
set[1] -= size
control[0] = 0
# 方块绘制
a = 19 * size - forms(ch1[0], set)[5][1] + origin[1]
for i in filled:
for k in range(4):
if i[0] == forms(ch1[0], set)[k][0]:
if a > i[1] - forms(ch1[0], set)[k][1] - size and i[1] - forms(ch1[0], set)[k][
1] - size >= 0:
a = i[1] - forms(ch1[0], set)[k][1] - size
for i in range(4): # 当前方块
d_color(forms(ch1[0], set)[6], face)
screen.blit(face, forms(ch1[0], set)[i])
if c_set[0] == 1:
for i in range(4): # 方块预降位置
d_color(forms(ch1[0], set)[6], face1)
screen.blit(face1, forms(ch1[0], (set[0], set[1] + a))[i])
# 方块预览
for i in range(4):
d_color(forms(ch1[1], set)[6], face)
screen.blit(face, forms(ch1[1], (330 * width / Width + 2 * size, 120 * height / Height + 2 * size))[i])
for i in range(4):
d_color(forms(ch1[2], set)[6], face)
screen.blit(face, forms(ch1[2], (330 * width / Width + 2 * size, 120 * height / Height + 6 * size))[i])
for i in range(4):
d_color(forms(ch1[3], set)[6], face)
screen.blit(face, forms(ch1[3], (330 * width / Width + 2 * size, 120 * height / Height + 10 * size))[i])
if ch1[4] != 0:
for i in range(4):
d_color(forms(ch1[4], set)[6], face)
screen.blit(face, forms(ch1[4], (330 * width / Width + 2 * size, 120 * height / Height + 14 * size))[i])
# 落地方块绘制
for i in filled:
d_color(i[2], face)
screen.blit(face, i[:2])
# 分数绘制
if control[0] == 1:
self.t_end = time.time()
sores[3] = round(self.t_end - self.t_start, 2)
if sores[2] >= 40:
sores[2] = 40
sor = f.render("剩余行:" + str(40 - sores[2]), True, word_color[2])
sor1 = f.render("用时:" + str(sores[3]), True, word_color[2])
screen.blit(sor, (width / Width * 330, 50 * height / Height))
screen.blit(sor1, (width / Width * 330, 10 * height / Height))
# 绘制游戏结束界面并判断游戏是否继续
if control[0] == 0:
self.o_update40()
screen1.blit(screen, c_dif)
pygame.display.flip()
# 结束界面
def o_update40(self):
im_over = pygame.image.load(path + "phto\\gameover.png")
im_over = pygame.transform.rotozoom(im_over, 0, multipl)
if sores[2] < 40:
im_over.blit(f.render('挑战失败', True, word_color[5]), (3 * size, 4 * size))
else:
im_over.blit(f.render('挑战成功', True, word_color[5]), (3 * size, 4 * size))
im_over.blit(f.render(str(round(self.t_end - self.t_start, 2)) + '秒', True, word_color[5]),
(3 * size, 6 * size))
screen.blit(im_over, (size, 3 * size))
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((67, 413), (232, 458)):
if sores[2] >= 40:
self.p = 0
self.sore_mark40()
data_clear()
control[0] = 1
start_update()
if isin((264, 411), (434, 458)):
self.p = 0
if sores[2] >= 40:
self.sore_mark40()
self.t_start = time.time()
data_clear()
control[0] = 1
def p_operation40(self):
t1 = time.time()
self.p = 0
pause = 0
isback = 0
while pause == 0:
for e in pygame.event.get():
if e.type == pygame.QUIT:
isquit()
if e.type == pygame.MOUSEBUTTONDOWN:
if isin((159, 151), (320, 193)):
pause = 1
if isin((156, 211), (321, 246)):
self.t_start = time.time()
isback = 1
pause = 1
data_clear()
if isin((152, 246), (321, 306)):
pause = 1
set_update()
if isin((156, 325), (321, 365)):
isquit()
if isin((156, 377), (321, 4118)):
pause = 1
start_update1()
screen.blit(im_pause, (width / 10, height / Height * 80))
screen1.blit(screen, c_dif)
pygame.display.flip()
if isback == 0:
self.t_start += time.time() - t1
def rank_list40(self):
o = 1
while o == 1:
im_rank = pygame.image.load(path + "phto/rank_40.png")
im_rank = pygame.transform.rotozoom(im_rank, 0, multipl)
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((20, 20), (127, 70)):
o = 0
try:
with open("material/word/rank_list40.csv", 'r', encoding="utf-8") as fr:
reader = csv.reader(fr)
c = 0
for i in reader:
c += 1
im_rank.blit(f.render(str(i[0]), True, word_color[0]),
(3 * size, 2 * size + 1.5 * c * word_size[0]))
if i[2] != "":
# im_rank.blit(f.render(i[2], True, word_color[1]),
# (width - 3 * word_size, 2 * size + 1.5 * c * word_size))
im_rank.blit(f.render(i[1], True, word_color[1]),
(3 * size + 3.5 * word_size[0], 2 * size + 1.5 * c * word_size[0]))
else:
im_rank.blit(f.render("虚位以待", True, word_color[0]),
(3 * size + 3.5 * word_size[0], 2 * size + 1.5 * c * word_size[0]))
except:
with open("material/word/rank_list40.csv", 'w', encoding="utf-8", newline="") as fr:
list = [["第一名", "虚位以待", ""],
["第二名", "虚位以待", ""],
["第三名", "虚位以待", ""],
["第四名", "虚位以待", ""],
["第五名", "虚位以待", ""],
["第六名", "虚位以待", ""],
["第七名", "虚位以待", ""],
["第八名", "虚位以待", ""],
["第九名", "虚位以待", ""],
["第十名", "虚位以待", ""]]
write = csv.writer(fr)
for i in list:
write.writerow(i)
screen1.blit(im_rank, c_dif)
pygame.display.flip()
def sore_mark40(self):
r_list = []
with open("material/word/rank_list40.csv", "r", encoding="utf-8") as fw:
reader1 = csv.reader(fw)
c = 0
for i in reader1:
if i[2] != "":
if float(i[1]) < sores[3]:
r_list.append(i)
else:
r_list.append(i)
if c != 1:
r_list.insert(-1, [i[0], sores[3], str(sores[0])])
c = 1
# r_list.append([i[0],i[1],i[2]])
else:
r_list.append(i)
if c != 1:
r_list.insert(-1, [i[0], sores[3], str(sores[0])])
c = 1
if c == 1:
r_list.pop()
t = ''
for j in range(len(r_list)):
if r_list[j][0] == t:
for i in range(len(r_list) - j - 1):
r_list[j + i][0] = r_list[j + 1 + i][0]
break
t = r_list[j][0]
with open("material/word/rank_list40.csv", "w", encoding="utf-8", newline="")as fw:
write = csv.writer(fw)
for i in r_list:
write.writerow(i)
def move40(self):
# 获取键盘事件
a = 0
rr = RobootRun()
rr.roboot(filled)
global pause, c_key, c_left, c_right, c_down
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
# 按键操作
# pygame.key.set_repeat(c_key, 0)
if event.type == pygame.KEYDOWN:
if event.key == left:
c_left = 1
elif event.key == right:
c_right = 1
elif event.key == down:
c_down = 1
elif event.key == pau:
self.p_operation()
elif event.key == spi_r:
spin(0)
isc_r()
iscreak1()
elif event.key == spi_l:
spin(1)
isc_l()
iscreak1()
elif event.key == change:
if n[0] == 0:
if ch1[4] == 0:
if ch1[0] == 19:
ch1[4] = 19
if ch1[0] >= 1 and ch1[0] <= 2:
ch1[4] = 2
if ch1[0] >= 3 and ch1[0] <= 4:
ch1[4] = 4
if ch1[0] >= 5 and ch1[0] <= 6:
ch1[4] = 6
if ch1[0] >= 7 and ch1[0] <= 10:
ch1[4] = 7
if ch1[0] >= 11 and ch1[0] <= 14:
ch1[4] = 14
if ch1[0] >= 15 and ch1[0] <= 18:
ch1[4] = 16
ch1[0] = ch1[1]
ch1[1] = ch1[2]
ch1[2] = ch1[3]
ch1[3] = c_list[random.randint(0, 6)]
set[0] = 4 * size + origin[0]
set[1] = origin[1] + 0
n[0] = 1
else:
v = ch1[0]
ch1[0] = ch1[4]
if v == 19:
ch1[4] = 19
if v >= 1 and v <= 2:
ch1[4] = 2
if v >= 3 and v <= 4:
ch1[4] = 4
if v >= 5 and v <= 6:
ch1[4] = 6
if v >= 7 and v <= 10:
ch1[4] = 7
if v >= 11 and v <= 14:
ch1[4] = 14
if v >= 15 and v <= 18:
ch1[4] = 16
set[0] = 4 * size + origin[0]
set[1] = origin[1] + 0
n[0] = 1
elif event.key == plunge:
a = 20 * size - forms(ch1[0], set)[5][1] + origin[1]
for i in filled:
for k in range(4):
if i[j][0] == forms(ch1[0], set)[k][0]:
if a > i[1] - forms(ch1[0], set)[k][1] and i[1] - forms(ch1[0], set)[k][
1] > 0:
a = i[1] - forms(ch1[0], set)[k][1]
set[1] += a
iscreak1()
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
c_left = 0
if event.key == pygame.K_RIGHT:
c_right = 0
if event.key == pygame.K_DOWN:
c_down = 0
# 鼠标操作
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((470, 0), (500, 30)):
self.p_operation40()
move1()
iscreak1()
# 120秒积分挑战
class Integral12(Classic):
global sensitivity
def __init__(self):
data_clear()
sensitivity = 0.08
self.t_start = 0
self.t_end = 0
self.control = 1
def update(self):
# 游戏框绘制
if self.p == 1:
tt = time.time()
self.p = 0
for i in range(3):
screen.blit(im, (0, 0))
sor11 = f1.render(str(3 - i), True, word_color[1])
screen.blit(sor11, (130 * multipl, 150 * multipl))
screen1.blit(screen, c_dif)
pygame.display.flip()
time.sleep(1)
screen.blit(im, (0, 0))
sor11 = f1.render("开始", True, word_color[1])
screen.blit(sor11, (80 * multipl, 150 * multipl))
screen1.blit(screen, c_dif)
pygame.display.flip()
time.sleep(1)
self.t_start += time.time() - tt
screen.blit(im, (0, 0))
# 判断游戏是否结束
if sores[3] >= 120:
control[0] = 0
if iscrash(forms(ch1[0], set), filled)[0] == 0 and forms(ch1[0], set)[0][1] <= origin[1]:
set[1] -= size
control[0] = 0
# 方块绘制
a = 19 * size - forms(ch1[0], set)[5][1] + origin[1]
for i in filled:
for k in range(4):
if i[0] == forms(ch1[0], set)[k][0]:
if a > i[1] - forms(ch1[0], set)[k][1] - size and i[1] - forms(ch1[0], set)[k][
1] - size >= 0:
a = i[1] - forms(ch1[0], set)[k][1] - size
for i in range(4): # 当前方块
d_color(forms(ch1[0], set)[6], face)
screen.blit(face, forms(ch1[0], set)[i])
if c_set[0] == 1:
for i in range(4): # 方块预降位置
d_color(forms(ch1[0], set)[6], face1)
screen.blit(face1, forms(ch1[0], (set[0], set[1] + a))[i])
# 方块预览
for i in range(4):
d_color(forms(ch1[1], set)[6], face)
screen.blit(face, forms(ch1[1], (330 * width / Width + 2 * size, 120 * height / Height + 2 * size))[i])
for i in range(4):
d_color(forms(ch1[2], set)[6], face)
screen.blit(face, forms(ch1[2], (330 * width / Width + 2 * size, 120 * height / Height + 6 * size))[i])
for i in range(4):
d_color(forms(ch1[3], set)[6], face)
screen.blit(face, forms(ch1[3], (330 * width / Width + 2 * size, 120 * height / Height + 10 * size))[i])
if ch1[4] != 0:
for i in range(4):
d_color(forms(ch1[4], set)[6], face)
screen.blit(face, forms(ch1[4], (330 * width / Width + 2 * size, 120 * height / Height + 14 * size))[i])
# 落地方块绘制
for i in filled:
d_color(i[2], face)
screen.blit(face, i[:2])
# 分数绘制
if control[0] == 1:
self.t_end = time.time()
sores[3] = round(self.t_end - self.t_start, 2)
if sores[2] >= 40:
sores[2] = 40
sor = f.render("分数:" + str(sores[0]), True, word_color[2])
sor1 = f.render("时间:" + str(round(120 - sores[3], 2)), True, word_color[2])
screen.blit(sor, (width / Width * 330, 50 * height / Height))
screen.blit(sor1, (width / Width * 330, 10 * height / Height))
# 绘制游戏结束界面并判断游戏是否继续
if control[0] == 0:
self.o_update()
screen1.blit(screen, c_dif)
pygame.display.flip()
# 结束界面
def o_update(self):
im_over = pygame.image.load(path + "phto\\gameover.png")
im_over = pygame.transform.rotozoom(im_over, 0, multipl)
if sores[3] < 120:
im_over.blit(f.render('挑战失败', True, word_color[5]), (3 * size, 4 * size))
else:
im_over.blit(f.render('挑战成功', True, word_color[5]), (3 * size, 4 * size))
im_over.blit(f.render("得分:" + str(sores[0]), True, word_color[5]),
(3 * size, 6 * size))
screen.blit(im_over, (size, 3 * size))
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((67, 413), (232, 458)):
if sores[3] >= 120:
self.p = 1
self.sore_mark()
self.t_start = time.time()
data_clear()
control[0] = 1
start_update()
if isin((264, 411), (434, 458)):
if sores[3] >= 120:
self.p = 1
self.sore_mark()
self.t_start = time.time()
data_clear()
control[0] = 1
def p_operation(self):
t1 = time.time()
self.p = 1
pause = 0
isback = 0
while pause == 0:
for e in pygame.event.get():
if e.type == pygame.QUIT:
isquit()
if e.type == pygame.MOUSEBUTTONDOWN:
if isin((159, 151), (320, 193)):
pause = 1
if isin((156, 211), (321, 246)):
self.t_start = time.time()
isback = 1
pause = 1
data_clear()
if isin((152, 246), (321, 306)):
pause = 1
set_update()
if isin((156, 325), (321, 365)):
isquit()
if isin((156, 377), (321, 4118)):
pause = 1
start_update1()
screen.blit(im_pause, (width / 10, height / Height * 80))
screen1.blit(screen, c_dif)
pygame.display.flip()
if isback == 0:
self.t_start += time.time() - t1
def rank_list(self):
o = 1
while o == 1:
im_rank = pygame.image.load(path + "phto/rank_12.png")
im_rank = pygame.transform.rotozoom(im_rank, 0, multipl)
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((20, 20), (127, 70)):
o = 0
try:
with open("material/word/rank_list12.csv", 'r', encoding="utf-8") as fr:
reader = csv.reader(fr)
c = 0
for i in reader:
c += 1
im_rank.blit(f.render(str(i[0]), True, word_color[0]),
(3 * size, 2 * size + 1.5 * c * word_size[0]))
if i[2] != "":
im_rank.blit(f.render(i[2], True, word_color[1]),
(3 * size + 3.5 * word_size[0], 2 * size + 1.5 * c * word_size[0]))
im_rank.blit(f.render(i[1], True, word_color[1]),
(width - 3 * word_size[0], 2 * size + 1.5 * c * word_size[0]))
else:
im_rank.blit(f.render("虚位以待", True, word_color[0]),
(3 * size + 3.5 * word_size[0], 2 * size + 1.5 * c * word_size[0]))
except:
with open("material/word/rank_list12.csv", 'w', encoding="utf-8", newline="") as fr:
list = [["第一名", "虚位以待", ""],
["第二名", "虚位以待", ""],
["第三名", "虚位以待", ""],
["第四名", "虚位以待", ""],
["第五名", "虚位以待", ""],
["第六名", "虚位以待", ""],
["第七名", "虚位以待", ""],
["第八名", "虚位以待", ""],
["第九名", "虚位以待", ""],
["第十名", "虚位以待", ""]]
write = csv.writer(fr)
for i in list:
write.writerow(i)
screen1.blit(im_rank, c_dif)
pygame.display.flip()
def sore_mark(self):
r_list = []
with open("material/word/rank_list12.csv", "r", encoding="utf-8") as fw:
reader1 = csv.reader(fw)
c = 0
for i in reader1:
if i[2] != "":
if int(i[2]) > sores[0]:
r_list.append(i)
else:
r_list.append(i)
if c != 1:
r_list.insert(-1, [i[0], str(sores[1]), str(sores[0])])
c = 1
# r_list.append([i[0],i[1],i[2]])
else:
r_list.append(i)
if c != 1:
r_list.insert(-1, [i[0], str(sores[1]), str(sores[0])])
c = 1
if c == 1:
r_list.pop()
t = ''
for j in range(len(r_list)):
if r_list[j][0] == t:
for i in range(len(r_list) - j - 1):
r_list[j + i][0] = r_list[j + 1 + i][0]
break
t = r_list[j][0]
with open("material/word/rank_list12.csv", "w", encoding="utf-8", newline="")as fw:
write = csv.writer(fw)
for i in r_list:
write.writerow(i)
def move(self):
# 获取键盘事件
global pause, c_key, c_left, c_right, c_down
for event in pygame.event.get():
if event.type == pygame.QUIT:
isquit()
# 按键操作
# pygame.key.set_repeat(c_key, 0)
if event.type == pygame.KEYDOWN:
if event.key == left:
c_left = 1
elif event.key == right:
c_right = 1
elif event.key == down:
c_down = 1
elif event.key == pau:
self.p_operation()
elif event.key == spi_r:
spin(0)
isc_r()
iscreak1()
elif event.key == spi_l:
spin(1)
isc_l()
iscreak1()
elif event.key == change:
if n[0] == 0:
if ch1[4] == 0:
if ch1[0] == 19:
ch1[4] = 19
if ch1[0] >= 1 and ch1[0] <= 2:
ch1[4] = 2
if ch1[0] >= 3 and ch1[0] <= 4:
ch1[4] = 4
if ch1[0] >= 5 and ch1[0] <= 6:
ch1[4] = 6
if ch1[0] >= 7 and ch1[0] <= 10:
ch1[4] = 7
if ch1[0] >= 11 and ch1[0] <= 14:
ch1[4] = 14
if ch1[0] >= 15 and ch1[0] <= 18:
ch1[4] = 16
ch1[0] = ch1[1]
ch1[1] = ch1[2]
ch1[2] = ch1[3]
ch1[3] = c_list[random.randint(0, 6)]
set[0] = 4 * size + origin[0]
set[1] = origin[1] + 0
n[0] = 1
else:
v = ch1[0]
ch1[0] = ch1[4]
if v == 19:
ch1[4] = 19
if v >= 1 and v <= 2:
ch1[4] = 2
if v >= 3 and v <= 4:
ch1[4] = 4
if v >= 5 and v <= 6:
ch1[4] = 6
if v >= 7 and v <= 10:
ch1[4] = 7
if v >= 11 and v <= 14:
ch1[4] = 14
if v >= 15 and v <= 18:
ch1[4] = 16
set[0] = 4 * size + origin[0]
set[1] = origin[1] + 0
n[0] = 1
elif event.key == plunge:
a = 20 * size - forms(ch1[0], set)[5][1] + origin[1]
for i in filled:
for k in range(4):
if i[0] == forms(ch1[0], set)[k][0]:
if a > i[1] - forms(ch1[0], set)[k][1] and i[1] - forms(ch1[0], set)[k][
1] > 0:
a = i[1] - forms(ch1[0], set)[k][1]
set[1] += a
iscreak1()
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
c_left = 0
if event.key == pygame.K_RIGHT:
c_right = 0
if event.key == pygame.K_DOWN:
c_down = 0
# 鼠标操作
if event.type == pygame.MOUSEBUTTONDOWN:
if isin((470, 0), (500, 30)):
self.p_operation()
move1()
iscreak1()
if __name__=='__main__':
main()
需要的配置文件放到网盘了需要的可以自取,有安装包可以体验效果。链接:链接:https://pan.baidu.com/s/19SgymQgH7gMHn1tTkcQjBw?pwd=ylzh
提取码:ylzh