📄 pushboxs.c
字号:
{
mannewAttr=MAN;
boxoldAttr=SPACE;
}
else
if (attr==BOXINPOSITION)
{
mannewAttr=MANINPOSITION;
boxoldAttr=BOXPOSITION;
}
//judge whether box can be moved or not before pushing and the direction in which to move
switch (JudgeBoxMove(*manX,*manY,xPos,yPos))
{
case NOMOVE:
return;
break;
case MANLEFTBOXRIGHT :
boxnewX=xPos+1;
boxnewY=yPos;
break;
case MANRIGHTBOXLEFT :
boxnewX=xPos-1;
boxnewY=yPos;
break;
case MANUPBOXDOWN :
boxnewX=xPos;
boxnewY=yPos+1;
break;
case MANDOWNBOXUP :
boxnewX=xPos;
boxnewY=yPos-1;
break;
default:
break;
}
if (GetWho(boxnewX,boxnewY)==SPACE)
boxnewAttr=BOX;
else if (GetWho(boxnewX,boxnewY)==BOXPOSITION)
boxnewAttr=BOXINPOSITION;
//first erase the box at the old place and then display it at the new place
//secondly,erase the man at the old place and display it at the new place
DrawBox(xPos,yPos,GPC_EXOR_STYLE);//erase the old box
DrawBox(boxnewX,boxnewY,GPC_EXOR_STYLE);//draw the new box
ChangePosition(xPos,yPos,boxoldAttr,boxnewX,boxnewY,boxnewAttr);
DrawMan(*manX,*manY,GPC_EXOR_STYLE);//erase the old man
DrawMan(xPos,yPos,GPC_EXOR_STYLE);//draw the new man
ChangePosition(*manX,*manY,manoldAttr,xPos,yPos,mannewAttr);
//add one box-moving step into the chain
addone(MAN,*manX,*manY,xPos,yPos);
addone(BOX,xPos,yPos,boxnewX,boxnewY);
gcandelete=CANDELETE;
*manX=xPos;
*manY=yPos;
}
void UndoMan(P_U8 manx,P_U8 many,U8 who)
{
struct chain *ptr=NULL;
U8 mannowAttr,manoldAttr;
// U8 attr;
if (who==MAN)
ptr=gamechain;
else
ptr=gamechain->next;
if (ManmoveAnimation(ptr->newx,ptr->newy,ptr->oldx,ptr->oldy))
{
mannowAttr=GetWho(ptr->newx,ptr->newy);
manoldAttr=GetWho(ptr->oldx,ptr->oldy);
switch (mannowAttr)
{
case MAN:
mannowAttr=SPACE;
break;
case MANINPOSITION:
mannowAttr=BOXPOSITION;
break;
default:
break;
}
switch (manoldAttr)
{
case SPACE:
manoldAttr=MAN;
break;
case BOXPOSITION:
manoldAttr=MANINPOSITION;
break;
default:
break;
}
//change the attibute of both positions
ChangePosition(ptr->newx,ptr->newy,mannowAttr,ptr->oldx,ptr->oldy,manoldAttr);
*manx=ptr->oldx;
*many=ptr->oldy;
}
}
void UndoBox()
{
struct chain *ptr=NULL;
U8 boxnowAttr,boxoldAttr;
ptr=gamechain;
DrawBox(ptr->newx,ptr->newy,GPC_EXOR_STYLE);
DrawBox(ptr->oldx,ptr->oldy,GPC_EXOR_STYLE);
boxnowAttr=GetWho(ptr->newx,ptr->newy);
boxoldAttr=GetWho(ptr->oldx,ptr->oldy);
switch (boxnowAttr)
{
case BOX:
boxnowAttr=SPACE;
break;
case BOXINPOSITION:
boxnowAttr=BOXPOSITION;
break;
default:
break;
}
switch (boxoldAttr)
{
case SPACE:
boxoldAttr=BOX;
break;
case BOXPOSITION:
boxoldAttr=BOXINPOSITION;
break;
default:
break;
}
//change the attibute of both positions
ChangePosition(ptr->newx,ptr->newy,boxnowAttr,ptr->oldx,ptr->oldy,boxoldAttr);
}
// the undo function
int Undo(P_U8 manx,P_U8 many)
{
U8 x,y;
U8 end=CANDELETE;
x=*manx;
y=*many;
switch (gamechain->who)
{
case MAN:
UndoMan(&x,&y,MAN);
if (deleteone()==0)
end=CANNOTDELETE;
break;
case BOX:
UndoMan(&x,&y,BOX);
UndoBox();
if (deleteone()==0)
end=CANNOTDELETE;
if (deleteone()==0)
end=CANNOTDELETE;
break;
default:
break;
}
*manx=x;
*many=y;
return end;
}
void Releaseundospace()
{
struct chain *ptr=NULL;
while (gamechain)
{
ptr=gamechain;
gamechain=gamechain->next;
Lfree(ptr);
}
}
int Succeed()
{
U8 i,j;
for(i=0;i<gameroom[gStageNow].Ynumber;i++)
for(j=0;j<gameroom[gStageNow].Xnumber;j++)
{
if (*(mapPtr+i*gameroom[gStageNow].Xnumber+j)==BOX)
return NOTEND;
}
return SUCCESS;
}
void SearchPutBoxsGame(void)
{
MSG msg;
U32 CreateWin;
// U32 vscroll;
U32 hGC;
U8 Gquit=0;
// U32 size;
// U32 XAreaId,areaId;
// P_U16 data;
//U32 exitArea;
U32 roomArea;
//char *exitString="退 出";
S16 xScr,yScr;//the absolute x,y coordinte of the room
U8 xPos,yPos;//the position of the touched unit in the array
// U8 startX,startY;//the unit's x ,y coordinate for the use of displaying
U8 manX,manY;//the man's position
// U32 undoArea;//the undo area ID
// U32 StageArea;//the stage-selecting area
// U8 i;
// U8 Stage;
//added by rsh 2002/6/19 15:20
U32 lbox;
struct LBOX_ITEM lboxitem[] =
{
ICON_ENABLE, UNDERLINE, "幼儿园",
ICON_ENABLE, UNDERLINE, "小学生",
ICON_ENABLE, UNDERLINE, "中学生",
ICON_ENABLE, UNDERLINE, "大学生",
ICON_END, UNDERLINE, NULL
};
/* 创建主窗口 */
CreateWin= CreateWindow( WNDCLASS_WIN, //窗口类型(主窗口)
"推箱子", //窗口标题
WS_OVERLAPPEDWINDOW, //窗口风格(主窗口风格的宏定义参见头文件asixwin.h)
0,0, //窗口左上角在逻辑屏幕中的坐标
PHY_LCD_W,PHY_LCD_H, //窗口的宽度和高度
0, //窗口的父窗口(主窗口没有父窗口)
0, //窗口的附加参数(主窗口没有附加参数)
NULL); //窗口的附加数据(主窗口没有附加数据)
/* 创建控件 */
/* 在此用户加入自己所需的控件 */
// 控件实例:
/* vscroll = CreateWindow( WNDCLASS_SCROLL, //控件类型(滚动条)
"Scroll", //控件标题(对于滚动条,标题不会显示)
WS_CHILD|SBS_VERT, //控件风格(控件风格的宏定义参见头文件asixwin.h)
100,20, //控件左上角在逻辑屏幕中的坐标
20,120, //控件的宽度和高度
mainwin, //控件的父窗口(一般是主窗口)
MAKELONG(1,10), //控件的附加参数(对于滚动条,该参数表示滚动范围)
NULL); //控件的附加数据(滚动条不使用该参数)
*/
//added by rsh 2002/6/19 15:30
lbox = CreateWindow(WNDCLASS_LIST, "ListBox", WS_CHILD|LBS_POPUP,10 ,LCD_HEIGHT-20,70,20,CreateWin,0, lboxitem);
//it need modify,for choose stage ,modified by rsh 2002/06/20 9:50
// gStageNow=0;//the default stage
StageReturn:
if (!(mapPtr=Stageinit())) return;
Drawroom(mapPtr);//draw room
//define the playing area or the touched-area
ActiveAreaEnable( (P_U32)&roomArea,INPUT_AREA,CONTINUOUS_MODE,
gameroomX,gameroomY,gameroomX+gameroomLen-1,gameroomY+gameroomWid-1,CreateWin);
//the man's position is initiated here
manX=gameroom[gStageNow].manx;
manY=gameroom[gStageNow].many;
gcandelete=CANNOTDELETE;
/* 用户可以在此绘图,但该图形不会被保存 */
hGC = GetGC();
// 消息处理
while(!Gquit)
{
ASIXGetMessage(&msg, NULL, 0, 0);
switch(msg.message)
{
/* 在此用户加入自己的消息处理 */
case IRPT_PEN:
GetPos(msg, &xScr, &yScr);
Getpos((U8)xScr,(U8)yScr,(P_U8)&xPos,(P_U8)&yPos);//get the position in the array
switch (GetWho(xPos,yPos)) // get who is at this place
{
//according to who is at the place , the
//programme handles it in different ways.
//0 brick; 1 box;2 bosposition;3 man;
//4 space; 5 maninposition; 6 boxinposition
case BRICK:
// no action
break;
case BOX:
BoxTouch(&manX,&manY,xPos,yPos,BOX);
break;
case BOXPOSITION:
BoxPositionTouch(&manX,&manY,xPos,yPos);
break;
case MAN:
//no action
break;
case SPACE:
SpaceTouch(&manX,&manY,xPos,yPos);
break;
case MANINPOSITION:
//no action
break;
case BOXINPOSITION:
BoxTouch(&manX,&manY,xPos,yPos,BOXINPOSITION);
//BoxinPositionTouch();
break;
default:
break;
}
if (Succeed())
{
MessageBox( 0,"Congratulation!go on!","hello",MB_OKCANCEL);
gStageNow=(gStageNow+1)%maxstage;
if (!(mapPtr=Stageinit())) return;
ClearRec(hGC, GPC_WHITE,gameroomX,gameroomY,gameroomLen,gameroomWid,GPC_REPLACE_STYLE);
Drawroom(mapPtr);//draw room
manX=gameroom[gStageNow].manx;
manY=gameroom[gStageNow].many;
Releaseundospace();
}
break;
/* 关闭窗口的消息,建议用户不要更改该消息的处理*/
//added by rsh 2002/06/19 15:30
case WM_LISTBOX:
switch(msg.wparam)
{
case 0: gStageNow = 0;
break;
case 1: gStageNow = 5;
break;
case 2: gStageNow = 10;
break;
case 3: gStageNow = 20;
break;
default: break;
}
ClearRec(hGC, GPC_WHITE,gameroomX,gameroomY,gameroomLen,gameroomWid,GPC_REPLACE_STYLE);
goto StageReturn;
break;
case WM_QUIT:
Gquit = 1;
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
}
DestroyWindow(CreateWin);
// EndofTask();
}
void PutBoxes(void)
{
MSG Msg;
U32 mainwin;
//U32 vscroll;
U32 hGC;
U8 quit=0;
U32 bt1,bt2;
U32 menu;
U32 tskbar; // 任务栏
struct MENU_ITEM menuitem[]=
{
1, 1, "1 stage",
1, 1, "2 stage",
1, 1, "3 stage",
1, 1, "4 stage",
1, 1, "5 stage",
1, 1, "6 stage",
1, 1, "7 stage",
1, 1, "8 stage",
1, 1, "9 stage",
1, 1, "10 stage",
1, 1, "11 stage",
1, 1, "12 stage",
1, 1, "13 stage",
1, 1, "14 stage",
1, 1, "15 stage",
1, 1, "16 stage",
1, 1, "17 stage",
1, 1, "18 stage",
1, 1, "19 stage",
1, 1, "20 stage",
1, 1, "21 stage",
1, 1, "22 stage",
1, 1, "23 stage",
1, 1, "24 stage",
1, 1, "25 stage",
1, 1, "26 stage",
1, 1, "27 stage",
1, 1, "28 stage",
1, 1, "29 stage",
1, 1, "30 stage",
0, 0, NULL,
};
/* 创建主窗口 */
mainwin = CreateWindow( WNDCLASS_WIN, //窗口类型(主窗口)
"推箱子游戏", //窗口标题
WS_OVERLAPPEDWINDOW, //窗口风格(主窗口风格的宏定义参见头文件asixwin.h)
0,0, //窗口左上角在逻辑屏幕中的坐标
PHY_LCD_W,PHY_LCD_H, //窗口的宽度和高度
0, //窗口的父窗口(主窗口没有父窗口)
0, //窗口的附加参数(主窗口没有附加参数)
NULL); //窗口的附加数据(主窗口没有附加数据)
tskbar = CreateWindow(WNDCLASS_TSKBAR, NULL, WS_CHILD|TBS_TYPICAL, 0, 0, 0, 0,mainwin, 0, NULL);
/* 创建控件 */
/* 在此用户加入自己所需的控件 */
// 控件实例:
/*
vscroll = CreateWindow( WNDCLASS_SCROLL, //控件类型(滚动条)
"Scroll", //控件标题(对于滚动条,标题不会显示)
WS_CHILD|SBS_VERT, //控件风格(控件风格的宏定义参见头文件asixwin.h)
100,20, //控件左上角在逻辑屏幕中的坐标
12,120, //控件的宽度和高度
mainwin, //控件的父窗口(一般是主窗口)
MAKELONG(1,10), //控件的附加参数(对于滚动条,该参数表示滚动范围)
NULL); //控件的附加数据(滚动条不使用该参数)
*/
bt1 = CreateWindow( WNDCLASS_BUTTON,
"开始",
WS_CHILD | BS_REGULAR ,
20,30,
60,20,
mainwin,
0,
NULL);
bt2 = CreateWindow( WNDCLASS_BUTTON,
"结束游戏",
WS_CHILD | BS_REGULAR,
20,65,
60,20,
mainwin,
0,
NULL);
menu = CreateWindow(WNDCLASS_MENU,
"阶段选择",
WS_CHILD | MNS_MID,
20,100,
60,20,
mainwin,
0,
(void *)menuitem);
/* 用户可以在此绘图,但该图形不会被保存 */
hGC = GetGC();
// KVMStarter();
// 消息处理
while(!quit)
{
ASIXGetMessage(&Msg, NULL, 0, 0);
switch(Msg.message)
{
// 在此用户加入自己的消息处理
case WM_COMMAND:
if (Msg.lparam == bt1)
{
SearchPutBoxsGame();
} else
if (Msg.lparam == bt2)
{
quit = 1;
} else
if (Msg.lparam == menu)
{
gStageNow = (U8)Msg.wparam;
SearchPutBoxsGame();
}
break;
// 关闭窗口的消息,建议用户不要更改该消息的处理
case WM_QUIT:
quit = 1;
break;
default: break;
}
DefWindowProc(Msg.message, Msg.lparam, Msg.data, Msg.wparam);
}
DestroyWindow( mainwin );
EndofTask();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -