唉,怎么说,感觉只有上班的时候摸鱼玩游戏才是最爽的
等于带薪摸鱼,现在不是有点流行说什么 带薪…带薪** 干嘛的
今天也是有点无聊,就想起之前搞了个拼图的小游戏,可以自己更改照片的 嘿嘿
这不刚玩了一局,就来分享给你们了
这个你们可以自己准备,也可以找我拿哈
源码.点击领取即可
import os
import sys
import random
import pygame
from pygame.locals import *
BACKGROUNDCOLOR = (255, 255, 255)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)
FPS = 40
NUMRANDOM = 100
def Stop():pygame.quit()sys.exit()
python学习交流Q群:770699889 ### 源码领取
def isOver(board, size):try:num_cells = size * sizeexcept:num_cells = size[0] * size[1]for i in range(num_cells-1):if board[i] != i:return Falsereturn True
def moveR(board, blank_cell_idx, num_cols):if blank_cell_idx % num_cols == 0:return blank_cell_idxboard[blank_cell_idx-1], board[blank_cell_idx] = board[blank_cell_idx], board[blank_cell_idx-1]return blank_cell_idx-1
def moveL(board, blank_cell_idx, num_cols):if (blank_cell_idx+1) % num_cols == 0:return blank_cell_idxboard[blank_cell_idx+1], board[blank_cell_idx] = board[blank_cell_idx], board[blank_cell_idx+1]return blank_cell_idx+1
def moveD(board, blank_cell_idx, num_cols):if blank_cell_idx < num_cols:return blank_cell_idxboard[blank_cell_idx-num_cols], board[blank_cell_idx] = board[blank_cell_idx], board[blank_cell_idx-num_cols]return blank_cell_idx-num_cols
def moveU(board, blank_cell_idx, num_rows, num_cols):if blank_cell_idx >= (num_rows-1) * num_cols:return blank_cell_idxboard[blank_cell_idx+num_cols], board[blank_cell_idx] = board[blank_cell_idx], board[blank_cell_idx+num_cols]return blank_cell_idx+num_cols
python学习交流Q群:770699889 ### 源码领取
def CreateBoard(num_rows, num_cols, num_cells):board = []for i in range(num_cells):board.append(i)# 去掉右下角那块blank_cell_idx = num_cells - 1board[blank_cell_idx] = -1for i in range(NUMRANDOM):# 0: left, 1: right, 2: up, 3: downdirection = random.randint(0, 3)if direction == 0:blank_cell_idx = moveL(board, blank_cell_idx, num_cols)elif direction == 1:blank_cell_idx = moveR(board, blank_cell_idx, num_cols)elif direction == 2:blank_cell_idx = moveU(board, blank_cell_idx, num_rows, num_cols)elif direction == 3:blank_cell_idx = moveD(board, blank_cell_idx, num_cols)return board, blank_cell_idx
def GetImagePath(filepath):imgs = os.listdir(filepath)if len(imgs) == 0:raise ValueError('No pictures in <%s>...' % filepath)return os.path.join(filepath, random.choice(imgs))
源码.点击领取即可
def ShowEndInterface(screen, width, height):screen.fill(BACKGROUNDCOLOR)font = pygame.font.Font('font/simkai.ttf', width // 8)title = font.render('Finished!', True, (233, 150, 122))rect = title.get_rect()rect.midtop = (width/2, height/2.5)screen.blit(title, rect)pygame.display.update()pygame.time.wait(500)while True:for event in pygame.event.get():if event.type == QUIT:Stop()elif event.type == KEYDOWN:if event.key == K_ESCAPE:Stop()
今天的分享到这里就结束了
给大家推荐一些Python视频教程,希望对大家有所帮助:
Python零基础教学合集
对文章有问题的,或者有其他关于python的问题,可以在评论区留言或者私信我哦
觉得我分享的文章不错的话,可以关注一下我,或者给文章点赞(/≧▽≦)/