Collage is a little game that let users to rearrange pictures according to the given order. The main logic is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
void canvasFrame::OnLButtonDown(UINT nFlags, CPoint point) { CClientDC dc(this); xx = yy = -1; //判断鼠标点击的位置 if(point.x > 0 && point.x < 100) { if(point.y > 0 && point.y < 100) { xx = 0; yy = 0; } if(point.y > 100 && point.y < 200) { xx = 1; yy = 0; } if(point.y > 200 && point.y < 300) { xx = 2; yy = 0; } } if(point.x > 100 && point.x < 200) { if(point.y > 0 && point.y < 100) { xx = 0; yy = 1; } if(point.y > 100 && point.y < 200) { xx = 1; yy = 1; } if(point.y > 200 && point.y < 300) { xx = 2; yy = 1; } } if(point.x > 200 && point.x < 300) { if(point.y > 0 && point.y < 100) { xx = 0; yy = 2; } if(point.y > 100 && point.y < 200) { xx = 1; yy = 2; } if(point.y > 200 && point.y < 300) { xx = 2; yy = 2; } } int xxx, yyy; if(xx != -1 && yy != -1) { for(int i = 0; i < 3; ++i) { for(int j = 0; j < 3; ++j) { if(cur[i][j] == 9) { xxx = i; yyy = j; } } } } if(abs(xxx - xx) + abs(yyy - yy) == 1) { //dc.TextOut(400, 400 ,"hello!"); //int t = cur[xxx][yyy]; cur[xxx][yyy] = cur[xx][yy]; cur[xx][yy] = 9; //交换图片位置 mdc->SelectObject(b); dc.BitBlt(a[xx * 3 + yy].x, a[xx * 3 + yy].y, 100, 100, mdc, 0, 0, SRCCOPY); switch(cur[xxx][yyy]) { case 1: mdc->SelectObject(p1);break; case 2: mdc->SelectObject(p2);break; case 3: mdc->SelectObject(p3);break; case 4: mdc->SelectObject(p4);break; case 5: mdc->SelectObject(p5);break; case 6: mdc->SelectObject(p6);break; case 7: mdc->SelectObject(p7);break; case 8: mdc->SelectObject(p8);break; } dc.BitBlt(a[xxx * 3 + yyy].x, a[xxx * 3 + yyy].y, 100, 100, mdc, 0, 0, SRCCOPY); int f = 0; for(int i = 0; i < 3; ++i) { int flag = 0; for(int j = 0; j < 3; ++j) { if(cur[i][j] != 3 * i + j + 1) { flag = 1; break; } } if(flag == 1) { f = 1; break; } } if(f == 0) { strcpy(result,"恭喜你,你赢了!"); dc.TextOut(100 , 350 ,result); } } CFrameWnd::OnLButtonDown(nFlags, point); } |
Leave a Comment