📄 color.c
字号:
}
else if(x-x1>0&&y<=y1&&(abs(x-x1)>=abs(y-y1)))
{
printf("Move from %d,%d to %d,%d \n",x,y,x1,y1);
if(Base[x-1][y].Kind==0&&(x-1>=0)&&Base[x-1][y].flag!=1)//shang
{
x=x-1;
printf("Move up to %d,%d;\n",x,y);
Base[x][y].flag=1;
while(x==x1&&y==y1)
{
printf("Move to DEST.\n");
return 1;
}
if(FindWay( x, y, x1, y1)==1)
return 1;
x=x+1;
}
if(Base[x][y+1].Kind==0&&(y+1<9)&&Base[x][y+1].flag!=1)//you
{
y=y+1;
printf("Move to right %d,%d;\n",x,y);
Base[x][y].flag=1;
while(x==x1&&y==y1)
{
printf("Move to DEST.\n");
return 1;
}
if(FindWay( x, y, x1, y1)==1)
return 1;
y=y-1;
}
if(Base[x][y-1].Kind==0&&(y-1>=0)&&Base[x][y-1].flag!=1)//zuo
{
y=y-1;
printf("Move left to %d,%d;\n",x,y);
Base[x][y].flag=1;
while(x==x1&&y==y1)
{
printf("Move to DEST.\n");
return 1;
}
if(FindWay(x, y, x1, y1)==1)
return 1;
y=y+1;
}
if(Base[x+1][y].Kind==0&&(x+1<9)&&Base[x+1][y].flag!=1)//xia
{
x=x+1;
printf("Move down to %d,%d;\n",x,y);
Base[x][y].flag=1;
while(x==x1&&y==y1)
{
printf("Move to DEST.\n");
return 1;
}
if(FindWay(x, y, x1, y1)==1)
return 1;
x=x-1;
}
}
count --;
printf("%d times \n",count);
return 0;
}
static int CheckBump()//核对格子是否填满 填满游戏结束
{
int num1=0,num2=0;
for(num1=0;num1<9;num1++)
for(num2=0;num2<9;num2++)
{
if(Base[num1][num2].Kind==0)
return 0;
}
return 1;
}
static int CountScore(int num)/*计分*/
{
switch(num){
case 5:
{
score+=10;
break;
}
case 6:
{
score+=20;
break;
}
case 7:
{
score+=30;
break;
}
case 8:
{
score+=40;
break;
}
case 9:
{
score+=50;
break;
}
case 10:
{
score+=60;
break;
}
case 11:
{
score+=70;
break;
}
case 12:
{
score+=80;
break;
}
}
return 0;
}
static int Readscore()/*读取记录*/
{
FILE *fp;
char p[4];
fp=fopen("score.txt","r");
if(fp==NULL)
{
printf("Open file failed! /n");
return -1;
}
fgets(p,4,fp);
highest=atoi(p);
fclose(fp);
return 0;
}
static int Writescore()/*写入记录*/
{
FILE *fp;
char p[4];
fp=fopen("score.txt","w+");
if(fp==NULL)
{
printf("Open file failed! /n");
return -1;
}
sprintf(p,"%d",highest);
fwrite(p,4,1,fp);
fclose(fp);
return 0;
}
static int BumpWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
int prex,prey;
static int i=0,j=0,k=0,l=0;
static unsigned int ScoreCount=0;
static int refresh=0,restart=0,GameOver=0;
static int buff=0,flag=0;
static int Tcount,BuffKind;
switch (message) {
case MSG_CREATE:
{
//SetTimer(hWnd,100,1000);
// if( Readscore()==-1)
// return -1;
break;
}
case MSG_PAINT:
{
hdc = BeginPaint(hWnd);
FillBoxWithBitmap(hdc,0,0,0,0,&Back_ground);
FillBoxWithBitmap(hdc,330,250,0,0,&Back_highest);
FillBoxWithBitmap(hdc,330,50,0,0,&Back_restart);
FillBoxWithBitmap(hdc,330,150,0,0,&Back_score);
//FillBoxWithBitmap(hdc,160,460,0,0,&Back_score);
FillBoxWithBitmap(hdc,360,172,0,0,&SPic[score/100]);
FillBoxWithBitmap(hdc,370,172,0,0,&SPic[(score%100)/10]);
FillBoxWithBitmap(hdc,380,172,0,0,&SPic[score%10]);
//FillBoxWithBitmap(hdc,255,460,0,0,&Back_hscore);
FillBoxWithBitmap(hdc,360,272,0,0,&SPic[((highest)%1000)/100]);
FillBoxWithBitmap(hdc,370,272,0,0,&SPic[(highest%100)/10]);
FillBoxWithBitmap(hdc,380,272,0,0,&SPic[highest%10]);
if(start==1)
{
Addball();
Addball();
CountScore(Killball());
start=0;
}
if(restart==1)
{
InitBase();
Addball();
Addball();
CountScore(Killball());
restart=0;
}
if(GameOver==1)
{
FillBoxWithBitmap(hdc,120,120,0,0,&Back_gameover);
GameOver=0;
}
else
{
for( i=0 ; i<9; i++)
{
for( j=0 ; j<9; j++)
{
if(Base[i][j].Kind!=0)
{
FillBoxWithBitmap(hdc,Base[i][j].PostX,Base[i][j].PostY,0,0,&MyPic[Base[i][j].Kind-1]);
}
}
}
}
EndPaint(hWnd,hdc);
break;
}
case MSG_LBUTTONDOWN:
{
prex = LOSWORD (lParam);
prey= HISWORD (lParam);
if(prex>5&&prex<320&&prey>5&&prey<320)
{
if(flag==0)
{
n=((prex-5)/35);
m=((prey-5)/35);
hdc = BeginPaint(hWnd);
if(Base[m][n].Kind!=0)
{
FillBoxWithBitmap(hdc,Base[m][n].PostX,Base[m][n].PostY,0,0,&MyPic2[Base[m][n].Kind-1]);
flag=1;
}
EndPaint(hWnd,hdc);
}
else if (flag==1)
{ flag=0;
l=((prex-5)/35);
k=((prey-5)/35);
count=0;
for(i=0;i<50;i++)
{
path[i][0]=0;
path[i][1]=0;
}
initflag();
if((Base[k][l].Kind==0)&&FindWay(m, n, k, l)==1)
{
//Base[k][l].Kind=Base[m][n].Kind;
//Base[m][n].Kind=0;
Tcount=0;
BuffKind=Base[m][n].Kind;
Base[m][n].Kind=0;
SetTimer(hWnd,100,4);
InvalidateRect (hWnd,&rect[m*9+n],TRUE);
//if(Tcount>=(count-1))
//{
//Base[k][l].Kind=Base[m][n].Kind;
//Base[m][n].Kind=0;
//CountScore(Killball());
//ResetTimer(hWnd,100,100);
//InvalidateRect (hWnd,NULL,TRUE);
//Addball();
//}
//InvalidateRect (hWnd,NULL,TRUE);
}
}
}
else if(prex>330&&prex<430&&prey>50&&prey<100)/*重新开始*/
{
restart=1;
score=0;
InvalidateRect (hWnd,NULL,TRUE);
}
break;
}
case MSG_TIMER:
{
if(Tcount<50&&Tcount<count)
{
hdc = BeginPaint(hWnd);
FillBoxWithBitmap(hdc,(rect[path[Tcount+1][0]*9+path[Tcount+1][1]]).left,(rect[path[Tcount+1][0]*9+path[Tcount+1][1]]).top,0,0,&MyPic[BuffKind-1]);
EndPaint(hWnd,hdc);
//if(Tcount>2)
//{
InvalidateRect (hWnd,&rect[path[Tcount][0]*9+path[Tcount][1]],TRUE);
//}
Tcount++;
printf("path %d %d %d\n",path[Tcount][0],path[Tcount][1],count);
}
if(Tcount==count)
{
Base[k][l].Kind=BuffKind;
ResetTimer(hWnd,100,20);
Tcount++;
InvalidateRect (hWnd,NULL,TRUE);
break;
}
if(Tcount==(count+1))//Tcount不再计数
{
Tcount=Killball();
if(Tcount!=0)
{
CountScore(Tcount);
if(score>highest)
{
highest=score;
Writescore();
}
}
else{
Addball();
Tcount=Killball();//增加求后再检测一次是不是可以消求
if(Tcount!=0)
{
CountScore(Tcount);
if(score>highest)
{
highest=score;
Writescore();
}
}
if(CheckBump()==1)
GameOver=1;
}
KillTimer(hWnd,100);
InvalidateRect (hWnd,NULL,TRUE);
}
break;
}
case MSG_CLOSE:
DestroyMainWindow (hWnd);
PostQuitMessage (hWnd);
return 0;
}
return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
int MiniGUIMain (int argc, const char* argv[])
{
MSG Msg;
HWND hMainWnd;
MAINWINCREATE CreateInfo;
LoadPicture();
InitBase();
initRect();
Readscore();
#ifdef _LITE_VERSION
SetDesktopRect(0, 0, 1024, 768);
#endif
CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER;
CreateInfo.dwExStyle = WS_EX_NONE;
CreateInfo.spCaption = " ";
CreateInfo.hCursor = GetSystemCursor(0);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = BumpWinProc;
CreateInfo.lx = 0;
CreateInfo.ty = 0;
CreateInfo.rx = 525;
CreateInfo.by = 325;
CreateInfo.iBkColor = COLOR_lightwhite;
CreateInfo.dwAddData = 0;
CreateInfo.hHosting = HWND_DESKTOP;
hMainWnd = CreateMainWindow (&CreateInfo);
if (hMainWnd == HWND_INVALID)
return -1;
ShowWindow(hMainWnd, SW_SHOWNORMAL);
while (GetMessage(&Msg, hMainWnd)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup (hMainWnd);
return 0;
}
#ifndef _LITE_VERSION
#include <minigui/dti.c>
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -