F:\游游\Minigui_snake.cPage100001://Function:Snakegame!00002://Date:2005-07-20start00003://FinishDate:2005-07-21end00004:#includestdio.h00005:#includestdlib.h00006:#includestring.h00007:#includesys/types.h00008:#includesys/stat.h00009:#includefcntl.h00010:#includestring.h00011:00012:#includeminigui/common.h00013:#includeminigui/minigui.h00014:#includeminigui/gdi.h00015:#includeminigui/window.h00016:#includeminigui/control.h00017:#includeminigui/mgext.h00018:00019:#includesnake.h00020:00021:staticHWNDhMainWnd=HWND_INVALID;00022:00023:#defineSNAKE_STACK6400024:#defineSNAKE_PANELSNAKE_STACK00025:00026:#defineSTEP_X1600027:#defineSTEP_Y1600028:#definePANEL_WIDTH1500029:#definePANEL_HEIGHT1800030:00031:#defineTIME_ID100000032:#defineFIELMAX_PATH25600033:00034:#defineBT_CLOSE10000035:00036:staticBITMAPbmpSnake,bmpBlock_h,bmpBlock_v,bmpGround,bmpPill00036:,bmpMouse,bmpSnake_h,bmpPanel;00037:00038:staticintiCurForward;//当当当当当当当当00039:00040:00041:Snakesnake[PANEL_WIDTH*PANEL_HEIGHT];00041://将当将将将将将将将将00042:inthead,tail;//当将蛇蛇蛇蛇蛇00043:intiSnakeLen=4;//当当蛇蛇蛇蛇00044:intiEatMouse=0;//吃吃当吃吃当将将00045:00046:intiCur_Time=0;//用用用用用用当用用用将00047:BOOLbHasPill=FALSE;00048:intiSetTime=30;00049:00050:Panelpanel[PANEL_WIDTH][PANEL_HEIGHT];//行行行行行00051:F:\游游\Minigui_snake.cPage200052:enum{//定定当当定00053:LEFT,//当向00054:RIGHT,//当向00055:UP,//当向00056:DOWN//当向00057:};00058:00059:staticBOOLbStartGame=FALSE;//游游游蛇游游00060:00061:00062:SnakeGetNextStepGetNextStep(Snake,int);00063:voidCutSnakeTailCutSnakeTail();00064:voidSetNewHeadSetNewHead(Snake);00065:00066:SnakeGetheadGethead()//获获当获00067:{00068:returnsnake[head];00069:}00070:00071://Function:获获获获获获获获00072://return:GROUND00073://MOUSE00074://BLOCK00075://SNAKE00076://PILL00077:staticintGetNextBlockStatusGetNextBlockStatus()00078:{00079:SnakepCur=Gethead();00080:00081:Snakepnext=GetNextStep(pCur,iCurForward);00082:00083:returnpnext.full;00084:}00085:00086:00087:staticvoidEatMouseEatMouse()00088:{00089:SnakepCur=Gethead();00090:SnakepNext=GetNextStep(pCur,iCurForward);00091:panel[pNext.x][pNext.y].full=GROUND;//释释吃释释00092:SetNewHead(pNext);00093:iSnakeLen++;00094:iEatMouse++;00095:00096:}00097:00098:BOOLIsGroundIsGround(intx,inty)00099://判判判判判判判判00100:{00101:F:\游游\Minigui_snake.cPage300102:if(panel[x][y].full==GROUND)//行将盘用00103:{00104:inti;00105:for(i=0;iPANEL_WIDTH*PANEL_HEIGHT;i++)00106:{00107:if(snake[i].full==SNAKE)00108:{00109:if(!(snake[i].x==x&&snake[i].y==y))00109://并并并并当当并并00110:returnTRUE;00111:}00112:}00113:}00114:returnFALSE;00115:}00116:00117://Function:随随随随随随00118:staticvoidCreateMouseCreateMouse()00119:{00120://randomcreateamouse00121:intx,y;00122:00123:00124:do{00125:00126:x=rand()%PANEL_WIDTH;00127:y=rand()%PANEL_HEIGHT;00128:00129:x=x0?x*(-1):x;00130:y=y0?y*(-1):y;00131:}00132:while(!IsGround(x,y));00133:00134:panel[x][y].full=MOUSE;00135:00136:printf(CreateMouse:[%d,%d]\n,x,y);0?endCreateMouse?0137:}00138:00139://Function:吃吃吃吃吃吃吃吃获00140:staticvoidEatPillEatPill()00141:{00142:SnakepCur=Gethead();00143:SnakepNext=GetNextStep(pCur,iCurForward);00144:panel[pNext.x][pNext.y].full=GROUND;//释释用用释00145:SetNewHead(pNext);00146:CutSnakeTail();00147:CutSnakeTail();00148:iSnakeLen--;00149:bHasPill=FALSE;00150:00151:00152:}00153:00154:F:\游游\Minigui_snake.cPage400155:00156:staticvoidInitGameInitGame()00157:{00158:srand(time(NULL));00159:00160://填填填填00161:intx,y;00162:00163:for(x=0;xPANEL_WIDTH;x++)00164:{00165:for(y=0;yPANEL_HEIGHT;y++)00166:{00167://将将将获将将将将将将获将00168:if(x==0||y==0)00169:{00170:panel[x][y].full=BLOCK;00171:}00172:elseif(x==PANEL_WIDTH-1||y==PANEL_HEIGHT-1)00173:{00174:panel[x][y].full=BLOCK;00175:}00176:00176://将将将将将y=6,x=4,x=10当并并的的并将当释00177:elseif(y==PANEL_HEIGHT/3&&(xPANEL_WIDTH/4)00177:&&(xPANEL_WIDTH*3/4))00178:{00179:panel[x][y].full=BLOCK;00180:}00181:elseif(y==PANEL_HEIGHT*2/3&&(xPANEL_WIDTH/400181:)&&(xPANEL_WIDTH*3/4))00182:{00183:panel[x][y].full=BLOCK;00184:}00185://其其其将将将随判其将00186:else00187:{00188:panel[x][y].full=GROUND;00189:}001?endfory=0;yPANEL_HEIGHT;y++?90:}00?endforx=0;xPANEL_WIDTH;x++?191:}00192:00193:00193://填填吃将将将吃将将将吃吃填填将SNAKE、其00193:其O畛畛畛ROUND00194:inti;00195:head=0;//当获00196:tail=3;//当将将将00197:for(i=0;iPANEL_WIDTH*PANEL_HEIGHT;i++)00198:{00199:snake[i].x=10+i;//当获当并并(游蛇并并)00200:snake[i].y=PANEL_HEIGHT-2;00201:if(itail+1)00202:snake[i].full=SNAKE;00203:elseF:\游游\Minigui_snake.cPage500204:snake[i].full=GROUND;00205:}00206:00207://随随随4个00208:for(i=0;i4;i++)00209:CreateMouse();00210:0?endInitGame?0211:}00212:00213:00214:00215://Function:获获吃获获获获个其将00216://Param:param1--当当吃获其将00217://param2--当当吃当当将当00218://return:吃获获获个其将00219:SnakeGetNextStepGetNextStep(SnakepCur,intforward)00220:{00221:Snaketmp;00222:00223:tmp=pCur;00224:00225:switch(forward)00226:{00227:caseLEFT:00228:tmp.x--;00229:break;00230:00231:caseRIGHT:00232:tmp.x++;00233:break;00234:00235:caseUP:00236:tmp.y--;00237:break;00238:00239:caseDOWN:00240:tmp.y++;00241:break;00242:00243:default:00244:break;00245:00?endswitchforward?246:}00247://检检获获个判判判吃吃F:\游游\Mi