- 浏览: 1654522 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (405)
- C/C++ (16)
- Linux (60)
- Algorithm (41)
- ACM (8)
- Ruby (39)
- Ruby on Rails (6)
- FP (2)
- Java SE (39)
- Java EE (6)
- Spring (11)
- Hibernate (1)
- Struts (1)
- Ajax (5)
- php (2)
- Data/Web Mining (20)
- Search Engine (19)
- NLP (2)
- Machine Learning (23)
- R (0)
- Database (10)
- Data Structure (6)
- Design Pattern (16)
- Hadoop (2)
- Browser (0)
- Firefox plugin/XPCOM (8)
- Eclise development (5)
- Architecture (1)
- Server (1)
- Cache (6)
- Code Generation (3)
- Open Source Tool (5)
- Develope Tools (5)
- 读书笔记 (7)
- 备忘 (4)
- 情感 (4)
- Others (20)
- python (0)
最新评论
-
532870393:
请问下,这本书是基于Hadoop1还是Hadoop2?
Hadoop in Action简单笔记(一) -
dongbiying:
不懂呀。。
十大常用数据结构 -
bing_it:
...
使用Spring MVC HandlerExceptionResolver处理异常 -
一别梦心:
按照上面的执行,文件确实是更新了,但是还是找不到kernel, ...
virtualbox 4.08安装虚机Ubuntu11.04增强功能失败解决方法 -
dsjt:
楼主spring 什么版本,我的3.1 ,xml中配置 < ...
使用Spring MVC HandlerExceptionResolver处理异常
程序代码:
#include <windows.h> #include <math.h> #include "resource.h" // 菜单资源头文件 #define SHADOW_WIDTH1 1 //阴影宽度1 #define SHADOW_WIDTH2 2 //阴影宽度2 #define SHADOW_WIDTH3 3 //阴影宽度3 #define ID_TIMER 1 //定时器的id号 #define BORDER 8 //边界的宽度 #define BOX_WIDTH 18//box的宽度 #define BOX_HEIGHT 18 //box的高度 #define RESERVED_AREA 32 //保留区高度 //************************************ //自定义的函数声明 //************************************ //窗口过程函数 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); //绘制边界 void DrawBorder(HDC hdc,int x,int y,int width,int height,int BorderWidth,COLORREF &color1,COLORREF &color2,bool WTop); //自动打开Boxes void AutoOpenBoxes(HDC &hdc,int i,int j); //自动打开时,重绘box矩形区域 void drawRect(HDC &hdc,int x,int y); //判断周围box是否都打开了 bool allRoundIsOpened(int row,int col); //初始化box void InitBox(); //更新当前窗口,并reset void UpdateTheWindow(HWND &hwnd,int rows,int cols,int mineNO); //计算当前box周围雷的个数 void ComputeRoundMineNo(); //随机布雷 void RandomSetMines(); //绘制mineRect变量保存雷区 void DrawMineArea(HDC &hdc); //报告游戏结束 void ReportGameOver(HDC &hdc,HBITMAP &hBitmap1,HBITMAP &hBitmap2); //绘制显示雷的个数的区域 void DisplayMineNo(HDC &hdc); //绘制计时显示区域 void DrawTimeArea(HDC &hdc); //显示计时器时间 void DisplayTime(HDC &hdc); //绘制重置按钮 void DrawResetButton(HDC &hdc,HBITMAP &hBitmap); void DisplayADigit(HDC hdc,int iNumber); //********************************** //结构体Box,roundMineNO表示周围雷得 //个数containMine表示是否里面是否有 //雷,isOpened表示box是否已经打开 //********************************** struct Box { int roundMineNO; bool containMine; bool isOpened; }; //******************** //全局静态变量声明 //******************** static int mineNumber;//雷的个数 static int ROWS; //行数 static int COLS; //列数 static int iSM_BorderX;//系统boder宽度 static int iSM_BorderY;//系统boder高度 static int iSM_CaptionY; //系统标题栏高度 static int iSM_MenuY;//菜单栏的高度 static int icxSrc,icySrc;//屏幕的大小 static Box **box;//结构体Box的二维指针 static int i,j,numberOpened;//已经打开box的数量 static int time;//计数变量 static HMENU hMenu; static RECT mineRect;//保存雷区域的RECT static RECT resetButtonRect;//保存重置“按钮”区域的RECT static COLORREF color1=RGB(128, 128, 128),//绘制border的shadow区域 color2=RGB(255,255,255),//绘制border的hightlight区域 color3=RGB(192,192,192),//窗体的背景颜色 color4=RGB(120,120,200);//绘制打开的box分割线颜色 static HBITMAP hBitmap1,hBitmap2,hBitmap3,hBitmap4; //******** //main函数 //******** int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("SineWave") ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; mineNumber = 10; ROWS = 10; COLS = 10; box = new Box* [ROWS]; for(int k=0;k<ROWS;k++) box[k] = new Box[COLS]; iSM_BorderX = GetSystemMetrics(SM_CXBORDER); iSM_BorderY = GetSystemMetrics(SM_CYBORDER); iSM_CaptionY = GetSystemMetrics(SM_CYCAPTION); iSM_MenuY = GetSystemMetrics(SM_CYMENU); icxSrc = GetSystemMetrics(SM_CXSCREEN); icySrc = GetSystemMetrics(SM_CYSCREEN); int cx = BOX_WIDTH * COLS + 2 * SHADOW_WIDTH3 + 2 * SHADOW_WIDTH2 + 2 * iSM_BorderX + 2 * BORDER; int cy = BOX_HEIGHT * ROWS + 2 * SHADOW_WIDTH3 + 4 * SHADOW_WIDTH2 + 2 * iSM_BorderY + 3 * BORDER + RESERVED_AREA+iSM_CaptionY+iSM_MenuY; mineRect.left = SHADOW_WIDTH3+BORDER+SHADOW_WIDTH2; mineRect.right =mineRect.left + BOX_WIDTH * COLS; mineRect.top = SHADOW_WIDTH3+2*BORDER+RESERVED_AREA+3*SHADOW_WIDTH2; mineRect.bottom = mineRect.top + BOX_HEIGHT * ROWS; resetButtonRect.left = SHADOW_WIDTH3+BORDER+(mineRect.right-mineRect.left)/2-RESERVED_AREA/4; resetButtonRect.right = resetButtonRect.left + 2 * RESERVED_AREA / 3 + 2; resetButtonRect.top = SHADOW_WIDTH3+BORDER + RESERVED_AREA / 4 - 2; resetButtonRect.bottom = resetButtonRect.top + 2 * RESERVED_AREA / 3 + 4; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc= WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; hMenu = LoadMenu (hInstance, MAKEINTRESOURCE (IDR_MENU1)) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)) { MessageBox ( NULL, TEXT ("Program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow ( szAppName, TEXT ("扫雷-游戏"), WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, ,(icxSrc-cx)/2,(icySrc-cy)/2, cx, cy, NULL, hMenu, hInstance, NULL) ; ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } //************* //消息处理函数 //************* LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; HBRUSH hBrush; BITMAP bitmap; HINSTANCE hInstance; PAINTSTRUCT ps ; static bool isLButtonDown=false; static int m,n,cx,cy; static RECT grid,rect; static char szBuffer[2]; POINT pt; switch (message) { case WM_CREATE: //初始化变量 hInstance = ((LPCREATESTRUCT)lParam)->hInstance; hBitmap1 = LoadBitmap(hInstance,TEXT("FACE1")); GetObject(hBitmap1,sizeof(BITMAP),&bitmap); hBitmap2 = LoadBitmap(hInstance,TEXT("FACE2")); GetObject(hBitmap2,sizeof(BITMAP),&bitmap); hBitmap3 = LoadBitmap(hInstance,TEXT("FACE3")); GetObject(hBitmap3,sizeof(BITMAP),&bitmap); hBitmap4 = LoadBitmap(hInstance,TEXT("MINE")); GetObject(hBitmap4,sizeof(BITMAP),&bitmap); InitBox(); RandomSetMines(); ComputeRoundMineNo(); SetTimer(hwnd,ID_TIMER,1000,NULL); return 0; case WM_TIMER: hdc = GetDC(hwnd); time++; DisplayTime(hdc); DeleteDC(hdc); return 0; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; GetClientRect(hwnd,&rect); hBrush = CreateSolidBrush(RGB(192,192,192)); SetBkColor(hdc,RGB(192,192,192)); SelectObject(hdc,hBrush); SelectObject(hdc,GetStockObject(NULL_PEN)); Rectangle(hdc,0,0,rect.right,rect.bottom); //绘制外边界 DrawBorder(hdc,0,0,rect.right,rect.bottom,SHADOW_WIDTH3,color1,color2,true); //绘制保留区 DrawBorder(hdc, SHADOW_WIDTH3+BORDER, SHADOW_WIDTH3+BORDER, BOX_WIDTH * COLS + 2 * SHADOW_WIDTH2, RESERVED_AREA + 2 * SHADOW_WIDTH2, SHADOW_WIDTH2, color1,color2,false); DrawResetButton(hdc,hBitmap1); DisplayMineNo(hdc); DrawTimeArea(hdc); //绘制内边界 DrawBorder(hdc, SHADOW_WIDTH3+BORDER, SHADOW_WIDTH3+2*BORDER+RESERVED_AREA+2*SHADOW_WIDTH2, BOX_WIDTH * COLS + 2 * SHADOW_WIDTH2, BOX_HEIGHT*ROWS + 2*SHADOW_WIDTH2, SHADOW_WIDTH2, color1,color2,false); //绘制雷区的box DrawMineArea(hdc); EndPaint(hwnd,&ps); return 0 ; case WM_LBUTTONDOWN: hdc = GetDC(hwnd); isLButtonDown = true; DrawResetButton(hdc,hBitmap2); pt.x = LOWORD(lParam); pt.y = HIWORD(lParam); grid.left = mineRect.left; grid.right = mineRect.right; grid.top = mineRect.top; grid.bottom = mineRect.bottom; if(PtInRect(&resetButtonRect,pt)) { hdc = GetDC(hwnd); DrawBorder(hdc,resetButtonRect.left,resetButtonRect.top,resetButtonRect.right - resetButtonRect.left ,resetButtonRect.bottom - resetButtonRect.top,SHADOW_WIDTH2,color1,color2,false); DeleteDC(hdc); } else if(PtInRect(&grid,pt)) { j = (pt.x - grid.left) / BOX_WIDTH; i = (pt.y - grid.top) / BOX_HEIGHT; grid.left += BOX_WIDTH * j; grid.top += BOX_HEIGHT * i; grid.right = grid.left + BOX_WIDTH; grid.bottom = grid.top + BOX_HEIGHT; DrawBorder(hdc,grid.left,grid.top,BOX_WIDTH-2,BOX_HEIGHT-2,SHADOW_WIDTH2,color3,color3,false); DrawBorder(hdc,grid.left,grid.top,BOX_WIDTH,BOX_HEIGHT,SHADOW_WIDTH1,color4,color4,false); } DeleteDC(hdc); return 0; case WM_LBUTTONUP: static HPEN hPen; static RECT rect1; static char szBuffer[2]; hdc = GetDC(hwnd); pt.x = LOWORD(lParam); pt.y = HIWORD(lParam); isLButtonDown = false; DrawResetButton(hdc,hBitmap1); if(PtInRect(&resetButtonRect,pt)) { DrawBorder(hdc,resetButtonRect.left,resetButtonRect.top,resetButtonRect.right - resetButtonRect.left ,resetButtonRect.bottom - resetButtonRect.top,SHADOW_WIDTH2,color1,color2,true); UpdateTheWindow(hwnd,ROWS,COLS,mineNumber); return 0; } else if(!PtInRect(&mineRect,pt)) return 0; hPen = CreatePen(PS_SOLID,2,RGB(255,255,0)); SelectObject(hdc,hPen); SetBkColor(hdc,RGB(192,192,192)); rect1.left = mineRect.left + BOX_WIDTH * j; rect1.right = rect1.left + BOX_WIDTH; rect1.top = mineRect.top + BOX_HEIGHT * i; rect1.bottom = rect1.top + BOX_HEIGHT; if(!box[i][j].isOpened) { if(!box[i][j].containMine) { if(box[i][j].roundMineNO != 0) { wsprintf(szBuffer,TEXT("%d"),box[i][j].roundMineNO); //输出周围雷的个数 DrawText(hdc,szBuffer,-1,&rect1,DT_SINGLELINE|DT_CENTER|DT_VCENTER); } box[i][j].isOpened = true; numberOpened ++; if(numberOpened == ROWS * COLS - mineNumber) MessageBox (hwnd, TEXT ("祝贺你赢了!"),TEXT("扫雷-游戏"), MB_ICONWARNING) ; AutoOpenBoxes(hdc,i,j); } else ReportGameOver(hdc,hBitmap3,hBitmap4); } DeleteDC(hdc); return 0; case WM_MOUSEMOVE: if(isLButtonDown) { pt.x = LOWORD(lParam); pt.y = HIWORD(lParam); rect.left = mineRect.left; rect.right = mineRect.right; rect.top = mineRect.top; rect.bottom = mineRect.bottom; if(PtInRect(&rect,pt))//判断是否在雷区 { m = i; n = j; j = (pt.x - rect.left) / BOX_WIDTH; i = (pt.y - rect.top) / BOX_HEIGHT; rect.left += BOX_WIDTH * j; rect.top += BOX_HEIGHT * i; rect.right = rect.left + BOX_WIDTH; rect.bottom = rect.top + BOX_HEIGHT; if(grid.left == rect.left && grid.right==rect.right &&grid.bottom == rect.bottom && grid.top == rect.top) return 0; hdc = GetDC(hwnd); if(!box[m][n].isOpened)//鼠标移走后,恢复未按下 { DrawBorder(hdc,grid.left,grid.top,BOX_WIDTH-2,BOX_HEIGHT-2,SHADOW_WIDTH2,color1,color2,true); DrawBorder(hdc,grid.left,grid.top,BOX_WIDTH,BOX_HEIGHT,SHADOW_WIDTH1,color3,color3,true); } //使当前的box成为按下状态 grid.left = rect.left; grid.right = rect.right; grid.bottom = rect.bottom; grid.top = rect.top; DrawBorder(hdc,grid.left,grid.top,BOX_WIDTH-2,BOX_HEIGHT-2,SHADOW_WIDTH2,color3,color3,true); DrawBorder(hdc,grid.left,grid.top,BOX_WIDTH,BOX_HEIGHT,SHADOW_WIDTH1,color4,color4,true); } DeleteDC(hdc); } return 0; case WM_COMMAND: //响应菜单消息 switch (LOWORD (wParam)) { case IDM_PLAY: InitBox(); RandomSetMines(); ComputeRoundMineNo(); InvalidateRect(hwnd,NULL,TRUE); UpdateWindow(hwnd); return 0; case IDM_BEGINER: UpdateTheWindow(hwnd,10,10,10); return 0; case IDM_MEDIUM: UpdateTheWindow(hwnd,15,15,20); return 0; case IDM_SENIOR: UpdateTheWindow(hwnd,15,20,30); return 0; case IDM_EXIT: SendMessage (hwnd, WM_CLOSE, 0, 0) ; return 0; case IDM_ABOUT: return 0; } case WM_DESTROY: DeleteObject(hBitmap1); DeleteObject(hBitmap2); DeleteObject(hBitmap3); DeleteObject(hBitmap4); KillTimer(hwnd,ID_TIMER); PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; } //绘制边界 void DrawBorder(HDC hdc,int x,int y,int width,int height,int BorderWidth,COLORREF &color1,COLORREF &color2,bool WTop) { int i; HPEN hpen1,hpen2; hpen1=CreatePen(PS_SOLID, 1, color1); hpen2=CreatePen(PS_SOLID, 1, color2); if(WTop) SelectObject(hdc,hpen2); else SelectObject(hdc,hpen1); for(i = 0; i < BorderWidth; i++) { MoveToEx(hdc,x+i,y+i,NULL); LineTo(hdc,x+width-i,y+i); MoveToEx(hdc,x+i,y+i,NULL); LineTo(hdc,x+i,y+height-i); } if(WTop) SelectObject(hdc,hpen1); else SelectObject(hdc,hpen2); for(i = 0; i < BorderWidth; i++) { MoveToEx(hdc,x+width-i,y+height-i,NULL); LineTo(hdc,x+width-i,y+i); MoveToEx(hdc,x+width-i,y+height-i,NULL); LineTo(hdc,x+i,y+height-i); } DeleteObject(hpen1); DeleteObject(hpen2); } //初始化box void InitBox() { numberOpened = 0; time = 0; for(int i=0;i<ROWS;i++) for(int j=0;j<COLS;j++) { box[i][j].containMine = false; box[i][j].isOpened = false; box[i][j].roundMineNO = 0; } } //计算周围类的个数 void ComputeRoundMineNo() { for(int i=0;i<ROWS;i++) for(int j=0;j<COLS;j++) { if(i>0&&box[i-1][j].containMine==true) { box[i][j].roundMineNO++; } if(i>0&&j<COLS-1&&box[i-1][j+1].containMine == true) { box[i][j].roundMineNO++; } if(j<COLS-1&&box[i][j+1].containMine == true) { box[i][j].roundMineNO++; } if(i<ROWS-1 && j<COLS && box[i+1][j+1].containMine == true) { box[i][j].roundMineNO++; } if(i<ROWS-1 && box[i+1][j].containMine == true) { box[i][j].roundMineNO++; } if(i<ROWS-1 && j>0 && box[i+1][j-1].containMine == true) { box[i][j].roundMineNO++; } if(j>0 && box[i][j-1].containMine == true) { box[i][j].roundMineNO++; } if(i>0 && j>0 && box[i-1][j-1].containMine == true) { box[i][j].roundMineNO++; } } } //随机布雷 void RandomSetMines() { int row,col; srand((UINT)GetCurrentTime()); for(int i=0;i<mineNumber;) { row=rand()%ROWS; col=rand()%COLS; if(box[row][col].containMine != true) { box[row][col].containMine = true; i++; } } } //自动打开box void AutoOpenBoxes(HDC &hdc,int x,int y) { if(x >= 0 && y >= 0 && x < ROWS && y < COLS && box[x][y].roundMineNO == 0&& !allRoundIsOpened(x,y)) { drawRect(hdc,x-1,y); drawRect(hdc,x-1,y+1); drawRect(hdc,x,y+1); drawRect(hdc,x+1,y+1); drawRect(hdc,x+1,y); drawRect(hdc,x+1,y-1); drawRect(hdc,x,y-1); drawRect(hdc,x-1,y-1); AutoOpenBoxes(hdc,x-1,y); AutoOpenBoxes(hdc,x-1,y+1); AutoOpenBoxes(hdc,x,y+1); AutoOpenBoxes(hdc,x+1,y+1); AutoOpenBoxes(hdc,x+1,y); AutoOpenBoxes(hdc,x+1,y-1); AutoOpenBoxes(hdc,x,y-1); AutoOpenBoxes(hdc,x-1,y-1); } } //绘制雷区 void DrawMineArea(HDC &hdc) { char szBuffer[2]; int xStart = mineRect.left; int yStart = mineRect.top; RECT rect0; HDC hdcMem; hdcMem = CreateCompatibleDC(hdc); SelectObject(hdcMem,hBitmap4); for(int i = 0; i < ROWS; i++) { for(int j = 0; j < COLS; j++) { if(!box[i][j].isOpened) DrawBorder(hdc,xStart,yStart,BOX_WIDTH-2,BOX_HEIGHT-2,SHADOW_WIDTH2, color1,color2,true); else { DrawBorder(hdc,xStart,yStart,BOX_WIDTH-2,BOX_HEIGHT-2,SHADOW_WIDTH2, color3,color3,true); DrawBorder(hdc,xStart,yStart,BOX_WIDTH,BOX_HEIGHT,SHADOW_WIDTH1, color4,color4,true); rect0.left = mineRect.left + BOX_WIDTH * j; rect0.right = rect0.left + BOX_WIDTH; rect0.top = mineRect.top + BOX_HEIGHT * i; rect0.bottom = rect0.top + BOX_HEIGHT; if(box[i][j].containMine) { BitBlt(hdc,rect0.left+2,rect0.top+2,BOX_WIDTH-2,BOX_HEIGHT-2,hdcMem,2,2,SRCCOPY); } else if(box[i][j].roundMineNO != 0) { wsprintf(szBuffer,TEXT("%d"),box[i][j].roundMineNO); //输出周围雷的个数 DrawText(hdc,szBuffer,-1,&rect0,DT_SINGLELINE|DT_CENTER|DT_VCENTER); } } xStart += BOX_WIDTH; } yStart += BOX_HEIGHT; xStart = SHADOW_WIDTH3+BORDER+SHADOW_WIDTH2; } DeleteDC(hdcMem); } //更新窗口,并reset void UpdateTheWindow(HWND &hwnd,int rows,int cols,int mineNO) { ROWS = rows; COLS = cols; mineNumber = mineNO; mineRect.left = SHADOW_WIDTH3+BORDER+SHADOW_WIDTH2; mineRect.right =mineRect.left + BOX_WIDTH * COLS; mineRect.top = SHADOW_WIDTH3+2*BORDER+RESERVED_AREA+3*SHADOW_WIDTH2; mineRect.bottom = mineRect.top + BOX_HEIGHT * ROWS; resetButtonRect.left = SHADOW_WIDTH3+BORDER+(mineRect.right-mineRect.left)/2-RESERVED_AREA/4; resetButtonRect.right = resetButtonRect.left + 2 * RESERVED_AREA / 3 + 2; resetButtonRect.top = SHADOW_WIDTH3+BORDER + RESERVED_AREA / 4 - 2; resetButtonRect.bottom = resetButtonRect.top + 2 * RESERVED_AREA / 3 + 4; int cx = BOX_WIDTH * COLS + 2 * SHADOW_WIDTH3 + 2 * SHADOW_WIDTH2 + 2 * iSM_BorderX + 2 * BORDER; int cy = BOX_HEIGHT * ROWS + 2 * SHADOW_WIDTH3 + 4 * SHADOW_WIDTH2 + 2 * iSM_BorderY + 3 * BORDER + RESERVED_AREA+iSM_CaptionY+iSM_MenuY; box = new Box* [ROWS]; for(int k=0;k<ROWS;k++) box[k] = new Box[COLS]; InitBox(); RandomSetMines(); ComputeRoundMineNo(); MoveWindow(hwnd,(icxSrc-cx)/2,(icySrc-cy)/2,cx,cy,true); InvalidateRect(hwnd,NULL,TRUE); UpdateWindow(hwnd); } //自动打开时,重绘box矩形区域 void drawRect(HDC &hdc,int x,int y) { RECT rect1; TCHAR szBuffer[2]={"0"}; if(x<0 || y<0 || x >= ROWS || y >= COLS) return; rect1.left = mineRect.left + BOX_WIDTH * y; rect1.right = rect1.left + BOX_WIDTH; rect1.top = mineRect.top + BOX_HEIGHT * x; rect1.bottom = rect1.top + BOX_HEIGHT; if(!box[x][y].isOpened) { DrawBorder(hdc,rect1.left,rect1.top, BOX_WIDTH-2,BOX_HEIGHT-2,SHADOW_WIDTH2,color3,color3,true); DrawBorder(hdc,rect1.left,rect1.top, BOX_WIDTH,BOX_HEIGHT,SHADOW_WIDTH1,color4,color4,true); if(!box[x][y].containMine && box[x][y].roundMineNO != 0) { wsprintf(szBuffer,TEXT("%d"),box[x][y].roundMineNO); DrawText(hdc,szBuffer,-1,&rect1,DT_SINGLELINE|DT_CENTER|DT_VCENTER); } box[x][y].isOpened = true; numberOpened ++; if(numberOpened == ROWS * COLS - mineNumber ) { MessageBox (NULL, TEXT ("祝贺你赢了!"),TEXT("扫雷-游戏"), MB_ICONWARNING) ; } } } //判断周围的所有box是否已经open bool allRoundIsOpened(int x,int y) { bool flag = true; if(x > 0 && !box[x-1][y].isOpened) flag = false; if(x > 0 && y < COLS-1 && !box[x-1][y+1].isOpened) flag = false; if(y < COLS-1 && !box[x][y+1].isOpened) flag = false; if(x < ROWS-1 && y< COLS-1 && !box[x+1][y+1].isOpened) flag = false; if(x < ROWS-1 && !box[x+1][y].isOpened) flag = false; if(x < ROWS-1 && y > 0 && !box[x+1][y-1].isOpened) flag = false; if(y > 0 && !box[x][y-1].isOpened) flag = false; if(x > 0 && y > 0 && !box[x-1][y-1].isOpened) flag = false; return flag; } //宣告游戏结束 void ReportGameOver(HDC &hdc,HBITMAP &hBitmap1,HBITMAP &hBitmap2) { RECT rect; HDC hdcMem; hdcMem = CreateCompatibleDC(hdc); SelectObject(hdcMem,hBitmap2); DrawResetButton(hdc,hBitmap1); for(int k=0;k<ROWS;k++) for(int l=0;l<COLS;l++) { if(box[k][l].containMine)//点到雷后,使所有的lei显现 { box[k][l].isOpened = true; rect.left =mineRect.left + BOX_WIDTH * l; rect.top = mineRect.top + BOX_HEIGHT * k; rect.right = rect.left + BOX_WIDTH; rect.bottom = rect.top + BOX_HEIGHT; DrawBorder(hdc,rect.left,rect.top,BOX_WIDTH-2,BOX_HEIGHT-2,SHADOW_WIDTH2,color3,color3,false); DrawBorder(hdc,rect.left,rect.top,BOX_WIDTH,BOX_HEIGHT,SHADOW_WIDTH1,color4,color4,false); BitBlt(hdc,rect.left+2,rect.top+2,BOX_WIDTH-2,BOX_HEIGHT-2,hdcMem,2,2,SRCCOPY); } } DeleteDC(hdcMem); MessageBox (NULL, TEXT ("游戏结束"),TEXT("扫雷-游戏"), MB_ICONWARNING) ; } //绘制显示雷的个数的区域 void DisplayMineNo(HDC &hdc) { RECT tempRect; HPEN hPen; int t = 0,temp = mineNumber; HBRUSH hBrush; tempRect.left = mineRect.left + (mineRect.right - mineRect.left) / 20 ; tempRect.right = tempRect.left + 52; tempRect.top = SHADOW_WIDTH3+BORDER+RESERVED_AREA/5; tempRect.bottom = tempRect.top + 24; DrawBorder(hdc,tempRect.left,tempRect.top,tempRect.right - tempRect.left , tempRect.bottom - tempRect.top ,SHADOW_WIDTH2,color1,color2,false); hPen = CreatePen(PS_SOLID,3,RGB(0,0,0)); SelectObject(hdc,hPen); hBrush = CreateSolidBrush(RGB(0,0,0)); SelectObject(hdc,hBrush); Rectangle(hdc,tempRect.left+2,tempRect.top+2,tempRect.right-1, tempRect.bottom-1 ); for(int i=0;i<3;i++) { SetViewportOrgEx(hdc,tempRect.right-15-t ,tempRect.top+2,NULL); DisplayADigit(hdc,temp%10); temp /= 10; t+=15; } SetViewportOrgEx(hdc,0,0,NULL); DeleteObject(hPen); DeleteObject(hBrush); } //绘制计时显示区域 void DrawTimeArea(HDC &hdc) { RECT tempRect; HBRUSH hBrush; HPEN hPen; int t = 0; int temp = time; tempRect.right = mineRect.right - (mineRect.right - mineRect.left) / 20 ; tempRect.left = tempRect.right - 52; tempRect.top = SHADOW_WIDTH3+BORDER+RESERVED_AREA/5; tempRect.bottom = tempRect.top + 24; DrawBorder(hdc,tempRect.left,tempRect.top,tempRect.right - tempRect.left , tempRect.bottom - tempRect.top ,SHADOW_WIDTH2,color1,color2,false); hPen = CreatePen(PS_SOLID,3,RGB(0,0,0)); SelectObject(hdc,hPen); hBrush = CreateSolidBrush(RGB(0,0,0)); SelectObject(hdc,hBrush); Rectangle(hdc,tempRect.left+2,tempRect.top+2,tempRect.right-1, tempRect.bottom-1 ); for(int i=0;i<3;i++) { SetViewportOrgEx(hdc,tempRect.right-15-t ,tempRect.top+2,NULL); DisplayADigit(hdc,temp%10); temp /= 10; t+=15; } SetViewportOrgEx(hdc,0,0,NULL); DeleteObject(hPen); DeleteObject(hBrush); } //显示时间 void DisplayTime(HDC &hdc) { RECT tempRect; HBRUSH hBrush; HPEN hPen; int t = 0; int temp = time; tempRect.right = mineRect.right - (mineRect.right - mineRect.left) / 20 ; tempRect.left = tempRect.right - 52; tempRect.top = SHADOW_WIDTH3+BORDER+RESERVED_AREA/5; tempRect.bottom = tempRect.top + 24; hPen = CreatePen(PS_SOLID,3,RGB(0,0,0)); SelectObject(hdc,hPen); hBrush = CreateSolidBrush(RGB(0,0,0)); SelectObject(hdc,hBrush); Rectangle(hdc,tempRect.left+2,tempRect.top+2,tempRect.right-1, tempRect.bottom-1 ); for(int i=0;i<3;i++) { SetViewportOrgEx(hdc,tempRect.right-15-t ,tempRect.top+2,NULL); DisplayADigit(hdc,temp%10); temp /= 10; t+=15; } SetViewportOrgEx(hdc,0,0,NULL); DeleteObject(hPen); DeleteObject(hBrush); } //绘制重置按钮 void DrawResetButton(HDC &hdc,HBITMAP &hBitmap) { int xPos = SHADOW_WIDTH3+BORDER+(mineRect.right-mineRect.left)/2-RESERVED_AREA/4; int yPos = SHADOW_WIDTH3+BORDER+RESERVED_AREA/4-2; int width = 2*RESERVED_AREA/3 + 2; int height = width + 2; HDC hdcMem; DrawBorder(hdc, xPos, yPos,width,height,SHADOW_WIDTH2,color1,color2,true); hdcMem = CreateCompatibleDC(hdc); SelectObject(hdcMem,hBitmap); BitBlt(hdc,xPos+2,yPos+2,width-2,height-2,hdcMem,0,0,SRCCOPY); DeleteDC(hdcMem); } //显示一个八段的数字 void DisplayADigit(HDC hdc,int iNumber) { static bool fSevenSegment[11][8] = { 1,1,1,0,1,1,1,0, //0 0,0,1,0,0,1,0,0, //1 1,0,1,1,1,0,1,1, //2 1,0,1,1,0,1,1,1, //3 0,1,1,1,0,1,0,1, //4 1,1,0,1,0,1,1,1, //5 1,1,0,1,1,1,1,1, //6 1,0,1,0,0,1,0,0, //7 1,1,1,1,1,1,1,1, //8 1,1,1,1,0,1,1,1, //9 0,0,0,1,0,0,0,1 //10(负号) }; static POINT ptSegment[8][4] = { {1,0,9,0,7,2,3,2}, //0 {0,1,2,3,2,7,0,9}, //1 {8,3,10,1,10,9,8,7}, //2 {1,10,2,9,8,9,9,10}, //3 {0,11,2,13,2,17,0,19}, //4 {8,13,10,11,10,19,8,17}, //5 {1,20,3,18,7,18,9,20}, //6 {1,10,2,11,8,11,9,10} //7 }; int iSeg; HPEN hPen; HBRUSH hBrush; hPen = CreatePen(PS_SOLID,1,RGB(255,0,0)); hBrush = CreateSolidBrush(RGB(255,0,0)); SelectObject(hdc,hPen); SelectObject(hdc,hBrush); for(iSeg=0;iSeg<8;++iSeg){ if(fSevenSegment[iNumber][iSeg]) Polygon(hdc,ptSegment[iSeg],4); } DeleteObject(hPen); DeleteObject(hBrush); }
评论
2 楼
fuliang
2008-07-14
这是我大二的时候写的,代码写的比较烂
1 楼
healer_kx
2008-07-14
希望你继续完善,不能一边写着那些模式和原则,一边写着这样的代码哦。
过几天我再来看看。
过几天我再来看看。
发表评论
-
C++继承访问控制
2010-12-19 15:37 1467C++允许在派生类对继承的方法访问控制重新定义,可以放松或者添 ... -
C++、面向对象随想
2010-10-17 23:19 1682最近使用C++,用起来总 ... -
C++类的作用域
2010-10-07 20:00 2588形参表和函数体处于类作用域中,函数返回类型不一定在类作用域中, ... -
C++ explicit
2010-09-26 23:07 1610C++ explicit用来修饰构造函数,表明是显式的。与显式 ... -
C++中的hash Map
2010-07-30 09:53 9836标准std中只有map,是使用平衡二叉树实现的,查找和添加的复 ... -
getopt test
2010-07-22 20:30 1126试了一下getopt,代码如下: #include< ... -
No local goto--longjmp and setjmp
2010-05-14 09:49 1525c语言提供了两个函数可以用来非local的跳转: #incl ... -
c语言的split
2009-05-21 22:58 5124leven同学提到一个简单的功能"12 22 33 ... -
c++ copy constructor VS java clone
2008-02-29 16:16 3389今天有一同学问我,java怎么没有拷贝构造函数呢,java的c ... -
c++指针与引用
2007-04-09 23:18 4200引用与指针的区别: 常常有人问引用与指针的区别,可能是指针 ... -
放假了,n长时间没有用过c++的class了,回顾一下.
2007-04-09 22:57 18401、你的类需要构造函数 ... -
Windows程序之滚动的正弦曲线(一)
2007-04-09 17:48 1865Windows程序之滚动的正弦曲线(一) #includ ... -
MFC下实现图形学之多边形扫描转化填充算法
2007-04-09 17:33 6782//************************* //获 ... -
MFC下实现图形学之Hermite、Bezier曲线的绘制
2007-04-09 17:21 8852//************************* ... -
今天用Windows API写的扫雷程序
2007-04-09 17:18 3817#include <windows.h> ...
相关推荐
仿windows扫雷小游戏java完整实现.zip仿windows扫雷小游戏java完整实现.zip仿windows扫雷小游戏java完整实现.zip仿windows扫雷小游戏java完整实现.zip仿windows扫雷小游戏java完整实现.zip仿windows扫雷小游戏java...
基于Android扫雷游戏的设计与实现.docx基于Android扫雷游戏的设计与实现.docx基于Android扫雷游戏的设计与实现.docx基于Android扫雷游戏的设计与实现.docx基于Android扫雷游戏的设计与实现.docx基于Android扫雷游戏...
扫雷游戏的设计与开发.rar扫雷游戏的设计与开发.rar
java课程设计(扫雷游戏)(20210809110704).pdf
基于JAVA的扫雷游戏的设计与实现.pdf
基于android的扫雷游戏的开发与实现.docx
毕业设计(论文)-java扫雷游戏课程设计与实现.pdf
扫雷游戏.exe
本文的设计与实现方法对基于Matlab的游戏开发具有重要的意义,为专业人员快速开发具有强大计算功能的专业应用软件提供了有价值的参考。 相关知识点: * Matlab GUI的设计与实现 * 扫雷游戏的核心算法和游戏逻辑 * ...
扫雷游戏设计代码VB完善版.doc
扫雷游戏课程设计汇本报告.doc
Java游戏扫雷-简易复制品.zipJava游戏扫雷-简易复制品.zip Java游戏扫雷-简易复制品.zipJava游戏扫雷-简易复制品.zip Java游戏扫雷-简易复制品.zipJava游戏扫雷-简易复制品.zip Java游戏扫雷-简易复制品.zipJava游戏...
Java实现扫雷游戏.zipJava实现扫雷游戏.zipJava实现扫雷游戏.zipJava实现扫雷游戏.zip Java实现扫雷游戏.zipJava实现扫雷游戏.zipJava实现扫雷游戏.zipJava实现扫雷游戏.zip Java实现扫雷游戏.zipJava实现扫雷游戏....
基于Java扫雷游戏的设计与实现.pdf
基于Java扫雷游戏的设计与实现.docx
扫雷游戏的PNG素材可以直接用于项目中,无需进一步处理。 7. **源文件**:源文件通常指的是设计软件的原始工作文件,如PSD和XD文件。提供源文件意味着设计师可以完全控制每一个设计细节,进行自定义修改。 8. **可...
扫雷小游戏小程序源码.zip
扫雷游戏算法- 扫雷是什么鬼?扫雷里包含什么算法?.mp4
【Java扫雷游戏课程设计详解】 本篇将详细介绍基于Java技术设计的扫雷游戏软件,旨在帮助学生深入理解和掌握Java编程技巧,同时提升独立思考和团队协作能力。 **设计目标** 设计目标是创建一个具有初级、中级和...