📄 fivechess.c
字号:
PostMessage(my_hwnd,WM_CLOSE,0,0);
} // end if
// return success or failure or your own return code here
return(1);
} // end Game_Main
////////////////////////////////////////////////////////////
void Update_all()
{
int i = 0, j = 0;
HDC hDC;
InvalidateRect(my_hwnd,NULL,0);
hDC=BeginPaint(my_hwnd);
// FillBoxWithBitmap(hDC,0,0,376,376, &h_map);
DrawMyBitmap(hDC, &h_map, 0,0,376,376);
DrawMyBitmap(HDC_SCREEN, &h_map, 0,0,376,376);
for(i=0;i<15;i++)
{
for(j=0;j<15;j++)
{
if( bb[i][j].stat==1)
{
FillBoxWithBitmap(hDC, xx[j],xx[i], 21, 21, &h_back);
}
else if( bb[i][j].stat==2)
{
FillBoxWithBitmap(hDC, xx[j],xx[i], 21, 21, &h_white);
}
}
}
EndPaint(my_hwnd, hDC);
}
int Game_Init()
{
int i = 0, j = 0;
for( i=0;i<15;i++)
{for( j=0;j<15;j++)
{
bb[i][j].stat=0;
}
xx[i]=8+i*24;
}
Update_all();
return(1);
} // end Game_Init
/////////////////////////////////////////////////////////////
int Game_Shutdown()
{
return(1);
} // end Game_Shutdown
LRESULT CALLBACK lpfn_P_WIN_DialProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{switch(msg)
{ case WM_INITDIALOG:
{//SendMessage(hDlg,BM_SETCHECK,BST_CHECKED,233);
}break;
case WM_COMMAND:
{EndDialog(hDlg,TRUE);
}break;
default:
{
}break;
}
return(0);
}
LRESULT CALLBACK lpfn_C_WIN_DialProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{switch(msg)
{ case WM_INITDIALOG:
{//SendMessage(hDlg,BM_SETCHECK,BST_CHECKED,233);
}break;
case WM_COMMAND:
{EndDialog(hDlg,TRUE);
}break;
default:
{
}break;
}
return(0);
}
LRESULT CALLBACK lpfnAboutDialProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{switch(msg)
{ case WM_INITDIALOG:
{//SendMessage(hDlg,BM_SETCHECK,BST_CHECKED,233);
}break;
case WM_LBUTTONDOWN:
{
EndDialog(hDlg,TRUE);
return(0);
} break;
case WM_COMMAND:
{EndDialog(hDlg,TRUE);
}break;
default:
{
}break;
}
return(0);
}
LRESULT CALLBACK lpfnSelectDialProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{switch(msg)
{ case WM_INITDIALOG:
{
//SendMessage(hDlg,BM_SETCHECK,BST_CHECKED,200);
}break;
case WM_COMMAND:
{
switch (wParam)
{
case ME_FIRST://玩家先下---------------------------
{Game_Init();
EndDialog(hDlg,TRUE);
return (0);
}break;
case COMPUTER_FIRST://电脑先下----------------------------
{Game_Init();
bb[7][7].stat=2;
Pain_white(7,7);
EndDialog(hDlg,TRUE);
return (0);
}break;
default:
break;
}
}break;
default:
break;
}
return(0);
}
int WindowProc(HWND hwnd,
int msg,
WPARAM wparam,
LPARAM lparam)
{
//PAINTSTRUCT ps; // used in WM_PAINT
HDC hdc; // handle to a device context
//char buffer[80]; // used to print strings
my_hwnd=hwnd;
// what is the message
switch(msg)
{
case WM_CREATE:
{
LoadBitmap(HDC_SCREEN, &h_map, my_map);
LoadBitmap(HDC_SCREEN, &h_white, my_white);
LoadBitmap(HDC_SCREEN, &h_back, my_back);
h_white.bmType |= BMP_TYPE_COLORKEY;
h_white.bmColorKey = 0xfcfcfc;
h_back.bmType |= BMP_TYPE_COLORKEY;
h_back.bmColorKey = 0xffffff;
Game_Init();
return(0);
} break;
case WM_LBUTTONDOWN:
{int flag=0;
mouse_x=(int)LOWORD(lparam);
mouse_y=(int)HIWORD(lparam);
if(My_work(mouse_x,mouse_y)==0)//如返回的是0,则说明玩家没有走,
return (0);//则六即返回,让玩家重新输入
if(Check_win()==1)//玩家赢了
{
//DialogBox(my_hinstance,(LPCTSTR)"P_WIN_DIALOG",my_hwnd,(DLGPROC)lpfn_P_WIN_DialProc);
MessageBox(hwnd, "你胜了!!!-----牛人!!", "五子棋", 0);
Game_Init();
}
Computer_think();
Computer_work();
if(Check_win()==2)// 电脑赢了
{
//DialogBox(my_hinstance,(LPCTSTR)"C_WIN_DIALOG",my_hwnd,(DLGPROC)lpfn_C_WIN_DialProc);
MessageBox(hwnd, "你输了!!!-----再来吧!!", "五子棋", 0);
Game_Init();
}
return (0);
}break;
// case WM_ACTIVATE:
case WM_SIZE:
{
// InvalidateRect(my_hwnd,NULL,FALSE);
// Update_all();
}
break;
case WM_PAINT:
{
// simply validate the window
hdc = BeginPaint(hwnd);
TextOut (hdc, 10, 25, "Bomb Game Ver 1.0 (2000/04/11)");
Rectangle(hdc, 100, 100, 200, 200);
Update_all();
// end painting
EndPaint(hwnd, hdc);
// return success
return(0);
} break;
case WM_COMMAND:
{
switch(LOWORD(wparam))
{
case GAME_OVER:
{
// PostQuitMessage(0);
if(MessageBox(hwnd, "你确认退出吗?", "五子棋", MB_OK | MB_OKCANCEL | MB_ICONQUESTION) == IDOK)
DestroyMainWindow (hwnd);
// PostMessage(hwnd, WM_CLOSE, 0, 0);
}break;
case GAME_ABOUT:
{
MessageBox(hwnd, "作者:侯辉华\nQQ:106719880\n邮箱:coolhealth1@163.com\n有什么好的意见,请与我联系,谢谢!!", "五子棋", 0);
//DialogBox(my_hinstance,(LPCTSTR)"DIALOG_2",my_hwnd,(DLGPROC)lpfnAboutDialProc);
}break;
case GAME_BEGAIN:
{
if(MessageBox(hwnd, "新游戏?", "五子棋", MB_OK | MB_OKCANCEL | MB_ICONQUESTION) == IDOK)
Game_Init();
// DialogBox(my_hinstance,(LPCTSTR)"DIALOG_1",my_hwnd,(DLGPROC)lpfnSelectDialProc);
}break;
}//----end---switch----------
}break;
case WM_CLOSE:
UnloadBitmap(&h_map);
UnloadBitmap(&h_back);
UnloadBitmap(&h_white);
DestroyMainWindow (hwnd);
PostQuitMessage (hwnd);
return 0;
default:break;
} // end switch
// process any messages that we didn't take care of
return (DefaultMainWinProc(hwnd, msg, wparam, lparam));
} // end WinProc
// WINMAIN ////////////////////////////////////////////////
/*int WINAPI WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
int WINAPI WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
WNDCLASSEX winclass; // this will hold the class we create
HWND hwnd; // generic window handle
MSG msg; // generic message
HDC hdc; // graphics device context
// first fill in the window class stucture
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL ,IDC_ARROW );
winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
winclass.lpszMenuName = "MAIN_MENU";
winclass.lpszClassName = WINDOW_CLASS_NAME;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// save hinstance in global
my_hinstance = hinstance;
// register the window class
if (!RegisterClassEx(&winclass))
return(0);
// create the window
if (!(hwnd = CreateWindowEx(NULL, // extended style
WINDOW_CLASS_NAME, // class
"一发不可收拾", // title
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100,100, // initial x,y
WINDOW_WIDTH,WINDOW_HEIGHT, // initial width, height
NULL, // handle to parent
NULL, // handle to menu
hinstance,// instance of this application
NULL))) // extra creation parms
return(0);
// save main window handle
my_hwnd = hwnd;
// initialize game here
Game_Init();
// enter main event loop
while(TRUE)
{
// test if there is a message in queue, if so get it
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
// test if this is a quit
if (msg.message == WM_QUIT)
break;
// translate any accelerator keys
TranslateMessage(&msg);
// send the message to the window proc
DispatchMessage(&msg);
} // end if
// main game processing goes here
Game_Main();
} // end while
// closedown game here
Game_Shutdown();
// return to Windows like this
return(msg.wParam);
} // end WinMain
*/
///////////////////////////////////////////////////////////
HMENU createpmenustart_chess(void)
{
HMENU hmnu;
MENUITEMINFO mii;
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING;
mii.id = 0;
mii.typedata = (DWORD)"游戏";
hmnu = CreatePopupMenu (&mii);
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING ;
mii.state = 0;
mii.id = GAME_BEGAIN;
mii.typedata = (DWORD)"新游戏";
InsertMenuItem(hmnu, 0, TRUE, &mii);
mii.type = MFT_STRING ;
mii.state = 0;
mii.id = GAME_OVER;
mii.typedata = (DWORD)"退出游戏";
InsertMenuItem(hmnu, 1, TRUE, &mii);
return hmnu;
}
HMENU createpmenuabout_chess(void)
{
HMENU hmnu;
MENUITEMINFO mii;
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING;
mii.id = 0;
mii.typedata = (DWORD)"关于";
hmnu = CreatePopupMenu (&mii);
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING ;
mii.state = 0;
mii.id = GAME_ABOUT;
mii.typedata = (DWORD)"关于五子棋";
InsertMenuItem(hmnu, 3, TRUE, &mii);
return hmnu;
}
HMENU createmenu_chess(void)
{
HMENU hmnu;
MENUITEMINFO mii;
hmnu = CreateMenu();
memset (&mii, 0, sizeof(MENUITEMINFO));
mii.type = MFT_STRING;
mii.id = 100;
mii.typedata = (DWORD)"游戏";
mii.hsubmenu = createpmenustart_chess();
InsertMenuItem(hmnu, 0, TRUE, &mii);
mii.type = MFT_STRING;
mii.id = 110;
mii.typedata = (DWORD)"关于";
mii.hsubmenu = createpmenuabout_chess();
InsertMenuItem(hmnu, 2, TRUE, &mii);
return hmnu;
}
void InitFiveChessCreateInfo(HWND hwnd, PMAINWINCREATE pCreateInfo)
{
// WS_BORDER | WS_CAPTION;
pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_VISIBLE;
pCreateInfo->dwExStyle = WS_EX_NONE;
pCreateInfo->spCaption="五子棋之MinuGui版...";
pCreateInfo->hMenu = createmenu_chess();
pCreateInfo->hCursor = GetSystemCursor(0);
pCreateInfo->hIcon = 0;
pCreateInfo->MainWindowProc = WindowProc;
pCreateInfo->lx = 100;
pCreateInfo->ty = 100;
// pCreateInfo->rx = WIDTH_LARGEWIN;
// pCreateInfo->by = HEIGHT_LARGEWIN;
pCreateInfo->rx = 100+WINDOW_WIDTH;
pCreateInfo->by = 100+WINDOW_HEIGHT;
pCreateInfo->iBkColor = COLOR_lightgray;
pCreateInfo->dwAddData = 0;
// pCreateInfo->hHosting = HWND_DESKTOP;
pCreateInfo->hHosting = hwnd;
}
/*
#ifdef _LITE_VERSION
int MiniGUIMain(int args, const char* arg[])
#else
void* TestMyWindow(void* data)
#endif
{
MSG Msg;
MAINWINCREATE CreateInfo;
HWND hMainWnd;
#ifdef _LITE_VERSION
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 + 1024,
max_rect.top + 768) == INV_LAYER_HANDLE) {
printf ("JoinLayer: invalid layer handle.\n");
exit (1);
}
#endif
// InitMyWinCreateInfo(&CreateInfo);
InitFiveChessCreateInfo(NULL, &CreateInfo);
hMainWnd = CreateMainWindow(&CreateInfo);
if (hMainWnd == HWND_INVALID)
#ifdef _LITE_VERSION
return 0;
#else
return NULL;
#endif
ShowWindow(hMainWnd,SW_SHOWNORMAL);
while( GetMessage(&Msg, hMainWnd) ) {
TranslateMessage (&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup(hMainWnd);
#ifdef _LITE_VERSION
return 0;
#else
return NULL;
#endif
}
#ifndef _LITE_VERSION
int MiniGUIMain(int args, const char* arg[])
{
pthread_t imethread;
CreateThreadForMainWindow (&imethread, NULL, IMEWindow, 0);
TestMyWindow (NULL);
return 0;
}
#endif
*/
int MiniGUIMain_f(int argc, const char* argv[])
{
MSG Msg;
HWND hMainWnd;
MAINWINCREATE CreateInfo;
#ifdef _LITE_VERSION
SetDesktopRect(0, 0, 1024, 768);
#endif
InitFiveChessCreateInfo(HWND_DESKTOP, &CreateInfo);
hMainWnd = CreateMainWindow(&CreateInfo);
printf ("The main window created.\n");
if (hMainWnd == HWND_INVALID)
return -1;
ShowWindow(hMainWnd, SW_SHOWNORMAL);
printf ("The main window showed.\n");
while (GetMessage(&Msg, hMainWnd)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup (hMainWnd);
return 0;
}
#ifndef _LITE_VERSION
#include <minigui/dti.c>
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -