別踩白塊兒之禪模式 windows程式實現

來源:互聯網
上載者:User

標籤:windows   遊戲   別踩白塊兒   禪模式   

別踩白塊兒之禪模式 windows程式實現

代碼如下

#include <Windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(//程式入口,WINAPI是一種函數呼叫慣例,用於表明如何產生在堆棧中放置調用參數的機器代碼HINSTANCE hInstance  //執行個體控制代碼,標識該程式, HINSTANCE hPreInstance  //16位中用於標識該程式前一執行個體,32位中不再採用,參數為NULL, LPSTR szCmdLine  //調用時的命令列, int iCmdShow)   //視窗顯示方式{static TCHAR szName[] = TEXT("HIYUN");HWND hwnd;MSG msg;WNDCLASS wc;wc.style = CS_VREDRAW | CS_HREDRAW;wc.cbClsExtra = 0;wc.cbWndExtra = 0;wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wc.hCursor = LoadCursor(NULL, IDC_ARROW);wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);wc.hInstance = hInstance;wc.lpfnWndProc = WndProc;wc.lpszMenuName = NULL;wc.lpszClassName = szName;if (!RegisterClass(&wc)){MessageBox(NULL, TEXT("註冊失敗!"), TEXT("失敗"), MB_OK | MB_ICONERROR);}hwnd = CreateWindow(szName, TEXT("別踩白塊兒之禪模式 - 閑雲野鶴製作,QQ群116920287"), WS_OVERLAPPEDWINDOW,400, 100, 400, 600,NULL, NULL, 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;PAINTSTRUCT ps;RECT rect;TCHAR szBuff[50];static HBRUSH brushPass = CreateSolidBrush(RGB(223, 223, 223));static int i, j, x, y, tx, ty;static int runing, cxChar, cyChar, cxClient, cyClient, cxSquare, cySquare;static TCHAR PlayName[] = TEXT("YUN");static ULONG score = 0, t;static int Loc[20];switch (message){case WM_CREATE:runing = 0;hdc = GetDC(hwnd);TEXTMETRIC tm;GetTextMetrics(hdc, &tm);cxChar = tm.tmAveCharWidth;cyChar = tm.tmHeight + tm.tmExternalLeading;ReleaseDC(hwnd, hdc);return 0;case WM_SIZE:cxClient = LOWORD(lparam);cyClient = HIWORD(lparam);cxSquare = cxClient / 4;cySquare = (int)(cxSquare * 1.5);for (i = 0; i <= cyClient / cySquare + 2; ++i){Loc[i] = rand() % 4;}return 0;case WM_LBUTTONDOWN:tx = x = LOWORD(lparam);ty = y = HIWORD(lparam);x /= cxSquare;y = (cyClient - y) / cySquare;if (Loc[0] == x && y == 0 && !runing){runing = 1;InvalidateRect(hwnd, NULL, true);}else if (Loc[1] == x && y == 1 && runing){score++;for (i = 0; i <= cyClient / cySquare + 1; ++i){Loc[i] = Loc[i + 1];}Loc[i] = rand() % 4;InvalidateRect(hwnd, NULL, true);}return 0;case WM_PAINT:hdc = BeginPaint(hwnd, &ps);SetBkMode(hdc, TRANSPARENT);SetTextColor(hdc, RGB(255, 0, 0));for (i = 1; i < 4; ++i){MoveToEx(hdc, cxSquare * i, 0, NULL);LineTo(hdc, cxSquare * i, cyClient);}for (i = 0; i <= cyClient / cySquare + 1; ++i){MoveToEx(hdc, 0, cyClient - cySquare * i, NULL);LineTo(hdc, cxClient, cyClient - cySquare * i);j = Loc[i];if (i == 0 && runing)SelectObject(hdc, brushPass);elseSelectObject(hdc, GetStockObject(BLACK_BRUSH));Rectangle(hdc, j * cxSquare, cyClient - cySquare * (i + 1),cxSquare * (j + 1) + 1, cyClient - cySquare * i + 1);if (!runing && i == 0){TextOut(hdc, j * cxSquare + cxSquare / 2 - cxChar * 1.5, cyClient - cySquare / 2,szBuff, wsprintf(szBuff, TEXT("開始")));}}TextOut(hdc, cxChar, cyChar, szBuff,wsprintf(szBuff, TEXT("Player:%s"), PlayName));t = wsprintf(szBuff, TEXT("Score: %ld"), score);TextOut(hdc, cxClient - (t + 2) * cxChar, cyChar, szBuff, t);EndPaint(hwnd, &ps);return 0;case WM_DESTROY:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, message, wparam, lparam);}


別踩白塊兒之禪模式 windows程式實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.