Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the jigsaw puzzle of C++ based on EasyX library

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge of this article, "C++ based on EasyX library how to achieve the puzzle Mini Game", so the editor gave you a summary of the following contents, detailed contents, clear steps, and have a certain reference value. I hope you can get something after reading this article. Let's take a look at this "C++ based on EasyX library how to achieve the puzzle Mini Game" article.

The specific code is as follows:

# pragma once#include # include using namespace std;static const int MAX_MAP = 30; / define the maximum row or column chunk constant int check[ Max _ MAP] [MAX_MAP]; / / check the array int mapping [Max _ MAP] [MAX_MAP]; / / store int numbers [Max _ MAP * MAX_MAP]; / / randomize the array IMAGE img_total / / original image IMAGE img_blank; / / White background IMAGE IMG [Max _ MAP] [MAX_MAP]; / / storing block image int level = 3; / / checkpoint difficulty int width_temp = 0; / / Block width int height_temp = 0; / / Block height int flagi = 0; / / Mark block line position int flagj = 0 / / Mark the block column position int mousei = 0; / / mark the mouse position int mousej = 0; / / mark the mouse position int FLAG = 0; / / mark the victory mark void Get_graphics (); / / read the picture and preload it to the original image void Set_graphics (); / / set the picture position and corresponding relationship void Line_flush () / / draw a line to split the picture void Rand_array (); / / initialize the random array void Get_mouse (); / / get the mouse operation void Judge_graphics (); / / determine whether to clear the customs and choose whether to void Show_graphics the next level () / / display the segmented picture inline void Get_graphics () / / read the picture and preload it into the original image {loadimage (& img_total, L "1.png"); loadimage (& img_blank, L "0.png"); initgraph (img_total.getwidth (), img_total.getheight ());} inline void Set_graphics () / / set the picture position and corresponding relationship {width_temp = img_total.getwidth () / level Height_temp = img_total.getheight () / level; / / load the image SetWorkingImage (& img_total) of each block; for (int I = 0; I < level; iTunes +) {for (int j = 0; j < level; jacks +) getimage (& IMG [I] [j], I * width_temp, j * height_temp, width_temp, height_temp);} SetWorkingImage (); / / check array initialization int cnt = 0; for (int I = 0; I < level) ) {for (int j = 0; j < level; jacks +) {check [I] [j] = cnt; cnt++;}} inline void Line_flush () / / draw a line to split the picture {for (int I = 0; I < level; I +) {/ / setlinecolor (RED); / / you can change the line color default white line (I * width_temp, 0, I * width_temp, img_total.getheight ()) Line (0, I * height_temp, img_total.getwidth (), I * height_temp);}} inline void Rand_array () / / initialize the random array {for (int I = 0; I < level * level; iarrays +) random [I] = I; random_device rd; mt19937 g (rd ()); / / random number engine shuffle (random, random + level * level, g); / / disrupt the order int cnt = 0 For (int I = 0; I < level; iTunes +) {for (int j = 0; j < level; jacks +) {map [j] [I] = random [cnt]; / / reverse assignment 1 cnt++;}} void Get_mouse () {MOUSEMSG msg = GetMouseMsg (); if (msg.uMsg = WM_LBUTTONDOWN) {mousei = msg.x / width_temp; mousej = msg.y / height_temp If ((mousei + 1 = = flagi & & mousej = = flagj) | | (mousei = = flagi & & mousej + 1 = = flagj) | | (mousei-1 = = flagi & & mousej = = flagj) | | (mousei = = flagi & & mousej-1 = = flagj) {/ / Exchange image blocks swap (map [Mousej] [mousei], map [flagj] [flagi]);} void Judge_graphics () {int cnt = 0; for (int I = 0; I < level; iTunes +) {for (int j = 0) J < level; jungle +) {if (map [I] [j] = = check [I] [j]) cnt++;}} if (cnt = = level * level) {MessageBox (GetHWnd (), _ T ("pass."), _ T ("message tip."), MB_OK); FLAG = 1; exit (0);}} inline void Show_graphics () / / display block image {for (int I = 0; I < level) ) {for (int j = 0; j < level; jacks +) {if (map [j] [I] = = level * level-1) / / reverse assignment 2 {flagi = I; flagj = j; putimage (I * width_temp, j * height_temp, & img_blank);} else {int countj = map [j] [I]% level; int counti = map [j] [I] / level Putimage (I * width_temp, j * height_temp, & IMG [countj] [counti]);} Line_flush ();} int main () {Get_graphics (); Set_graphics (); Rand_array (); Show_graphics (); while (1) {BeginBatchDraw (); / / a pair of buffers to prevent flicker Get_mouse (); Show_graphics (); EndBatchDraw (); / / a pair of buffers to prevent flicker Judge_graphics () } if (FLAG) {putimage (0,0, & img_total); FLAG = 0;} system ("pause"); return 0;} the above is about "how C++ implements puzzles Mini Game based on EasyX library". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report