猪腰子的做法.txt猪腰子的做法.txt
ÓÎÏ??ØÖÆ?º
enter?ü?ªÊ?ÓÎÏ?
?Õ?ñ ?ü ÔÝÍ?
Ê?ϵÄ?ÍÊǵØÇòÈË??ÖªµÀµÄ??Ïò?ü
?ÃÓÎÏ?ÓÃc++ºÍwindows apiÔÚeclipse_cppÖÐ?àÐ????????ØÖÆÌ??ÌÐò???É
?Ä?ÌÐòÔÚvc6.0??ºÍeclipse_cppÖÐÔËÐÐÕý??
Ð??Ë?ÌÐòÖ?Î?Á?ÊÖ??
??Ó,?ó?Ò?âÊÔ??Á? Èç??ÏÖ?ÌÐòÎÊÌâÇëÁªÏµwangzhen_621@126....
猪腰子的做法.txt
ÓÎÏ??ØÖÆ?º
enter?ü?ªÊ?ÓÎÏ?
?Õ?ñ ?ü ÔÝÍ?
Ê?ϵÄ?ÍÊǵØÇòÈË??ÖªµÀµÄ??Ïò?ü
?ÃÓÎÏ?ÓÃc++ºÍwindows apiÔÚeclipse_cppÖÐ?àÐ????????ØÖÆÌ??ÌÐò???É
?Ä?ÌÐòÔÚvc6.0??ºÍeclipse_cppÖÐÔËÐÐÕý??
Ð??Ë?ÌÐòÖ?Î?Á?ÊÖ??
??Ó,?ó?Ò?âÊÔ??Á? Èç??ÏÖ?ÌÐòÎÊÌâÇëÁªÏµwangzhen_621@126.com
/*
* Data.h
* Author: ÍõÕñ ???ªÁÖ?óÑ???
* wangzhen_621@126.com
* Created on: 2008-11-11
*
*/
#ifndef DATA_H_
#define DATA_H_
/*
* index:7ÐÐ10ÁÐÊý×é Ã?ÐÐ?ÔÓ?Ò?ÖÖ???éÀà?ð??
* Ã?ÐеÄÇ?ËÄÁÐΪx×ø?ê??ÖÐ?äËÄÁÐΪy×ø?ê
* µÚ?ÅÁÐΪ???éÀà?ð?úÂë??×îºóÒ?ÁÐΪ?ÃÀàÐÍ???éÓÐ??ÖÖ?äÐÎ
* ÓÃÒ??ö5*5µÄ?ØÕó?íÊ? 7ÖÖÀà?ð???é ??19ÖÖ?äÐÎ
*/
#include
static const int KINDS=7;//???éÖÖÀàÊýÁ? static const int COLS=10;//Êý?ÝÁÐÊý
//Ã?ÖÖ???éµÄ?úºÅ
static const int TYPE1=1;
static const int TYPE2=2;
static const int TYPE3=3;
static const int TYPE4=4;
static const int TYPE5=5;
static const int TYPE6=6;
static const int TYPE7=7;
//?äÐεÄÖÖÀà
static const int RTYPE1=1;
static const int RTYPE2=2;
static const int RTYPE3=4;
static int rTypeNext;
static int rTypeDown;
//?õÊ??????é×ø?ê???ÔÓ?µÄÀà?ðºÍ?äÐÎÖÖÀà static const int index[KINDS][COLS]={
{0,1,0,1,0,0,-1,-1,TYPE1,RTYPE1},
{-1,0,1,2,0,0,0,0,TYPE2,RTYPE2},
{0,0,1,1,1,0,0,-1,TYPE3,RTYPE2},
{0,0,1,1,-1,0,0,1,TYPE4,RTYPE2},
{-1,0,0,1,0,0,1,0,TYPE5,RTYPE3},
{-1,0,1,1,0,0,0,-1,TYPE6,RTYPE3},
{-1,0,1,1,0,0,0,1,TYPE7,RTYPE3} };
//??Ê?Æ?ID
static const int TIMER=1;
//
//?õÊ?ÓÎÏ????ð?ÔÓ?µÄÊ??ä?ä?ô static int CURRENTLEVEL=600; static int level=1;
//Ã?ÖÖÍ?ÐÎËù?üº?µÄÐ????éÊý
static const int CTN=4;
//???éÐÎ×???Òå
typedef struct {
int x;
int y;
}sCord;
sCord sDown[CTN],sNext[CTN];
//ÏÂÒ??ö???éµÄ×ø?ê
static RECT rectNext[CTN];
//ÕýÔÚÏÂÂä???éµÄ×ø?ê
static RECT rectDown[CTN];
//ÏÔÊ?ÇøÓòµÄ?óÐ?
static const int cxSize=25; static const int cySize=35;
//???éÆ?Àë(0,0)µÃÎ?ÖÃ
static int offsetx;
static int offsety;
static int offsetxNext;
static int offsetyNext;
//×Ô??ÒåÏûÏ?
static const int MS_DOWN=10001;
//ÔÝÍ?
static bool go=true;
//?ªÊ?
static bool startGame=false;
//?áÊø
static bool gameOver=false;
//µÃ?Ö
static int score;
RECT rt={326,81,425,455};
//Ã??ö???ñ?üº?µÄÏñËØ
static const int pelsSize=13;
//ÏÔÊ?ÇøÓò?óÐ?µÄ??Òå
static const POINT area[]={0,455,326,455,326,0}; //ÏÔÊ?ÇøÓòµÄ?íÊ????? ×îºóÒ?ÁÐ×îºóÒ?ÐÐ?Ö?ð?ÔÓ??ÃÐÐ?ÃÁÐËù?ßÓеÄ???é×ÜÊý
0?íÊ?Ã?ÓÐ???é1?íÊ?ÓÐ
static int fillArea[cySize+1][cxSize+1];
HBRUSH hBrush1=CreateSolidBrush(RGB(0,0,0));//???éÑÕÉ? //HBRUSH hBrush1=CreateSolidBrush(RGB(240,250,100));//?ÆÉ?
HBRUSH hBrush2=CreateSolidBrush(RGB(255,255,255)); HPEN hPen1=CreatePen(PS_SOLID,0,RGB(230,230,230));//?????ñÑÕÉ?
#endif /* DATA_H_ */
/*
* MainPro.cpp
*
* Created on: 2008-11-11
* Author: ÍõÕñ ???ªÁÖ?óÑ???
* wangzhen_621@126.com
*/
#include"Data.h"
#include
#include
using namespace std;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); /*
* ÄæÊ?Õë??ÏòÐýת???ñ ?µ?ØÄÜ?ñÐýת
* @param lpsCord ÒªÐýתµÄ???é×ø?êÖ?Õë
* @param rType ÐýתÀàÐÍ
* @param rNumber Ðýת?ÎÊý
* @param ÊÇ?ñµÚÒ??ÎÐýת
*/
bool rotate(sCord *lpsCord,int rType,int rNumber,bool firstRotate);
void getRandom();//?õÊ??????ñÐÎ×?
void getNext(sCord *targ,const sCord* sur);//È??öÏÂÒ??ö???é
void draw();//?æ?ö???ñ
void start();//?ªÊ?ÓÎÏ?
bool downAble();//ÄÜ?ñÏÂÂä
bool leftAble();//ÄÜ?ñ×óÒÆ
bool rightAble();//ÄÜ?ñÓÒÒÆ
bool disRows(HWND hwnd);//ÅÐ?ÏÄÜ?ñÏûÐÐ
//int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
//
// PSTR szCmdLine, int iCmdShow)
//void paintRect(HDC hdc,RECT&,HBRUSH hBrush);
int main()
{
HINSTANCE hInstance=NULL;
static TCHAR szAppName[]=TEXT("ELS");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style=CS_HREDRAW|CS_VREDRAW;//|~(WS_MINIMIZEBOX|WS_MAXIMIZEBOX) ;
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);//
CreateSolidBrush(RGB(195,195,237));
wndclass.lpszMenuName= NULL;
wndclass.lpszClassName= szAppName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("REGISTER ERROR"),szAppName,MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName,TEXT("?íÂÞË????é"),WS_DLGFRAME|WS_OVERLAPPED|WS_CAPT
ION|WS_SYSMENU|WS_MINIMIZEBOX,//(WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX)&~WS_BO
RDER,//WS_SIZEBOX
WS_OVERLAPPEDWINDOW&~WS_MAXIMIZEBOX,WS_CAPTION|//&~WS_MAXIMIZEBOX?ûÓÃ×î?ó??Ñ?Ïî
300,100,429,480,
NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
void getRandom()
{
int k=rand()%KINDS+1;
for(int i=0;i sNext[t].y ? sNext[t].y : min_y;
offsetxNext=(int)(cxSize/2)*pelsSize+(int)(pelsSize/2);//x??ÏòµÄÖÐ?äÏÔÊ?
offsetyNext=(-min_y)*pelsSize+(int)(pelsSize/2);//??Ö?ÖÃ??ÏÔÊ?
}
bool rotate(sCord *lpsCord,int rType,int rNumber,bool firstRotate)
{
int tempx;
int tempy;
int temp;
int tx=(offsetx-(int)(pelsSize/2))/pelsSize;
int ty=(offsety-(int)(pelsSize/2))/pelsSize;
bool ra=true;
switch(rType)
{
case RTYPE1:
ra=false;
break;
case RTYPE2:
{
if(rNumber%2!=0)
{
for (int j = 0; j < CTN; j++)
{
tempx=-lpsCord->y+tx;
tempy=lpsCord->x+ty;
lpsCord++;
if(!firstRotate&&(fillArea[tempx][tempy]>0||tempx>24||tempx<0||tempy<0||tempy>34
))
{
ra=false;
}
}
lpsCord-=4;
}
if(ra)
{
if (rNumber % 2 != 0)
for (int k = 0; k < CTN; k++)
{
temp = -lpsCord->x;
lpsCord->x = lpsCord->y;
lpsCord->y = temp;
lpsCord++;
}
}
}
break;
case RTYPE3:
for(int k=0;ky+tx;
tempy=(-lpsCord->x)+ty;
lpsCord++;
if(!firstRotate&&(fillArea[tempx][tempy]>0||tempx>24||tempx<0||tempy<0||tempy>34
))
{
ra = false;
}
}
lpsCord-=4;
}
if(ra)
for (int i = 0; i < rNumber; i++)
{
for (int j = 0; j < CTN; j++)
{
temp = -lpsCord->x;
lpsCord->x = lpsCord->y;
lpsCord->y = temp;
lpsCord++;
}
lpsCord=lpsCord-4;
}
break;
}
return ra;
}
void getNext(sCord *targ,const sCord* sur)
{
rTypeDown=rTypeNext;
offsetx=offsetxNext;
offsety=offsetyNext;
for(int i=0;ix=sur->x;
targ->y=sur->y;
sur++;
targ++;
}
getRandom();
}
void draw(HWND hwnd,const sCord* shape,RECT *rect,HBRUSH hBrush,int offsetx,int
offsety)
{
HDC hdc=GetDC(hwnd);
SelectObject(hdc,hBrush);
SelectObject(hdc,hPen1); // SelectObject(hdc,hPen2); // for(int i=0;ix<<"y="<y<x-(int)(pelsSize/2)+offsetx,pelsSize*shape->y-(int)
(pelsSize/2)+offsety, //
pelsSize*shape->x+(int)(pelsSize/2)+offsetx,pelsSize*shape->y+(int)(pelsSize/2)+
offsety);
// FillRect(hdc,rect,hBrush); // shape++;
// rect++;
// }
for(int i=0;ix-(int)(pelsSize/2)+offsetx,pelsSize*shape->y-(int
)(pelsSize/2)+offsety,
pelsSize*shape->x+(int)(pelsSize/2)+offsetx+2,pelsSize*shape->y+(int)(pelsSize/2
)+offsety+2);
shape++;
// rect++;
}
ReleaseDC(hwnd,hdc);
}
void start()
{
if(!startGame)
{
for (int i = 0; i < cySize + 1; i++)
for (int j = 0; j < cxSize + 1; j++)
fillArea[i][j] = 0;
startGame=true;
go=true;
score=0;
}
}
bool downAble()
{
bool da=true;
int x=(offsetx-(int)(pelsSize/2))/pelsSize;
int y=(offsety-(int)(pelsSize/2))/pelsSize;
int xtemp;
int ytemp;
for(int i=0;i0||ytemp>34)
{
da=false;
break;
}
}
if (!da)
{
for (int k = 0; k < CTN; k++)
{
xtemp = sDown[k].x + x;
ytemp = sDown[k].y + y;
fillArea[ytemp][xtemp] = 1;
fillArea[ytemp][cxSize]++;
fillArea[cySize][xtemp]++;
}
}
return da;
}
bool leftAble()
{
bool la = true;
int x = (offsetx - (int) (pelsSize / 2)) / pelsSize;
int y = (offsety - (int) (pelsSize / 2)) / pelsSize;
int xtemp;
int ytemp;
for (int i = 0; i < CTN; i++)
{
xtemp = sDown[i].x + x-1;
ytemp = sDown[i].y + y;
if (fillArea[ytemp][xtemp] > 0 || xtemp <0)
{
la = false;
break;
}
}
return la;
}
bool rightAble()
{
bool ra = true;
int x = (offsetx - (int) (pelsSize / 2)) / pelsSize;
int y = (offsety - (int) (pelsSize / 2)) / pelsSize ;
int xtemp;
int ytemp;
for (int i = 0; i < CTN; i++)
{
xtemp = sDown[i].x + x+1;
ytemp = sDown[i].y + y;
if (fillArea[ytemp][xtemp] > 0 || xtemp > 24)
{
ra = false;
break;
}
}
return ra;
}
bool disRows(HWND hwnd)
{
HDC hdc=GetDC(hwnd);
bool da=false;
int row[CTN];//?ÉÒÔÏû?ýµÄÐÐ
for (int ii = 0; ii < CTN; ii++)
row[ii] = 0;
int number = 0;//?ÉÁ?ÐøÏûµÄÐÐÊý
static int levelScore;
SelectObject(hdc,hPen1);
for (int i = 0; i < cySize; i++)
{
if (fillArea[i][cxSize] == cxSize)
row[number++] = i;
}
if (number > 0)//?ÉÒÔÏûÐÐ
{
da=true;
levelScore+=(number + 1) * number / 2;
score += (number + 1) * number / 2;
cout<<"levelScore:"<19)//Ôö?ÓÓÎÏ????ð
{
levelScore=0;
CURRENTLEVEL=(int)CURRENTLEVEL*2/3;
SetTimer(hwnd,TIMER,CURRENTLEVEL,NULL);
cout<<"currentlevel:"<=600)
{
level=i+2;
cout<<"level"<0;i--)
{
for(int j=0;jword(lParam)<
0)
{
Rectangle(hdc,k*pelsSize,t*pelsSize,(k+1)*pelsSize+1,(t+1)*pelsSize+1);
}
}
if(startGame)
{
draw(hwnd,sNext,rectNext,hBrush1,369,44);
draw(hwnd,sDown,rectDown,hBrush1,offsetx,offsety);
}
FillRect(hdc,&rt,hBrush2);
char ss[20];
char ll[20];
wsprintf(ss,"score:%d",score);
wsprintf(ll,"level:%d",level);
TextOut(hdc,330,300,ll,lstrlen(ll));
TextOut(hdc,330,320,ss,lstrlen(ss));
if(gameOver)
{
char g[]="Game Over!!";
TextOut(hdc,330,200,g,lstrlen(g));
}
SelectObject(hdc, GetStockObject(BLACK_PEN));
Polyline(hdc, area, 3);//?æÖÆÒ??ö?ØÐÎ
MoveToEx(hdc, 325, 80, NULL);
LineTo(hdc, 425, 80);
EndPaint(hwnd, &ps);
return 0;
}
case WM_KEYDOWN:
switch(wParam)
{
case VK_UP:
{
if(go&&startGame)
{
down=false;
draw(hwnd,sDown,rectDown,(HBRUSH)GetStockObject(WHITE_BRUSH),offsetx,offsety);
rotate(sDown,rTypeDown,1,false);
draw(hwnd,sDown,rectDown,hBrush1,offsetx,offsety);
}
}
return 0;
case VK_DOWN:
{
if(go&&startGame)
{
down=false;
draw(hwnd,sDown,rectDown,(HBRUSH)GetStockObject(WHITE_BRUSH),offsetx,offsety);
int k=(offsety-(int)(pelsSize)/2)/pelsSize;
while(k
本文档为【猪腰子的做法.txt】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。