#include "stdafx.h"
#include "resource.h"
HINSTANCE g_hInst = NULL;
HBITMAP g_hBmMine = NULL;
HBITMAP g_BitFace = NULL;
HBITMAP g_BitNumber = NULL;
HANDLE g_output = NULL;
int g_Flag[100][100] = {0};
int g_Bit[100][100] = {0};
int g_FaceNUM = 0;
int g_Number1 = 0;
int g_Number2 = 0;
int g_Number3 = 0;
int g_Number_1 = 0;
int g_Number_2 = 0;
int g_Number_3 = 0;
int g_TimeCount = 0;
int g_Heigth = 0;
int g_Width = 0;
BOOL b_IfFace = FALSE;
BOOL IsLoadMine = FALSE;
BOOL IsOver = FALSE;
BOOL timer = FALSE;
CHAR szText[256] = {0};
int nXClient = 9;
int nYClient = 9;
int nMaxMine = 10;
VOID CALLBACK TestTimerProc(HWND hwnd,
UINT nMsg,
UINT idEvent,
DWORD dwTim)
{
g_TimeCount++;
g_Number_1--;
if (g_Number_1 <= 1)
{
g_Number_2--;
g_Number_1 = 12;
g_Number_1--;
if (g_Number_2 <= 1)
{
g_Number_3--;
g_Number_2 = 12;
g_Number_1 = 12;
g_Number_1--;
}
}
InvalidateRect(hwnd, NULL, FALSE);
}
//初始化
void OnCreate(HWND hwnd)
{
KillTimer(hwnd, 100);
b_IfFace = FALSE;
IsLoadMine = FALSE;
IsOver = FALSE;
timer = FALSE;
//加载位图
g_hBmMine = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_MINE));
g_BitFace = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_FACE));
g_BitNumber = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_NUMBER));
g_FaceNUM = 4;
g_Number_1 = 11;
g_Number_2 = 11;
g_Number_3 = 11;
//初始化位图
for (int nxIndex = 0; nxIndex < nXClient; nxIndex++)
{
for (int nyIndex = 0; nyIndex < nYClient; nyIndex++)
{
g_Flag[nxIndex][nyIndex] = IDBITNUM_INIT;
g_Bit[nxIndex][nyIndex] = IDBITNUM_INIT;
}
}
//初始化雷区
int row, clm;
srand((unsigned)GetTickCount());
for (int nIndex = 0; nIndex < nMaxMine; nIndex++)
{
row = rand() % nXClient;
clm = rand() % nYClient;
while (g_Flag[row][clm] == IDBITNUM_MINE)
{
row = rand() % nXClient;
clm = rand() %nYClient;
}
g_Flag[row][clm] = IDBITNUM_MINE;
}
}
//转换数字
int cToNumber(CHAR * lParma, int *nint)
{
CHAR str[256] = {0};
int i, j, num = 0, p = 0;
for (i = 0; i < 10; ++i)
{
sprintf(str, "%s", lParma);
if (i == 0 && (str[0] == '-' || str[0] == '+'))
{
p = 1;
continue;
}
if (str[i] > '9' || str[i] <'0') break;
}
for (j = p; j < i; ++j)
num = num * 10 + str[j] - '0';
if (str[0] == '-')
num = -num;
nint = #
return *nint;
}
//处理自定义窗口信息
void OnDLGCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
int flag = 0;
RECT rect;
HWND p_hwnd = GetParent(hwnd);
GetWindowRect(p_hwnd, &rect);
CHAR DlgText[256] = {0};
switch (LOWORD(wParam))
{
case IDOK:
SendDlgItemMessage(hwnd, ID_EDITHEITH, WM_GETTEXT, 5, (LPARAM)DlgText);
nYClient = cToNumber(DlgText, 0);
if (nYClient > 0 && nYClient <= 39);
else
nYClient = 10, flag = 1;
SendDlgItemMessage(hwnd, ID_EDITWIDTH, WM_GETTEXT, 5, (LPARAM)DlgText);
nXClient = cToNumber(DlgText, 0);
if (nXClient > 0 && nXClient <= 62);
else
nXClient = 10, flag = 1;
SendDlgItemMessage(hwnd, ID_EDITMINE, WM_GETTEXT, 5, (LPARAM)DlgText);
nMaxMine = cToNumber(DlgText, 0);
if (nMaxMine > 0 && nMaxMine <= nXClient * nYClient);
else
nMaxMine = 10, flag = 1;
if (flag == 1)
MessageBox(NULL, "你丫连100以内的非零自然数都输入不对,脑残片吃多了吧!好好看说明书去。", "你脑残吧!!!", MB_OK);
MoveWindow(p_hwnd, rect.left, rect.top, nXClient * 16 + 36,
nYClient * 16 + 126, TRUE);
OnCreate(p_hwnd);
InvalidateRgn(p_hwnd, NULL, TRUE);
EndDialog(hwnd, 100);
break;
case IDCANCEL:
EndDialog(hwnd, 100);
break;
}
}
BOOL CALLBACK ModalProc(HWND hwnd,
UINT nMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (nMsg)
{
case WM_COMMAND:
OnDLGCommand(hwnd, wParam, lParam);
break;
case WM_SYSCOMMAND:
if (SC_CLOSE == wParam)
{
EndDialog(hwnd, 100);
}
}
return 0;
}
//获得窗口信息
void OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
g_Width = LOWORD(lParam);
g_Heigth = HIWORD(lParam);
}
//显示自定义
void OnModal(HWND hwnd, WPARAM wParam)
{
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_SETTING), hwnd, ModalProc);
}
void OnAbout(HWND hwnd, WPARAM wParam)
{
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_ABOUT), hwnd, ModalProc);
}
void FindMine1(int x, int y)
{
if ((x < nXClient && y < nYClient) && (x >= 0 && y >= 0))
{
if (g_Flag[x][y] == 0)
{
g_Flag[x][y] = IDBITNUM_SPASE;
g_Bit[x][y] = IDBITNUM_SPASE;
FindMine1(x + 1, y);
FindMine1(x - 1, y);
FindMine1(x, y + 1);
FindMine1(x, y - 1);
FindMine1(x + 1, y - 1);
FindMine1(x - 1, y - 1);
FindMine1(x + 1, y + 1);
FindMine1(x - 1, y + 1);
}
else if (g_Flag[x][y] != IDBITNUM_MINE)
{
g_Bit[x][y] = g_Flag[x][y];
}
}
return;
}
//背景
void FindMine(int x, int y)
{
for (int row = 0; row < nXClient; row++)
{
for (int clm = 0; clm < nYClient; clm++)
{
if (g_Flag[row][clm] == IDBITNUM_INIT)
{
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
if (g_Flag[row - 1 + i][clm - 1 + j] == IDBITNUM_MINE)
{
g_Flag[row][clm]++;
}
}
}
}
}
}
FindMine1(x, y);
}
void IsMine()
{
for (int row = 0; row < nXClient; row++)
{
for (int clm = 0; clm < nYClient; clm++)
{
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
if (g_Flag[row - 1 + i][clm - 1 + j] == IDBITNUM_MINE)
{
g_Bit[row - 1 + i][clm - 1 + j] = g_Flag[row - 1 + i][clm - 1 + j];
}
}
}
if (g_Flag[row][clm] == IDBITNUM_MINE)
g_Bit[row][clm] = g_Flag[row][clm];
else
if (g_Flag[row][clm] != IDBITNUM_MINE && g_Bit[row][clm] == 14)
g_Bit[row][clm] = 12;
}
}
IsOver = TRUE;
}
//菜单
void OnCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
UINT nNotyfiyCode = HIWORD(wParam);
UINT nID = LOWORD(wParam);
RECT rect;
GetWindowRect(hwnd, &rect);
switch (nID)
{
case ID_EXIT:
PostQuitMessage(0);
break;
case ID_START:
OnCreate(hwnd);
InvalidateRgn(hwnd, N
LLawliet
- 粉丝: 20
- 资源: 1