Introduction:
If you’ve ever played with a jigsaw puzzle, you know that even if there are more than 1,000 pieces of the puzzle, each piece has its own position.
But when you put each piece of the puzzle together,To fit neatly into its place.It’s hard to forget the sense of satisfaction and accomplishment once you’ve tried it.
Jigsaw puzzle is a game with almost no threshold. It just focuses on and quietly completes a simple thing, and slowly restores the scattered and disorderly fragments into a complete small world.
It allows you to concentrate and enjoy a few hours of peace without distractions.
This time, our store has arranged a new oneHere’s a puzzle piece for you.Difficulty from high to low, 3*3 pieces, 4*4 pieces, 5*5 pieces of the puzzle.
The body of the
Update today – learned an article by a big man, sorted it out and then made a jigsaw puzzle of school flowers and grass by myself!
This jigsaw puzzle game – from simple to difficult, if you have crossed, and there is a love of people, then brave to vindicate ~ let him, she know your heart!
Start –
Let’s show the effect first:
Proud ~ ha ha ha ha have finished ha! I this technique is still good, when people this is the simplest 3*3 mode, the back of the more difficult mode to everyone!
The game steps are as follows:
(1) First install the corresponding environment.
Python, PyCharm, PyGame modules.
(2) Configuration file.
SCREENSIZE = (640, 640) PICTURE_ROOT_DIR = os.path.join(os.getcwd(), "FONTPATH = os.path.join(os.getcwd(), BACKGROUNDCOLOR = (255, 255, 255) RED = (255, 0, 0) BLUE = (0, 0, 0) 255) BLACK = (0, 0, 0) "FPS" "FPS" "NUMRANDOM = 100Copy the code
(3) The space moves up and down.
Def moveR(board, blank_cell_idx, num_cols): if blank_cell_idx % num_cols == 0: return blank_cell_idx board[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_idx board[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_idx board[blank_cell_idx-num_cols], board[blank_cell_idx] = board[blank_cell_idx], Blank_cell_idx-num_cols [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_idx board[blank_cell_idx+num_cols], board[blank_cell_idx] = board[blank_cell_idx], board[blank_cell_idx+num_cols] return blank_cell_idx + num_colsCopy the code
(4) Game interface.
def ShowStartInterface(screen, width, height): screen.fill(cfg.BACKGROUNDCOLOR) tfont = pygame.font.Font(cfg.FONTPATH, Font(CFG.FONTPATH, width//20) title = tfont. Render (' school flower ', True, Cfg. RED) content1 = cfont. Render ('H -- hard, M -- medium, L -- easy ', True, cfg.BLUE) Content2 = cfont. Render ('H -- hard, M -- medium, L -- easy ', True, cfg.BLUE) trect = title.get_rect() trect.midtop = (width/2, height/10) crect1 = content1.get_rect() crect1.midtop = (width/2, Midtop = (width/2, height/1.8) screen.blit(title, width/2, height/1.8) trect) screen.blit(content1, crect1) screen.blit(content2, crect2) while True: for event in pygame.event.get(): if (event.type == pygame.QUIT) or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == ord('l'): return 3 elif event.key == ord('m'): return 4 elif event.key == ord('h'): return 5 pygame.display.update()Copy the code
As shown below:
conclusion
The full text is finished, the article is finished to write ha ~ take quickly to try to play!
Source code for free:
If you need a complete source code: private xiaobian 06 or directly click on the blue font can be free!
Welcome to read, if it helps you, remember sanlian oh ~ learn to grow and communicate together!