📄 main.c
字号:
return hmnu;}HMENU createpmenustart(void){ HMENU hmnu; MENUITEMINFO mii; memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING; mii.id = 0; mii.typedata = (DWORD)"Start"; hmnu = CreatePopupMenu (&mii); memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING ; mii.state = 0; mii.id = ID_NEWONE; mii.typedata = (DWORD)"Start one player game"; InsertMenuItem(hmnu, 0, TRUE, &mii); mii.type = MFT_STRING ; mii.state = 0; mii.id = ID_NEWTWO; mii.typedata = (DWORD)"Start two player game"; InsertMenuItem(hmnu, 1, TRUE, &mii); mii.type = MFT_STRING ; mii.state = 0; mii.id = ID_NEWTWOTEASE; mii.typedata = (DWORD)"Start two player game(Tease)"; InsertMenuItem(hmnu, 2, TRUE, &mii); mii.type = MFT_STRING ; mii.state = 0; mii.id = ID_HIGHSCORE; mii.typedata = (DWORD)"High Score"; InsertMenuItem(hmnu, 3, TRUE, &mii); mii.type = MFT_STRING ; mii.state = 0; mii.id = ID_EXIT; mii.typedata = (DWORD)"Exit"; InsertMenuItem(hmnu, 4, TRUE, &mii); return hmnu;}HMENU createpmenusetting(void){ HMENU hmnu; MENUITEMINFO mii; memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING; mii.id = 0; mii.typedata = (DWORD)"Setting"; hmnu = CreatePopupMenu (&mii); memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING ; mii.state = 0; mii.id = ID_KEYSARRANGE; mii.typedata = (DWORD)"Optoins"; InsertMenuItem(hmnu, 0, TRUE, &mii); return hmnu;}HMENU createpmenuabout(void){ HMENU hmnu; MENUITEMINFO mii; memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING; mii.id = 0; mii.typedata = (DWORD)"About"; hmnu = CreatePopupMenu (&mii); memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING ; mii.state = 0; mii.id = ID_ABOUT; mii.typedata = (DWORD)"About Russia Square"; InsertMenuItem(hmnu, 0, TRUE, &mii); return hmnu;}int TestMyWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ HDC hdc; RECT rect1; int iMousePositionX; int iMousePositionY; switch(message){ case MSG_CREATE: if(!InitializeApp()){ DestroyMainWindow (hWnd); PostQuitMessage (hWnd); } break; case MSG_COMMAND: switch(LOWORD(wParam)){ case ID_NEWONE: theApp.bTease = FALSE; OnCommandNewOne(hWnd); InvalidateRect(hWnd,NULL,TRUE); break; case ID_NEWTWO: theApp.bTease = FALSE; OnCommandNewTwo(hWnd); InvalidateRect(hWnd,NULL,TRUE); break; case ID_NEWTWOTEASE: theApp.bTease = FALSE; OnCommandNewTwo(hWnd); OnStartKeyDown(hWnd,theApp.pPlayingWindow1,1); OnStartKeyDown(hWnd,theApp.pPlayingWindow2,2); theApp.bTease = TRUE; InvalidateRect(hWnd,NULL,TRUE); break; case ID_HIGHSCORE: show_snake(hWnd); break; case ID_EXIT: PostMessage(hWnd, MSG_CLOSE, 0, 0); break; case ID_KEYSARRANGE: DialogKeySetting(hWnd); break; case ID_ABOUT: MessageBox(hWnd, "Song Lixin(zjujoe@263.net)\nRussia Square Ver 0.1 (2000/08/04)", "About", MB_OK); break; } break; case MSG_LBUTTONDOWN: iMousePositionX = LOWORD(lParam); iMousePositionY = HIWORD(lParam); return 0; case MSG_PAINT: hdc = BeginPaint(hWnd); OnDraw(hWnd,hdc); EndPaint(hWnd,hdc); return 0; case MSG_KEYDOWN: GetMenuBarItemRect(hWnd,1,&rect1); //syslog(LOG_INFO,"MenuBar:%d,%d,%d,%d",rect1.left,rect1.top,rect1.right,rect1.bottom); if(wParam == theApp.KeySetting1.iKeyRotate){ return OnRotateKeyDown(hWnd,theApp.pPlayingWindow1,1); }else if(wParam == theApp.KeySetting1.iKeyDown){ return OnDownKeyDown(hWnd,theApp.pPlayingWindow1,1); }else if(wParam == theApp.KeySetting1.iKeyLeft){ return OnLeftKeyDown(hWnd,theApp.pPlayingWindow1,1); }else if(wParam == theApp.KeySetting1.iKeyRight){ return OnRightKeyDown(hWnd,theApp.pPlayingWindow1,1); }else if(wParam == theApp.KeySetting1.iKeyStart){ return OnStartKeyDown(hWnd,theApp.pPlayingWindow1,1); }else if(wParam == theApp.KeySetting1.iKeyPause){ return OnPauseKeyDown(hWnd,theApp.pPlayingWindow1,1); // Keys in Playing Windows 2 presswd: }else if(wParam == theApp.KeySetting2.iKeyRotate){ return OnRotateKeyDown(hWnd,theApp.pPlayingWindow2,2); }else if(wParam == theApp.KeySetting2.iKeyDown){ return OnDownKeyDown(hWnd,theApp.pPlayingWindow2,2); }else if(wParam == theApp.KeySetting2.iKeyLeft){ return OnLeftKeyDown(hWnd,theApp.pPlayingWindow2,2); }else if(wParam == theApp.KeySetting2.iKeyRight){ return OnRightKeyDown(hWnd,theApp.pPlayingWindow2,2); }else if(wParam == theApp.KeySetting2.iKeyStart){ return OnStartKeyDown(hWnd,theApp.pPlayingWindow2,2); }else if(wParam == theApp.KeySetting2.iKeyPause){ return OnPauseKeyDown(hWnd,theApp.pPlayingWindow2,2); } return 0; case MSG_TIMER: if(theApp.bBusy) break; if(wParam == RUSSIA_SQUARE_TIMER1){ OnTimer(hWnd,theApp.pPlayingWindow1,1); } else if(wParam == RUSSIA_SQUARE_TIMER2){ OnTimer(hWnd,theApp.pPlayingWindow2,2); } break; case MSG_CLOSE: OnClose(hWnd); return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam);}#if 0 TextOut (hdc, 10, 25, "Russia Square Ver 0.1 (2000/08/04)"); TextOut (hdc, 10, 55, "Author: Mr.Song Lixin(zjujoe@263.net).");#endifvoid InitMyWinCreateInfo(PMAINWINCREATE pCreateInfo){ pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_VISIBLE; pCreateInfo->dwExStyle = WS_EX_NONE; pCreateInfo->spCaption="Russia Square"; pCreateInfo->hMenu = createmenu1(); pCreateInfo->hCursor = GetSystemCursor(0); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = TestMyWinProc; pCreateInfo->lx = 0; pCreateInfo->ty = 0; pCreateInfo->rx = WIDTH_LARGEWIN; pCreateInfo->by = HEIGHT_LARGEWIN; pCreateInfo->iBkColor = COLOR_black; pCreateInfo->dwAddData = 0; pCreateInfo->hHosting = HWND_DESKTOP;}int MiniGUIMain(int args, const char* arg[]){ MSG Msg; MAINWINCREATE CreateInfo; HWND hMainWnd;#if defined(_LITE_VERSION) && !(_STAND_ALONE) int i; const char* layer = NULL; RECT max_rect = {0, 0, 0, 0}; for (i = 1; i < args; i++) { if (strcmp (arg[i], "-layer") == 0) { layer = arg[i + 1]; break; } } GetLayerInfo (layer, &max_rect, NULL, NULL, NULL); if (JoinLayer (layer, arg[0], max_rect.left, max_rect.top, max_rect.left + WIDTH_LARGEWIN, max_rect.top + HEIGHT_LARGEWIN) == INV_LAYER_HANDLE) { printf ("JoinLayer: invalid layer handle.\n"); exit (1); }#else#ifdef _IME_GB2312 GBIMEWindow (HWND_DESKTOP);#endif#endif InitMyWinCreateInfo(&CreateInfo); hMainWnd = CreateMainWindow(&CreateInfo); if (hMainWnd == HWND_INVALID) return -1; ShowWindow(hMainWnd,SW_SHOWNORMAL); while( GetMessage(&Msg, hMainWnd) ) { TranslateMessage (&Msg); DispatchMessage(&Msg); } MainWindowThreadCleanup(hMainWnd); return 0;}BOOL InitializeApp(void){ KeySetting * pKeySetting; openlog("rs",LOG_CONS,LOG_USER); strncpy (theApp.strEtcFilePath, getpwuid (getuid ()) ->pw_dir,MAX_PATH); if (theApp.strEtcFilePath[strlen (theApp.strEtcFilePath) - 1] != '/') strncat (theApp.strEtcFilePath, "/",MAX_PATH); strncat (theApp.strEtcFilePath,".",MAX_PATH); strncat (theApp.strEtcFilePath, ETCFILENAME,MAX_PATH); //syslog(LOG_INFO,"INIT:path:%s",theApp.strEtcFilePath); //initialize keysetting: if(GetValueFromEtcFile(theApp.strEtcFilePath,"HighScoreA","TitleHolder", theApp.HighScore[0].strTitleHolder,50)!=ETC_OK){ strncpy(theApp.HighScore[0].strTitleHolder,"joe",50); } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"HighScoreA","TheScore", &(theApp.HighScore[0].iHighScore))!=ETC_OK){ theApp.HighScore[0].iHighScore = 0; } if(GetValueFromEtcFile(theApp.strEtcFilePath,"HighScoreB","TitleHolder", theApp.HighScore[1].strTitleHolder,50)!=ETC_OK){ strncpy(theApp.HighScore[1].strTitleHolder,"joe",50); } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"HighScoreB","TheScore", &(theApp.HighScore[1].iHighScore))!=ETC_OK){ theApp.HighScore[1].iHighScore = 0; } if(GetValueFromEtcFile(theApp.strEtcFilePath,"HighScoreC","TitleHolder", theApp.HighScore[2].strTitleHolder,50)!=ETC_OK){ strncpy(theApp.HighScore[2].strTitleHolder,"joe",50); } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"HighScoreC","TheScore", &(theApp.HighScore[2].iHighScore))!=ETC_OK){ theApp.HighScore[2].iHighScore = 0; } if(GetValueFromEtcFile(theApp.strEtcFilePath,"HighScoreD","TitleHolder", theApp.HighScore[3].strTitleHolder,50)!=ETC_OK){ strncpy(theApp.HighScore[3].strTitleHolder,"joe",50); } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"HighScoreD","TheScore", &(theApp.HighScore[3].iHighScore))!=ETC_OK){ theApp.HighScore[3].iHighScore = 0; } if(GetValueFromEtcFile(theApp.strEtcFilePath,"HighScoreE","TitleHolder", theApp.HighScore[4].strTitleHolder,50)!=ETC_OK){ strncpy(theApp.HighScore[4].strTitleHolder,"joe",50); } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"HighScoreE","TheScore", &(theApp.HighScore[4].iHighScore))!=ETC_OK){ theApp.HighScore[4].iHighScore = 0; } pKeySetting = &(theApp.KeySetting1); if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadA","Difficulty", &(pKeySetting->iDifficulty))!=ETC_OK){ pKeySetting->iDifficulty = 0; }else{ pKeySetting->iDifficulty %= 10; } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadA","Rotate Key", &(pKeySetting->iKeyRotate))!=ETC_OK){ pKeySetting->iKeyRotate = SCANCODE_W; } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadA","Down Key", &(pKeySetting->iKeyDown))!=ETC_OK){ pKeySetting->iKeyDown = SCANCODE_S; } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadA","Left Key", &(pKeySetting->iKeyLeft))!=ETC_OK){ pKeySetting->iKeyLeft = SCANCODE_A; } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadA","Right Key", &(pKeySetting->iKeyRight))!=ETC_OK){ pKeySetting->iKeyRight = SCANCODE_D; } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadA","Start Key", &(pKeySetting->iKeyStart))!=ETC_OK){ pKeySetting->iKeyStart = SCANCODE_F; } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadA","Pause Key", &(pKeySetting->iKeyPause))!=ETC_OK){ pKeySetting->iKeyPause = SCANCODE_G; } pKeySetting = &(theApp.KeySetting2); if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadB","Difficulty", &(pKeySetting->iDifficulty))!=ETC_OK){ pKeySetting->iDifficulty = 0; }else{ pKeySetting->iDifficulty %= 10; } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadB","Rotate Key", &(pKeySetting->iKeyRotate))!=ETC_OK){ pKeySetting->iKeyRotate = SCANCODE_CURSORBLOCKUP; } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadB","Down Key", &(pKeySetting->iKeyDown))!=ETC_OK){ pKeySetting->iKeyDown = SCANCODE_CURSORBLOCKDOWN; } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadB","Left Key", &(pKeySetting->iKeyLeft))!=ETC_OK){ pKeySetting->iKeyLeft = SCANCODE_CURSORBLOCKLEFT; } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadB","Right Key", &(pKeySetting->iKeyRight))!=ETC_OK){ pKeySetting->iKeyRight = SCANCODE_CURSORBLOCKRIGHT; } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadB","Start Key", &(pKeySetting->iKeyStart))!=ETC_OK){ pKeySetting->iKeyStart = SCANCODE_KEYPAD0; } if(GetIntValueFromEtcFile(theApp.strEtcFilePath,"KeyPadB","Pause Key", &(pKeySetting->iKeyPause))!=ETC_OK){ pKeySetting->iKeyPause = SCANCODE_KEYPADPERIOD; } SaveSettingValue(); return TRUE;}void FreePlayingWindow(HWND hWnd){ PlayingWindow * pPlayingWindow; pPlayingWindow = theApp.pPlayingWindow1; if(pPlayingWindow){ if(pPlayingWindow->pMovingSquare) free(pPlayingWindow->pMovingSquare); if(pPlayingWindow->pPreCreatedSquare) free(pPlayingWindow->pPreCreatedSquare); free(theApp.pPlayingWindow1); KillTimer(hWnd,RUSSIA_SQUARE_TIMER1); } theApp.pPlayingWindow1 = NULL; pPlayingWindow = theApp.pPlayingWindow2; if(pPlayingWindow){ if(pPlayingWindow->pMovingSquare) free(pPlayingWindow->pMovingSquare); if(pPlayingWindow->pPreCreatedSquare) free(pPlayingWindow->pPreCreatedSquare); free(theApp.pPlayingWindow2); KillTimer(hWnd,RUSSIA_SQUARE_TIMER2); } theApp.pPlayingWindow2 = NULL;}void OnCommandNewOne(HWND hWnd){ PlayingWindow * pPlayingWindow; FreePlayingWindow(hWnd); theApp.pPlayingWindow1 = (PlayingWindow*)calloc(1,sizeof(PlayingWindow)); pPlayingWindow = theApp.pPlayingWindow1; pPlayingWindow->iLevel = theApp.KeySetting1.iDifficulty;#ifdef _TIMER_UNIT_10MS SetTimer(hWnd,RUSSIA_SQUARE_TIMER1,1000/TimerFreq[pPlayingWindow->iLevel]);#else SetTimer(hWnd,RUSSIA_SQUARE_TIMER1,TimerFreq[pPlayingWindow->iLevel]);#endif}void OnCommandNewTwo(HWND hWnd){ PlayingWindow * pPlayingWindow; FreePlayingWindow(hWnd); theApp.pPlayingWindow1 = (PlayingWindow*)calloc(1,sizeof(PlayingWindow)); pPlayingWindow = theApp.pPlayingWindow1; pPlayingWindow->iLevel = theApp.KeySetting1.iDifficulty;#ifdef _TIMER_UNIT_10MS SetTimer(hWnd,RUSSIA_SQUARE_TIMER1,1000/TimerFreq[pPlayingWindow->iLevel]);#else SetTimer(hWnd,RUSSIA_SQUARE_TIMER1,TimerFreq[pPlayingWindow->iLevel]);#endif theApp.pPlayingWindow2 = (PlayingWindow*)calloc(1,sizeof(PlayingWindow)); pPlayingWindow = theApp.pPlayingWindow2; pPlayingWindow->iLevel = theApp.KeySetting2.iDifficulty;#ifdef _TIMER_UNIT_10MS SetTimer(hWnd,RUSSIA_SQUARE_TIMER2,1000/TimerFreq[pPlayingWindow->iLevel]);#else SetTimer(hWnd,RUSSIA_SQUARE_TIMER2,TimerFreq[pPlayingWindow->iLevel]);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -