1、(要求写详细过程)该部分必须包括:系统结构框图、各模块流程图、关键代码、主要的数据结构、测试与评价等2.12.3头文件(宋体,小三)#include stdh.hclass Boardprivate: int m_bMAXN_BOARDMAXN_BOARD; / empty block position : ex ey / old empty block position oex,oey int m_ex,m_ey; int m_oex,m_oey; int m_dir; / reverse-direction of empty block bool m_bMove; / if the boa
2、rd moved int m_nx,m_ny; int m_nBlock;public: Board(); int Create(); bool Check(); / check if the game win int GetMat(int ,int ); int SetMat(int ,int , int ); int SetXY(int ,int ); int GetEX(); int GetEY(); int GetOEX(); int GetOEY(); int GetDir(); int Move(int , int ); bool CheckMove(); int ResetMov
3、e(); int Up(); int Down(); int Left(); int Right(); int Click(int , int); / when User click the picture int Init();/* Class Flip stored all elements of the flipping-block. It will be used when the clicked block moving to the destination.*/class Flip int m_cnt; int m_ux,m_uy; / uX , uY pixels are mov
4、ed per m_time int m_time; / uSeconds /direction of flip int m_cx,m_cy; / current pos of block int m_sx,m_sy; / source pos of block int m_dx,m_dy; / destination pos of block int GetXY(int , int& , int&); int GetTime(); int SetXY(int ,int ,int ,int ); int SetTime(int ); int SetCnt(int ,int ,int ); int
5、 SetDir(int); bool Finish(HWND ); / check if the flipping overFlip.hBoard.hclass Game Board m_board; Flip m_flip; int m_vFlip; int m_xFlip,m_yFlip; HBITMAP m_hBmp; HBITMAP m_hMemBmp; BITMAP m_bmp; HDC m_mdc,m_bufdc; /double cache HWND m_hWnd; Game(); int SetLevel(int ,int ); int LoadBmp(HINSTANCE,in
6、t); int Init(HWND); / Init the game int Create(HWND); int Paint(HWND); /User clicked the picture int Key(WPARAM); /User push down the keyboard int InitFlip(); / init the m_flip and then flipping start. bool CheckWin(); int Release(HWND );/NO_DEPENDENCIES/ Microsoft Visual C+ generated include file./
7、 Used by res.rc/#define IDB_AC 103#define IDB_BH 104/ Next default values for new objects/ #ifdef APSTUDIO_INVOKED#ifndef APSTUDIO_READONLY_SYMBOLS#define _APS_NEXT_RESOURCE_VALUE 105#define _APS_NEXT_COMMAND_VALUE 40001#define _APS_NEXT_CONTROL_VALUE 1001#define _APS_NEXT_SYMED_VALUE 101#endif#prag
8、ma once#include ctimecmathusing namespace std;const int MAXN_BOARD = 10;const int CLIENT_X = 1024;const int CLIENT_Y = 768;const int OFFSET_LINE = 1;const int DIR_UP = 0;const int DIR_DOWN = 1;const int DIR_LEFT = 2;const int DIR_RIGHT = 3;const int FLIP_CNT = 8;const int FLIP_TIME = 18;2.2源文件(宋体,小三
9、)Board:Board() memset(m_b,-1,sizeof(m_b); m_nx = m_ny = m_ex = m_ey = 0; m_nBlock = 0;int Board:Create() return 0;SetXY(int nx, int ny) m_nx = nx; m_ny = ny; m_nBlock = m_nx * m_ny; m_oex = m_ex = m_nx - 1; m_oey = m_ey = m_ny - 1;SetMat(int x, int y, int val) m_byx = val; return val;GetMat(int x, i
10、nt y) return m_byx;GetEX() return m_ex;GetEY() return m_ey;GetOEX() return m_oex;GetOEY() return m_oey;GetDir() return m_dir;bool Board:Check() int ck = 0; bool flag = true; for(int i = 0; i m_ny; +i) for(int j = 0; j m_nx; +j) if(ck != m_bij) flag = false; break; +ck; if(flag = false & ck m_nBlock-
11、1) return false; return true;Init() / VARIABLE: nStep , nLoop / / nStep: / In order to generate the random block positions and / to make sure must have a solution, we / have to simulate The-Inverse-Action of the user. / Then nStep mean we will execute the Inverse-Action times. / And each Action will
12、 be random generated. / nLoop: / Due to the reason that the method that above-mentioned has / a big Drawback: if the number of blocks is huge, then method would / only change a small area of all. Avoiding this I add a new variable / nloop, which means a same actions that executed times. It was prove
13、d / that after this improved the new-method work well. int nStep = (rand()&(1Up(); break; case 1:Down(); case 2:Left(); case 3:Right(); Move(int nx, int ny) m_ex = nx; m_ey = ny;CheckMove() return m_bMove;ResetMove() m_bMove = false;Up() Move(m_ex,m_ey); if(m_ey = 0) return -1; m_bm_eym_ex = m_bm_ey
14、-1m_ex; m_bm_ey-1m_ex = -1; -m_ey; m_dir = DIR_DOWN; m_bMove = true;Down() if(m_ey = m_ny - 1) m_bm_eym_ex = m_bm_ey+1m_ex; m_bm_ey+1m_ex = -1; +m_ey; m_dir = DIR_UP;Left() if(m_ex = 0) m_bm_eym_ex = m_bm_eym_ex-1; m_bm_eym_ex-1 = -1; -m_ex; m_dir = DIR_RIGHT;Right() if(m_ex = m_nx - 1) m_bm_eym_ex
15、= m_bm_eym_ex+1; m_bm_eym_ex+1 = -1; +m_ex; m_dir = DIR_LEFT;Click(int x, int y) if(x = m_nx | y = m_ny) if(abs(x-m_ex) + abs(y-m_ey) 1) if(x - m_ex 0) this- return 0; if(m_ex - x if(y - m_ey if(m_ey - y PingTu.hGame:Game() m_nx = m_ny = m_ux = m_uy = 0;int Game:Create(HWND hWnd) m_mdc = CreateCompa
16、tibleDC(GetDC(hWnd); m_bufdc = CreateCompatibleDC(GetDC(hWnd); srand(unsigned(time(NULL); m_board.Create();Init(HWND hWnd) m_ux = m_bmp.bmWidth/m_nx; m_uy = m_bmp.bmHeight/m_ny; m_hWnd = hWnd; m_board.Init(); MoveWindow(hWnd,0,0, m_bmp.bmWidth+m_ux+m_nx*OFFSET_LINE+20, m_bmp.bmHeight+20, TRUE); / in
17、itialize flip m_flip.SetCnt(FLIP_CNT,m_ux,m_uy); m_flip.SetTime(FLIP_TIME);SetLevel(int x, int y) m_nx = x; m_ny = y; m_board.SetXY(x,y);LoadBmp(HINSTANCE hInst, int id) m_hBmp = LoadBitmap(hInst,MAKEINTRESOURCE(id); GetObject(m_hBmp,sizeof(BITMAP),&m_bmp);Paint(HWND hWnd ) int x,y,k,i,j; int cur_bl
18、ock; HDC hdc; hdc = GetDC(hWnd); DeleteObject(m_hMemBmp); m_hMemBmp = CreateCompatibleBitmap(GetDC(hWnd),CLIENT_X,CLIENT_Y); SelectObject(m_mdc,m_hMemBmp); SelectObject(m_bufdc,m_hBmp); cur_block = m_board.GetMat(m_board.GetOEX(),m_board.GetOEY(); for(i = 0; for( j = 0; k = m_board.GetMat(j,i); x =
19、k%m_nx; y = k/m_nx; if( -1 = k ) /StretchBlt(m_mdc,j*m_ux+OFFSET_LINE,i*m_uy+OFFSET_LINE, / m_ux-2*OFFSET_LINE,m_uy-2*OFFSET_LINE, / m_bufdc,0,0,m_bmp.bmWidth,m_bmp.bmHeight,SRCCOPY); continue; else if( k = cur_block & !m_flip.Finish(hWnd) ) m_flip.GetXY(m_board.GetDir(),x,y); BitBlt(m_mdc,x,y,m_ux,
20、m_uy, m_bufdc,(k%m_nx)*m_ux,(k/m_nx)*m_uy,SRCCOPY); else BitBlt(m_mdc,j*(m_ux+(OFFSET_LINE1)+(OFFSET_LINE), i*(m_uy+(OFFSET_LINE1)+OFFSET_LINE,m_ux,m_uy, m_bufdc,x*m_ux,y*m_uy,SRCCOPY); BitBlt(hdc,0,0,m_bmp.bmWidth,m_bmp.bmHeight,m_mdc,0,0,SRCCOPY); StretchBlt(hdc,m_bmp.bmWidth,0,m_ux,m_uy, m_bufdc,0,0,m_bmp.bmWidth,m_bmp.bmHeight,SRCCOPY);Click(int mx, int my)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1