python+pygame Hopscotch小游戏

解密小游戏Hopscotch

偶然看到了一个小游戏【Hopscotch】,和跳房子的规则有点类似,这里放一个视频,(如果你不想看这个视频,我下面会简单介绍一下玩法,但建议看一下,我说的可能不清楚),我是看到这个了然后像写一个这样的简易小游戏,一方面练习python,另一方面‘0’成本玩游戏。

游戏规则

在这里插入图片描述
第一步:选择一个位置拿掉(这里皮卡丘将会变成喷火龙)
在这里插入图片描述
第二步:选择两个位置,这两个位置应该满足第一个位置是皮卡丘,第二个位置是喷火龙,他俩之间需要用皮卡丘隔开,效果如下:
在这里插入图片描述
第三步:反复操作,最后只剩下一个皮卡丘则胜利,否则失败。

思路说明

1、首先我采用59的矩阵来表示三角形的放置如图。
在这里插入图片描述
2、初始化,即第一步操作:去除一个点,使1变为0。
3、反复跳跃,使1变为0。这里主要在判断是否可以跳跃。我用的方法是,选择的第一个点值为1,第二个点值为0,两点坐标对应均值作为坐标的点的值为1。(这里可能有点绕,不太懂的可以看下面的代码)
4、判断是否胜利。方法为算矩阵值之和为666
30+1。
5、编写pygame的界面。(要将鼠标事件与对应跳跃相关联)

关键点解析

因为我在初步接触pygame,所以这里重点说一下pygame的应用。
pygame.init()初始化模块
pygame.image.load('pikaqiu.bmp')载入图片
screen.blit(icon1, [x,y])将图片icon放在[x,y]绝对坐标处
pygame.draw.rect(screen,[255,255,255],[x,y],0)在screen表面[x,y]处画一个宽度为1,颜色为黑色的矩形边框
size = width, height = 900, 650 screen = pygame.display.set_mode(size)建立screen的大小
pygame.display.set_caption('title')标题
screen.fill((255,255,255))背景颜色
pygame.mixer.music.load('River Fflows In You.wav')载入音乐
pygame.mixer.music.play()播放音乐
map_font = pygame.font.Font('msyh.ttc', 20)载入字体和字号
font_surf = map_font.render('祝您游戏愉快!', True, (0, 0, 0)) font_rect = font_surf.get_rect()编辑文本,建立一个对象
font_rect.center = (100, 25)将文本居中放在(100,25)绝对坐标处
screen.blit(font_surf, font_rect)显示文本
pygame.display.update()更新屏幕
在这里插入图片描述
进入事件队列,循环判断事件发生,并产生响应
pygame.event.pump() — 让 Pygame 内部自动处理事件
pygame.event.get() — 从队列中获取事件
pygame.event.poll() — 从队列中获取一个事件
pygame.event.wait() — 等待并从队列中获取一个事件
pygame.event.peek() — 检测某类型事件是否在队列中
pygame.event.clear() — 从队列中删除所有的事件
pygame.event.event_name() — 通过 id 获得该事件的字符串名字
pygame.event.set_blocked() — 控制哪些事件禁止进入队列
pygame.event.set_allowed() — 控制哪些事件允许进入队列
pygame.event.get_blocked() — 检测某一类型的事件是否被禁止进入队列
pygame.event.set_grab() — 控制输入设备与其他应用程序的共享
pygame.event.get_grab() — 检测程序是否共享输入设备
pygame.event.post() — 放置一个新的事件到队列中
pygame.event.Event() — 创建一个新的事件对象
pygame.event.EventType — 代表 SDL 事件的 Pygame 对象
事件类型摘自:https://blog.csdn.net/qq_41556318/article/details/86303039

代码回放

import pygame
import sys
#wx模块用于在选择错误是发出警告
import wx
import time

#list_是45个点的在屏幕中的位置坐标
#list_2是对应点的位置坐标
list_2 = [(1,5),(2,4),(2,6),(3,3),(3,5),(3,7),(4,2),(4,4),(4,6),(4,8),(5,1),(5,3),(5,5),(5,7),(5,9)]
list_ = [[405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530], [405, 30], [305, 155], [505, 155], [205, 280], [405, 280], [605, 280], [105, 405], [305, 405], [505, 405], [705, 405], [5, 530], [205, 530], [405, 530], [605, 530], [805, 530]]

#初始化5*9的矩阵来表示
def NumberArray():
    global record1,res
    record1 = np.array([[666, 666, 666, 666, 1, 666, 666, 666, 666],
                        [666, 666, 666, 1, 666, 1, 666, 666, 666],
                        [666, 666, 1, 666, 1, 666, 1, 666, 666],
                        [666, 1, 666, 1, 666, 1, 666, 1, 666],
                        [1, 666, 1, 666, 1, 666, 1, 666, 1]])
    res = []

#初始化
def initialize():
     record1[location_x-1,location_y-1] = 0
#是否可以跳跃的判断
def Doing():
    res.append([(location_x1 - 1, location_y1 - 1), (location_x2 - 1, location_y2 - 1)])
    record1[(location_x1 + location_x2 - 2) // 2, (location_y1 + location_y2 - 2) // 2] = 0
    record1[location_x1-1, location_y1-1] = 0
    record1[location_x2-1, location_y2-1] = 1
    
#将鼠标位置与图片位置坐标一一对应,与矩阵对接
def is_move(x,y):
    if x > 400 and x < 490 and y > 0 and y < 120:
        time_pic = 1
    elif x > 300 and x < 390 and y > 130 and y < 250:
        time_pic = 2
    elif x > 500 and x < 590 and y > 130 and y < 250:
        time_pic = 3
    elif x > 200 and x < 290 and y > 260 and y < 380:
        time_pic = 4
    elif x > 400 and x < 490 and y > 260 and y < 380:
        time_pic = 5
    elif x > 600 and x < 690 and y > 260 and y < 380:
        time_pic = 6
    elif x > 100 and x < 190 and y > 390 and y < 510:
        time_pic = 7
    elif x > 300 and x < 390 and y > 390 and y < 510:
        time_pic = 8
    elif x > 500 and x < 590 and y > 390 and y < 510:
        time_pic = 9
    elif x > 700 and x < 790 and y > 390 and y < 510:
        time_pic = 10
    elif x > 0 and x < 90 and y > 520 and y < 640:
        time_pic = 11
    elif x > 200 and x < 290 and y > 520 and y < 640:
        time_pic = 12
    elif x > 400 and x < 490 and y > 520 and y < 640:
        time_pic = 13
    elif x > 600 and x < 690 and y > 520 and y < 640:
        time_pic = 14
    elif x > 800 and x < 890 and y > 520 and y < 640:
        time_pic = 15
    else:
        time_pic = 999
    return time_pic

#将图片按矩阵中的值显示出来
def initialize_config():
    for i in range(5):
        for j in range(9):
            if record1[i][j] == 1:
                pygame.draw.rect(screen,[255,255,255],[j*(10+90)+5,i*(120+5)+30,90,120],0)
                screen.blit(icon1, [j*(10+90)+5,i*(120+5)+30])
            elif record1[i][j] == 0:
                pygame.draw.rect(screen, [255, 255, 255], [j * (10 + 90)+5, i * (120 + 5)+30, 90, 120], 0)
                screen.blit(icon2, [j*(10+90)+5,i*(120+5)+30])

#pygame的界面设计
def show_config():
    global screen,location_x,location_y,location_x1,location_y1,location_x2,location_y2,icon1,icon2
    app = wx.App()
    t = 0
    book = 0
    pygame.init()
    icon1 = pygame.image.load('pikaqiu.bmp')
    icon2 = pygame.image.load('penhuolong.bmp')
    size = width, height = 900, 650
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption('Puzzle')
    screen.fill((255,255,255))
    pygame.mixer.music.load('River Fflows In You.wav')
    pygame.mixer.music.play()

    map_font = pygame.font.Font('msyh.ttc', 20)
    font_surf = map_font.render('祝您游戏愉快!', True, (0, 0, 0))
    font_rect = font_surf.get_rect()
    font_rect.center = (100, 25)
    screen.blit(font_surf, font_rect)
    map_font2 = pygame.font.Font('msyh.ttc', 20)
    font_surf2 = map_font2.render('制作人:白云苍狗', True, (0, 0, 0))
    font_rect2 = font_surf2.get_rect()
    font_rect2.center = (100, 60)
    screen.blit(font_surf2, font_rect2)
  	
  	#进入事件队列循环
    while True:
        initialize_config()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
          	#初始化在屏幕上的显示
            if book == 0 and t == 0 and event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:#这里判断鼠标左键按下
                x, y = event.pos
                if is_move(x,y) != 999:#鼠标点击在图片上
                    n = is_move(x, y) - 1
                    location_x, location_y = list_2[n]
                    if record1[location_x-1][location_y-1] == 1:#该点可以移动
                        initialize()
                        book = 1
                        t = 1
                        continue
                    else:
                        wx.MessageBox("您的选择不合理,请重新选择",'warning',wx.OK|wx.ICON_WARNING)

            if t == 1 and event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:
                x,y = event.pos
                if is_move(x,y) != 999:
                    n1 = is_move(x, y) - 1
                    location_x1,location_y1 = list_2[n1]
                    pygame.draw.rect(screen, (255,0,0), (list_[n1][0],list_[n1][1],90, 120), 1)
                    t = 2
                    continue
            if t == 2 and event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:
                x, y = event.pos
                if is_move(x,y) != 999:
                    n2 = is_move(x, y) - 1
                    location_x2, location_y2 = list_2[n2]
                    if record1[location_x1-1][location_y1-1] == 1 and record1[location_x2-1][location_y2-1] == 0 and (location_x1 + location_y1) % 2 == 0 and (location_x2 + location_y2) % 2 == 0 and abs(location_x1-location_x2) <=2 and record1[(location_x1 + location_x2 - 2) // 2, (location_y1 + location_y2 - 2) // 2] == 1:
                        pygame.draw.rect(screen, (255,0,0), (list_[n2][0],list_[n2][1],90, 120), 1)
                        t = 3
                        continue
                    else:#如果选择有误,则返回第一个点重新选择
                        pygame.draw.rect(screen, [255, 255, 255], [list_[n1][0], list_[n1][1], 90, 120], 0)
                        screen.blit(icon1, [list_[n1][0], list_[n1][1]])
                        t = 1
                        wx.MessageBox("您的选择不合理,请重新选择", 'warning', wx.OK | wx.ICON_WARNING)

            if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[2]:#这里判断鼠标右键按下,将取消选中
                t = 1
                try:
                    pygame.draw.rect(screen, [255, 255, 255], [list_[n1][0],list_[n1][1], 90, 120], 0)
                    screen.blit(icon1, [list_[n1][0],list_[n1][1]])
                except:
                    pass
            if t == 3:#如果选择正确,将进行跳跃动作,并使图片改变
                pygame.draw.rect(screen, [255, 255, 255], [list_[n1][0], list_[n1][1], 90, 120], 0)
                screen.blit(icon1, [list_[n1][0], list_[n1][1]])
                pygame.draw.rect(screen, [255, 255, 255], [list_[n2][0], list_[n2][1], 90, 120], 0)
                screen.blit(icon2, [list_[n2][0], list_[n2][1]])
                Doing()
                initialize_config()
                t = 1
        pygame.display.update()

NumberArray()
show_config()`


问题总结

1、在选中错误后出现的警告会被屏幕覆盖,需要缩小确定,比较麻烦。
2、图片有白色边框,无法改变屏幕背景(否则会出现白色边框,十分难看)
3、界面不太友好,不易进行各种设置选择等操作

有想要玩的朋友,可以尝试一下哦。(据说这个游戏智商120一下玩不出来呢,但是我觉得噱头无信)

猜你喜欢

转载自blog.csdn.net/m0_47114189/article/details/106627401