#include <windows.h>
#include "resource.h"
#define BLACK 1
#define WHITE 2
#define RED 3
#define GREEN 4
#define BLUE 5
#define YELLOW 6
#define MAGENTA 7
#define CYAN 8
#define ID_TIMER 9
struct BLOCK
{
BOOL bool;
int color;
}block[22][12];
HBRUSH hRedBrush, hGreenBrush, hBlueBrush, hYellowBrush, hMagentaBrush, hCyanBrush, hBlackBrush, hWhiteBrush;
int m = 21, n = 4, m1 = 21, n1 = 5, m2 = 22, n2 = 5, m3 = 22, n3 = 6, NextBlock = 3, NowBlock = 3, score = 0;
int ChangeBlock0, ChangeBlock1, ChangeBlock2, ChangeBlock3, ChangeBlock4;
int id = 40006, id_Next;
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
VOID SetIsotropic(HDC hdc, int cxClient, int cyClient);
VOID DrawBlock(HDC hdc);
VOID DispatchBlock(VOID);
VOID DispatchBlockColor(VOID);
VOID ChangeBlock(HDC hdc, int q);
VOID ClearupBlock(VOID);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
HWND hwnd;
WNDCLASS wndclass;
MSG msg;
TCHAR szAppName[] = TEXT("WangXiaoQi");
wndclass.style = CS_VREDRAW | CS_HREDRAW;
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hIcon = LoadIcon(NULL, IDI_SHIELD);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("改程序只能在WindowsNT下才能运行!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName,
TEXT("俄罗斯方块!"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
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;
static int cxClient, cyClient;
HMENU hMenu;
int i, j, k, iFileLength;
HANDLE hFile;
PTSTR pstrFileName = TEXT("王小琪.WangXiaoQi");
CHAR pText[500], szBuffer[500];
DWORD dwBytesRead;
switch (message)
{
case WM_CREATE:
hBlackBrush = GetStockObject(BLACK_BRUSH);
hWhiteBrush = GetStockObject(WHITE_BRUSH);
hRedBrush = CreateSolidBrush(RGB(255, 0, 0));
hGreenBrush = CreateSolidBrush(RGB(0, 255, 0));
hBlueBrush = CreateSolidBrush(RGB(0, 255, 0));
hYellowBrush = CreateSolidBrush(RGB(255, 255, 0));
hMagentaBrush = CreateSolidBrush(RGB(255, 0, 255));
hCyanBrush = CreateSolidBrush(RGB(0, 255, 255));
for (i = 0; i <= 22; i++)
{
block[i][0].bool = TRUE;
block[i][11].bool = TRUE;
}
for (i = 0; i <= 11; i++)
block[0][i].bool = TRUE;
if (INVALID_HANDLE_VALUE ==
(hFile = CreateFile(pstrFileName, GENERIC_READ, 0,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)))
{
MessageBox(hwnd, TEXT("打开文件失败, 无法获取文件内的数据!"), TEXT("俄罗斯方块"), MB_ICONERROR);
}
iFileLength = GetFileSize(hFile, NULL);
if (iFileLength == 0)
{
for (i = 1; i <= 20; i++)
for (j = 1; j <= 10; j++)
block[i][j].bool = FALSE;
m = 21; n = 4; m1 = 21; n1 = 5; m2 = 22; n2 = 5; m3 = 22; n3 = 6;
ChangeBlock0 = 0; ChangeBlock1 = 0; ChangeBlock2 = 0; ChangeBlock3 = 0; ChangeBlock4 = 0;
NowBlock = 3;
id = 40004;
score = 0;
}
else
{
ReadFile(hFile, szBuffer, iFileLength, &dwBytesRead, NULL);
k = 0;
for (i = 1; i <= 20; i++)
for (j = 1; j <= 10; j++)
{
if (szBuffer[k] == '1')
block[i][j].bool = TRUE;
if (szBuffer[k] == '0')
block[i][j].bool = FALSE;
k++;
}
k++;
for (i = 1; i <= 20; i++)
for (j = 1; j <= 10; j++)
{
switch (szBuffer[k])
{
case '0':
block[i][j].color = 0; break;
case '3':
block[i][j].color = 3; break;
case '4':
block[i][j].color = 4; break;
case '5':
block[i][j].color = 5; break;
case '6':
block[i][j].color = 6; break;
case '7':
block[i][j].color = 7; break;
case '8':
block[i][j].color = 8; break;
}
k++;
}
k = 402;
m = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
n = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
m1 = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
n1 = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
m2 = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
n2 = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
m3 = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
n3 = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
ChangeBlock0 = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
ChangeBlock1 = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
ChangeBlock2 = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
ChangeBlock3 = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
ChangeBlock4 = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
NowBlock = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
id = atol(&szBuffer[k]);
while (1)
{
if (szBuffer[k] != ' ')
k++;
else
break;
}
k++;
score = atol(&szBuffer[k]);
}
CloseHandle(hFile);
if (id == 40003)
SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG)hWhiteBrush);
if (id == 40004)
{
SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG)hBlackBrush);
}
return 0;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SetIsotropic(hdc, cxClient, cyClient);
if (id == 40003)
SelectObject(hdc, GetStockObject(BLACK_PEN));
else
SelectObject(hdc, GetStockObject(WHITE_PEN));
MoveToEx(hdc, 0, 0, NULL);
LineTo(hdc, 0, 221);
MoveToEx(hdc, 0, 221, NULL);
LineTo(hdc, 111, 221);
MoveToEx(hdc, 111, 0, NULL);
LineTo(hdc, 111, 221);
MoveToEx(hdc, 111, 0, NULL);
LineTo(hdc, 0, 0);
DrawBlock(hdc);
EndPaint(hwnd, &ps);
return 0;
case WM_TIMER:
hdc = GetDC(hwnd);
SetIsotropic(hdc, cxClient, cyClient);
ChangeBlock(hdc, 0);
ReleaseDC(hwnd, hdc);
return 0;
case WM_LBUTTONDOWN:
SetTimer(hwnd, ID_TIMER, 800, NULL);
return 0;
case WM_RBUTTONDOWN:
KillTimer(hwnd, ID_TIMER);
return 0;
case WM_KEYDOWN:
hdc = GetDC(hwnd);
SetIsotropic(hdc, cxClient, cyClient);
switch (LOWORD(wParam))
{
case VK_ESCAPE:
SendMessage(hwnd, WM_CLOSE, 0, 0);
break;
case VK_UP:
ChangeBlock(hdc, 1);
break;
case VK_DOWN:
ChangeBlock(hdc, 0);
break;
case VK_LEFT:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m][n - 1].bool == FALSE && block[m1][n1 - 1].bool == FALSE && block[m2][n2 - 1].bool == FALSE && block[m3][n3 - 1].bool == FALSE)
{
n -= 1; n1 -= 1; n2 -= 1; n3 -= 1;
DispatchBlockColor();
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DrawBlock(hdc);
break;
case VK_RIGHT:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m][n + 1].bool == FALSE && block[m1][n1 + 1].bool == FALSE && block[m2][n2 + 1].bool == FALSE && block[m3][n3 + 1].bool == FALSE)
{
n += 1; n1 += 1; n2 += 1; n3 += 1;
DispatchBlockColor();
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DrawBlock(hdc);
break;
case VK_SPACE:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
while (1)
{
if (block[m - 1][n].bool == FALSE && block[m1 - 1][n1].bool == FALSE && block[m2 - 1][n2].bool == FALSE && block[m3 - 1][n3].bool == FALSE)
{
m -= 1; m1 -= 1; m2 -= 1; m3 -= 1;
}
else
break;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
ChangeBlock(hdc, 0);
break;
}
ReleaseDC(hwnd, hdc);
return 0;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_40001:
hdc = GetDC(hwnd);
SetIsotropic(hdc, cxClient, cyClient);
for (i = 1; i <= 20; i++)
for (j = 1; j <= 10; j++)
block[i][j].bool = FALSE;
SetTimer(hwnd, ID_TIMER, 800, NULL);
score = 0;
DrawBlock(hdc);
ReleaseDC(hwnd, hdc);
break;
case ID_40003:
SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG)hWhiteBrush);
InvalidateRect(hwnd, NULL, TRUE);
id_Next = id;
id = ID_40003;
break;
case 40004:
SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG)hBlackBrush);
InvalidateRect(hwnd, NULL, TRUE);
id_Next = id;
id = ID_40004;
break;
case 40005:
SendMessage(hwnd, WM_CLOSE, 0, 0);
break;
}
return 0;
case WM_MENUSELECT:
hMenu = GetMenu(hwnd);
CheckMenuItem(hMenu, id_Next, MF_UNCHECKED);
CheckMenuItem(hMenu, id, MF_CHECKED);
return 0;
case WM_DESTROY:
KillTimer(hwnd, ID_TIMER);
DeleteObject(hRedBrush);
DeleteObject(hGreenBrush);
DeleteObject(hBlueBrush);
DeleteObject(hYellowBrush);
DeleteObject(hMagentaBrush);
DeleteObject(hCyanBrush);
/*保存数据*/
if (INVALID_HANDLE_VALUE ==
(hFile = CreateFile(pstrFileName, GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL)))
{
return MessageBox(NULL, TEXT("打开文件失败, 无法写入数据"), TEXT("俄罗斯方块"), MB_ICONERROR);
PostQuitMessage(0);
}
k = 0;
for (i = 1; i <= 20; i++)
for (j = 1; j <= 10; j++)
{
if (block[i][j].bool == TRUE)
pText[k++] = '1';
else
pText[k++] = '0';
}
pText[k++] = '\n';
for (i = 1; i <= 20; i++)
for (j = 1; j <= 10; j++)
{
if (block[i][j].bool == TRUE)
{
switch (block[i][j].color)
{
case RED:
pText[k] = '3';
break;
case GREEN:
pText[k] = '4';
break;
case BLUE:
pText[k] = '5';
break;
case YELLOW:
pText[k] = '6';
break;
case MAGENTA:
pText[k] = '7';
break;
case CYAN:
pText[k] = '8';
break;
}
}
else
{
pText[k] = '0';
}
k++;
}
pText[k++] = ' ';
wsprintfA(&pText[k], "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", m, n, m1, n1, m2, n2, m3, n3, ChangeBlock0, ChangeBlock1, ChangeBlock2, ChangeBlock3, ChangeBlock4, NowBlock, id, score);
WriteFile(hFile, pText, (402 + lstrlenA(&pText[k])) * sizeof(CHAR), &dwBytesRead, NULL);
CloseHandle(hFile);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
VOID SetIsotropic(HDC hdc, int cxClient, int cyClient)
{
POINT pt;
SetMapMode(hdc, MM_ISOTROPIC);
SetWindowExtEx(hdc, 200, 224, NULL);
SetViewportExtEx(hdc, cxClient, -cyClient, NULL);
pt.x = cxClient / 2; pt.y = cyClient / 2;
DPtoLP(hdc, &pt, 1);
SetWindowOrgEx(hdc, -pt.x, -pt.y, NULL);
OffsetWindowOrgEx(hdc, 100, 110, NULL);
}
VOID DrawBlock(HDC hdc)
{
HBRUSH hOldBrush;
int i, j;
POINT pt[4];
int a1 = FALSE, a2 = FALSE, a3 = FALSE, a4 = FALSE, a5 = FALSE, a6 = FALSE, a7 = FALSE, a8 = FALSE;
CHAR szBuffer[20];
SelectObject(hdc, GetStockObject(NULL_PEN));
for (i = 1; i <= 20; i++)
{
for (j = 1; j <= 10; j++)
{
if (block[i][j].bool == TRUE)
{
switch (block[i][j].color)
{
case RED:
hOldBrush = SelectObject(hdc, hRedBrush); break;
case GREEN:
hOldBrush = SelectObject(hdc, hGreenBrush); break;
case BLUE:
hOldBrush = SelectObject(hdc, hBlueBrush); break;
case YELLOW:
hOldBrush = SelectObject(hdc, hYellowBrush); break;
case MAGENTA:
hOldBrush = SelectObject(hdc, hMagentaBrush); break;
case CYAN:
hOldBrush = SelectObject(hdc, hCyanBrush); break;
}
pt[0].x = (j - 1) * 10 + j; pt[0].y = (i - 1) * 10 + i;
pt[1].x = pt[0].x; pt[1].y = pt[0].y + 10;
pt[2].x = pt[0].x + 10; pt[2].y = pt[0].y + 10;
pt[3].x = pt[0].x + 10; pt[3].y = pt[0].y;
Polygon(hdc, pt, 4);
SelectObject(hdc, hOldBrush);
}
else
{
if (id == 40003)
hOldBrush = SelectObject(hdc, hWhiteBrush);
if (id == 40004)
hOldBrush = SelectObject(hdc, hBlackBrush);
pt[0].x = (j - 1) * 10 + j; pt[0].y = (i - 1) * 10 + i;
pt[1].x = pt[0].x; pt[1].y = pt[0].y + 10;
pt[2].x = pt[0].x + 10; pt[2].y = pt[0].y + 10;
pt[3].x = pt[0].x + 10; pt[3].y = pt[0].y;
Polygon(hdc, pt, 4);
SelectObject(hdc, hOldBrush);
}
}
}
if (id == 40003)
{
pt[0].x = 120; pt[0].y = 200; pt[1].x = 120; pt[1].y = 179; pt[2].x = 163; pt[2].y = 179; pt[3].x = 163; pt[3].y = 200;
hOldBrush = SelectObject(hdc, hWhiteBrush);
SelectObject(hdc, GetStockObject(NULL_PEN));
Polygon(hdc, &pt, 4);
SetTextColor(hdc, RGB(0, 0, 0));
SetBkColor(hdc, RGB(255, 255, 255));
}
else
{
pt[0].x = 120; pt[0].y = 200; pt[1].x = 120; pt[1].y = 179; pt[2].x = 163; pt[2].y = 179; pt[3].x = 163; pt[3].y = 200;
hOldBrush = SelectObject(hdc, hBlackBrush);
SelectObject(hdc, GetStockObject(NULL_PEN));
Polygon(hdc, &pt, 4);
SetTextColor(hdc, RGB(255, 255, 255));
SetBkColor(hdc, RGB(0, 0, 0));
}
TextOut(hdc, 120, 210, TEXT("NextBlock"), 9);
TextOut(hdc, 120, 40, TEXT("Score:"), 6);
wsprintfA(szBuffer, "%d", score);
TextOutA(hdc, 120, 30, szBuffer, lstrlenA(szBuffer));
switch (NextBlock)
{
case 0:
a1 = FALSE; a2 = FALSE; a3 = FALSE; a4 = FALSE; a5 = TRUE; a6 = TRUE; a7 = TRUE; a8 = TRUE;
hOldBrush = SelectObject(hdc, hRedBrush);
break;
case 1:
a1 = FALSE; a2 = TRUE; a3 = FALSE; a4 = FALSE; a5 = TRUE; a6 = TRUE; a7 = TRUE; a8 = FALSE;
hOldBrush = SelectObject(hdc, hGreenBrush);
break;
case 2:
a1 = TRUE; a2 = FALSE; a3 = FALSE; a4 = FALSE; a5 = TRUE; a6 = TRUE; a7 = TRUE; a8 = FALSE;
hOldBrush = SelectObject(hdc, hBlueBrush);
break;
case 3:
a1 = FALSE; a2 = TRUE; a3 = TRUE; a4 = FALSE; a5 = TRUE; a6 = TRUE; a7 = FALSE; a8 = FALSE;
hOldBrush = SelectObject(hdc, hYellowBrush);
break;
case 4:
a1 = TRUE; a2 = TRUE; a3 = FALSE; a4 = FALSE; a5 = FALSE; a6 = TRUE; a7 = TRUE; a8 = FALSE;
hOldBrush = SelectObject(hdc, hMagentaBrush);
break;
case 5:
a1 = TRUE; a2 = TRUE; a3 = FALSE; a4 = FALSE; a5 = TRUE; a6 = TRUE; a7 = FALSE; a8 = FALSE;
hOldBrush = SelectObject(hdc, hCyanBrush);
break;
}
if (a1 == TRUE)
{
pt[0].x = 120; pt[0].y = 200; pt[1].x = 120; pt[1].y = 190; pt[2].x = 130; pt[2].y = 190; pt[3].x = 130; pt[3].y = 200;
Polygon(hdc, &pt, 4);
}
if (a2 == TRUE)
{
pt[0].x = 131; pt[0].y = 200; pt[1].x = 131; pt[1].y = 190; pt[2].x = 141; pt[2].y = 190; pt[3].x = 141; pt[3].y = 200;
Polygon(hdc, &pt, 4);
}
if (a3 == TRUE)
{
pt[0].x = 142; pt[0].y = 200; pt[1].x = 142; pt[1].y = 190; pt[2].x = 152; pt[2].y = 190; pt[3].x = 152; pt[3].y = 200;
Polygon(hdc, &pt, 4);
}
if (a4 == TRUE)
{
pt[0].x = 153; pt[0].y = 200; pt[1].x = 153; pt[1].y = 190; pt[2].x = 163; pt[2].y = 190; pt[3].x = 163; pt[3].y = 200;
Polygon(hdc, &pt, 4);
}
if (a5 == TRUE)
{
pt[0].x = 120; pt[0].y = 189; pt[1].x = 120; pt[1].y = 179; pt[2].x = 130; pt[2].y = 179; pt[3].x = 130; pt[3].y = 189;
Polygon(hdc, &pt, 4);
}
if (a6 == TRUE)
{
pt[0].x = 131; pt[0].y = 189; pt[1].x = 131; pt[1].y = 179; pt[2].x = 141; pt[2].y = 179; pt[3].x = 141; pt[3].y = 189;
Polygon(hdc, &pt, 4);
}
if (a7 == TRUE)
{
pt[0].x = 142; pt[0].y = 189; pt[1].x = 142; pt[1].y = 179; pt[2].x = 152; pt[2].y = 179; pt[3].x = 152; pt[3].y = 189;
Polygon(hdc, &pt, 4);
}
if (a8 == TRUE)
{
pt[0].x = 153; pt[0].y = 189; pt[1].x = 153; pt[1].y = 179; pt[2].x = 163; pt[2].y = 179; pt[3].x = 163; pt[3].y = 189;
Polygon(hdc, &pt, 4);
}
}
VOID DispatchBlock(VOID)
{
int i;
NextBlock = rand() % 6;
}
VOID DispatchBlockColor(VOID)
{
switch (NowBlock)
{
case 0:
block[m][n].color = RED; block[m1][n1].color = RED; block[m2][n2].color = RED; block[m3][n3].color = RED;
break;
case 1:
block[m][n].color = GREEN; block[m1][n1].color = GREEN; block[m2][n2].color = GREEN; block[m3][n3].color = GREEN;
break;
case 2:
block[m][n].color = BLUE; block[m1][n1].color = BLUE; block[m2][n2].color = BLUE; block[m3][n3].color = BLUE;
break;
case 3:
block[m][n].color = YELLOW; block[m1][n1].color = YELLOW; block[m2][n2].color = YELLOW; block[m3][n3].color = YELLOW;
break;
case 4:
block[m][n].color = MAGENTA; block[m1][n1].color = MAGENTA; block[m2][n2].color = MAGENTA; block[m3][n3].color = MAGENTA;
break;
case 5:
block[m][n].color = CYAN; block[m1][n1].color = CYAN; block[m2][n2].color = CYAN; block[m3][n3].color = CYAN;
break;
}
}
VOID ChangeBlock(HDC hdc, int q)
{
VOID ClearupBlock(VOID);
static int time = 1;
if (q == 0)
{
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m - 1][n].bool == FALSE && block[m1 - 1][n1].bool == FALSE && block[m2 - 1][n2].bool == FALSE && block[m3 - 1][n3].bool == FALSE)
{
m -= 1; m1 -= 1; m2 -= 1; m3 -= 1;
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
if (time == 1)
DispatchBlock();
time = 0;
}
else
{
time = 1;
ChangeBlock0 = 0; ChangeBlock1 = 0; ChangeBlock2 = 0; ChangeBlock3 = 0; ChangeBlock4 = 0;
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
ClearupBlock();
DrawBlock(hdc);
NowBlock = NextBlock;
switch (NowBlock)
{
case 0:
m = 21; n = 4; m1 = 21; n1 = 5; m2 = 21; n2 = 6; m3 = 21; n3 = 7;
break;
case 1:
m = 21; n = 4; m1 = 21; n1 = 5; m2 = 21; n2 = 6; m3 = 22; n3 = 5;
break;
case 2:
m = 22; n = 4; m1 = 21; n1 = 4; m2 = 21; n2 = 5; m3 = 21; n3 = 6;
break;
case 3:
m = 21; n = 4; m1 = 21; n1 = 5; m2 = 22; n2 = 5; m3 = 22; n3 = 6;
break;
case 4:
m = 22; n = 4; m1 = 22; n1 = 5; m2 = 21; n2 = 5; m3 = 21; n3 = 6;
break;
case 5:
m = 21; n = 4; m1 = 22; n1 = 4; m2 = 21; n2 = 5; m3 = 22; n3 = 5;
break;
}
}
}
if (q == 1)
{
switch (NowBlock)
{
case 0:
switch (ChangeBlock0)
{
case 0:
block[m][n].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE; block[m1][n1].bool = FALSE;
if (block[m1 - 1][n1].bool == FALSE && block[m1 + 1][n1].bool == FALSE && block[m1 + 2][n1].bool == FALSE)
{
m = m1 - 1; m2 = m1 + 1; m3 = m1 + 2;
n = n2 = n3 = n1;
ChangeBlock0 = 1;
}
block[m][n].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE; block[m1][n1].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
case 1:
block[m][n].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE; block[m1][n1].bool = FALSE;
if (block[m1][n1 - 1].bool == FALSE && block[m1][n1 + 1].bool == FALSE && block[m1][n1 + 2].bool == FALSE)
{
m = m2 = m3 = m1;
n = n1 - 1; n2 = n1 + 1; n3 = n1 + 2;
ChangeBlock0 = 0;
}
block[m][n].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE; block[m1][n1].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
}
break;
case 1:
switch (ChangeBlock1)
{
case 0:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m1 - 1][n1].bool == FALSE)
{
m = m1 - 1; m2 = m1 + 1; m3 = m1;
n = n2 = n1; n3 = n1 + 1;
ChangeBlock1 = 1;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
case 1:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m1][n1 - 1].bool == FALSE)
{
m = m2 = m1; m3 = m1 - 1;
n = n1 - 1; n2 = n1 + 1; n3 = n1;
ChangeBlock1 = 2;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
case 2:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m1 + 1][n1].bool == FALSE)
{
m = m1; m2 = m1 - 1; m3 = m1 + 1;
n = n1 - 1; n2 = n3 = n1;
ChangeBlock1 = 3;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
case 3:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m1][n1 + 1].bool == FALSE)
{
m = m2 = m1; m3 = m1 + 1;
n = n1 - 1; n2 = n1 + 1; n3 = n1;
ChangeBlock1 = 0;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
}
break;
case 2:
switch (ChangeBlock2)
{
case 0:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m1 - 1][n1].bool == FALSE && block[m1 - 2][n1].bool == FALSE)
{
m = m1; n = n1 + 1;
m2 = m1 - 1; n2 = n1;
m3 = m1 - 2; n3 = n1;
ChangeBlock2 = 1;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
case 1:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m1][n1 - 1].bool == FALSE && block[m1][n1 - 2].bool == FALSE && n1 - 2 >= 1)
{
m = m1 - 1; n = n1;
m2 = m1; n2 = n1 - 1;
m3 = m1; n3 = n1 - 2;
ChangeBlock2 = 2;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
case 2:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m1 + 1][n1].bool == FALSE && block[m1 + 2][n1].bool == FALSE)
{
m = m1; n = n1 - 1;
m2 = m1 + 1; n2 = n1;
m3 = m1 + 2; n3 = n1;
ChangeBlock2 = 3;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
case 3:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m1][n1 + 1].bool == FALSE && block[m1][n1 + 2].bool == FALSE && n1 + 2 <= 10)
{
m = m1 + 1; n = n1;
m2 = m1; n2 = n1 + 1;
m3 = m1; n3 = n1 + 2;
ChangeBlock2 = 0;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
}
break;
case 3:
switch (ChangeBlock3)
{
case 0:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m1][n1 + 1].bool == FALSE && block[m1 - 1][n1 + 1].bool == FALSE)
{
m = m1 + 1; n = n1;
m2 = m1; n2 = n1 + 1;
m3 = m1 - 1; n3 = n1 + 1;
ChangeBlock3 = 1;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
case 1:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m1][n1 - 1].bool == FALSE && block[m1 + 1][n1 + 1].bool == FALSE)
{
m = m1; n = n1 - 1;
m2 = m1 + 1; n2 = n1;
m3 = m1 + 1; n3 = n1 + 1;
ChangeBlock3 = 0;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
}
break;
case 4:
switch (ChangeBlock4)
{
case 0:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m2 - 1][n2].bool == FALSE && block[m2 + 1][n2 + 1].bool == FALSE)
{
m = m2 - 1; n = n2;
m1 = m2; n1 = n2 + 1;
m3 = m2 + 1; n3 = n2 + 1;
ChangeBlock4 = 1;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
case 1:
block[m][n].bool = FALSE; block[m1][n1].bool = FALSE; block[m2][n2].bool = FALSE; block[m3][n3].bool = FALSE;
if (block[m2 + 1][n2].bool == FALSE && block[m2 + 1][n2 - 1].bool == FALSE)
{
m = m2 + 1; n = n2 - 1;
m1 = m2 + 1; n1 = n2;
m3 = m2; n3 = n2 + 1;
ChangeBlock4 = 0;
}
block[m][n].bool = TRUE; block[m1][n1].bool = TRUE; block[m2][n2].bool = TRUE; block[m3][n3].bool = TRUE;
DispatchBlockColor();
DrawBlock(hdc);
break;
}
break;
}
}
}
VOID ClearupBlock(VOID)
{
int i, j, k = 0;
int p, q;
for (i = 1; i <= 20; i++)
{
k = 0;
for (j = 1; j <= 10; j++)
{
if (block[i][j].bool == TRUE)
k++;
else
break;
}
if (k == 10)
{
for (p = i; p <= 20; p++)
for (q = 1; q <= 10; q++)
block[p][q] = block[p + 1][q];
score += 100;
}
k = 0;
for (j = 1; j <= 10; j++)
{
if (block[i][j].bool == TRUE)
k++;
else
break;
}
if (k == 10)
{
for (p = i; p <= 20; p++)
for (q = 1; q <= 10; q++)
block[p][q] = block[p + 1][q];
score += 100;
}
k = 0;
for (j = 1; j <= 10; j++)
{
if (block[i][j].bool == TRUE)
k++;
else
break;
}
if (k == 10)
{
for (p = i; p <= 20; p++)
for (q = 1; q <= 10; q++)
block[p][q] = block[p + 1][q];
score += 100;
}
k = 0;
for (j = 1; j <= 10; j++)
{
if (block[i][j].bool == TRUE)
k++;
else
break;
}
if (k == 10)
{
for (p = i; p <= 20; p++)
for (q = 1; q <= 10; q++)
block[p][q] = block[p + 1][q];
score += 100;
}
}
}