// 俄罗斯方块.cpp : 定义应用程序的入口点。
//
#include "stdafx.h"
#include "俄罗斯方块A.h"
#include
#include
#pragma comment(lib, "WINMM.LIB")
#define LEFT VK_LEFT
#define RIGHT VK_RIGHT
#define DOWN VK_DOWN
#define UP VK_UP
#define LEVEL1 1000
#define LEVEL2 500
#define LEVEL3 200
#define LEVEL4 100
RUS rus;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
void time1(UINT);
void PUSEGAME();
void GoOn();
void ReStartGame();
HINSTANCE hInst;
UINT Time=1000;
int num=1;//控制消行时的闪烁次数
HWND hWnd;
int LINE=0;//用于gameover后刷屏
bool Mm=0;//当难度更改后重画难度的显示区域
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevinstance,PSTR szCmdLine,int iCmdShow)
{
static TCHAR szAppName[]=TEXT("hello windows 7");
HWND hwnd;
MSG msg;
HACCEL hAccelTable;
WNDCLASS wndclass;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=MAKEINTRESOURCE(IDC_A);
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_A));
wndclass.lpszClassName=szAppName;
RegisterClassW(&wndclass);
hInst=hInstance;
hwnd=CreateWindow(szAppName,TEXT("Display"),WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,CW_USEDEFAULT,CW_USEDEFAULT,365,465,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
rus.Initialize_MAP();
rus.Initialize_OBJECT();
rus.InitializeXY();
rus.CheckDownWhite();
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
bool IsMoveRight=false,IsMoveLeft=false,IsMoveVertical=true,IsDeformation=false,puse=false,IsShining=false;int mm=1;
LRESULT CALLBACK WndProc(HWND hwnd,UINT message, WPARAM wParam,LPARAM lParam)
{
int wmId, wmEvent;//与菜单有关
TCHAR szBuffer [50] ;
int iLength;
static int cxChar, cxCaps, cyChar ;
hWnd=hwnd;
HDC hdc;
PAINTSTRUCT ps;
static HPEN hpen=CreatePen(PS_SOLID,2,RGB(255,0,0)),hpenw=CreatePen(PS_SOLID,2,RGB(255,255,0)),hpen1=CreatePen(PS_SOLID,10,RGB(220,72,41));
static int *PointX=rus.GetX(),*PointY=rus.GetY();//与红色方块的位置有关
TEXTMETRIC tm ;
switch(message)
{
case WM_CREATE:
hdc= GetDC (hwnd) ;
GetTextMetrics (hdc, &tm) ;
cxChar = tm.tmAveCharWidth ;
cyChar = tm.tmHeight + tm.tmExternalLeading ;
ReleaseDC (hwnd, hdc) ;
PlaySound (TEXT ("Begin.wav"), NULL, SND_FILENAME | SND_ASYNC|SND_LOOP );
SetTimer(hwnd,1,Time,NULL);
return 0;
/
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// 分析菜单选择:
switch (wmId)
{
case ID_32772://第一级
time1(LEVEL1);
break;
case ID_32773://第二级
time1(LEVEL2);
break;
case ID_32774://第三级
time1(LEVEL3);
break;
case ID_32775://第四级
time1(LEVEL4);
break;
case ID_32777://暂停
PUSEGAME();
break;
case ID_32778://继续
GoOn();
break;
case ID_32779://新游戏
ReStartGame();
InvalidateRect(hwnd,NULL,FALSE);//重画窗口
break;
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, About); //菜单
break;
case IDM_EXIT:
DestroyWindow(hwnd);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
break;
/
case WM_SIZE:
MM=true; //窗口改变大小,重画;
return 0;
/
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
if(MM||mm||Mm)
{
if(Mm)
{
iLength = wsprintf (szBuffer, TEXT (" 0"));
SetTextAlign (hdc, TA_RIGHT | TA_TOP);
TextOut(hdc,300,220,szBuffer,iLength);
}
else
{
iLength = wsprintf (szBuffer, TEXT ("%i"),rus.SCORE);
SetTextAlign (hdc, TA_RIGHT | TA_TOP);
TextOut(hdc,300,220,szBuffer,iLength);
}
SetTextAlign (hdc, TA_LEFT | TA_TOP);
iLength = wsprintf (szBuffer, TEXT ("SCORE: "));
TextOut(hdc,250,200,szBuffer,iLength);
iLength = wsprintf (szBuffer, TEXT ("难度:"));
TextOut(hdc,250,280,szBuffer,iLength);
switch(Time)
{
case LEVEL1:
iLength = wsprintf (szBuffer, TEXT ("Level 1")); //画文字
TextOut(hdc,250,310,szBuffer,iLength);
break;
case LEVEL2:
iLength = wsprintf (szBuffer, TEXT ("Level 2"));
TextOut(hdc,250,310,szBuffer,iLength);
break;
case LEVEL3:
iLength = wsprintf (szBuffer, TEXT ("Level 3"));
TextOut(hdc,250,310,szBuffer,iLength);
break;
case LEVEL4:
iLength = wsprintf (szBuffer, TEXT ("Level 4"));
TextOut(hdc,250,310,szBuffer,iLength);
break;
default:break;
}
Mm=0;
}
/
SelectObject(hdc,hpen1);
MoveToEx(hdc,10,0,NULL);
LineTo(hdc,10,410);
MoveToEx(hdc,10,410,NULL); //画外围的直线
LineTo(hdc,350,410);
MoveToEx(hdc,350,410,NULL);
LineTo(hdc,350,0);
MoveToEx(hdc,227,0,NULL);
LineTo(hdc,227,410);
MoveToEx(hdc,243,125,NULL);
LineTo(hdc,243,43);
MoveToEx(hdc,243,125,NULL);
LineTo(hdc,320,125);
MoveToEx(hdc,240,330,NULL);
LineTo(hdc,240,270);
MoveToEx(hdc,240,270,NULL);
LineTo(hdc,320,270);
/
if(rus.NUM)
{
PUSEGAME();
IsShining=true;
SetTimer(hwnd,3,200,NULL);
for(int m=0;m