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一下玩不出來呢,但是我覺得噱頭無信)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章