写点什么

2021-3-20 【推箱子】

  • 2022 年 5 月 03 日
  • 本文字数:2248 字

    阅读完需:约 7 分钟

while (1){


DesignUI();


}


}


void DesignUI(){


int iCh;


char cNum;


iCh=WelcomePage();


if(iCh==49){


GetLevel1();


}


if(iCh==50){


else


printf("\n\t\t Please input level!(From 1 to 4):");


getchar();


cNum=getchar();


switch (cNum){


case'1':


GetLevel1();


break;


case'2':


GetLevel2();


break;


case'3':


GetLevel3();


break;


case'4':


GetLevel4();


break;


default:


printf("Enter error!\n");


Sleep(1000);


exit(0);


break;


}


}


else if(iCh==51){


system("cls");


exit(0);


}


}


int WelcomePage(){


int i=0;


system("cls");


system("color OE");


printf("\n\n\t\t Welcome to play box!\n\n");


printf("\t\t Person:♀ Wall:㊣ Box:■ Target:★ Reach target: ☆\n");


printf("\t\t Up:↑\n\t\t Down:↓\n\t\t Left: ←\n\t\t Right: →\n\n");


printf("\t\t Please number 1 to start new game\n\t\t\n");


printf("\t\t Please number 2 to choose level\n\t\t\n");


printf("\t\t Please number 3 to quit from game\n\t\t\n");


printf("\t\t Please right number to continue:");


while (1){


i=getchar();


if(i>=49&&i<=51){


return i;


}


}


}


int PrintMap(int aiMap[][16],int iImp){


int i,j;


int iCount=0;


for(i=0;i<14;i++){


for(j=0;j<16;j++){


switch(aiMap[i][j]){


case 0:


printf(" ");


break;


case 1:


SelectColor(14);


printf("㊣");


break;


case 2:


printf(" ");


break;


case 3:


SelectColor(11);


printf("★");


break;


case 4:


SelectColor(11);


printf("■");


break;


case 5:


SelectColor(9);


printf("☆");


break;


case 6:


SelectColor(10);


printf("♀");


break;


}


}


printf("\n");


}


SelectColor(14);


printf("\n");


printf("\tYou are in Level %d!\t\t\n",iImp);


printf("\tPress arrow keys to play the game!\t\n");


printf("\tPress N to the next level!\t\n");


printf("\tPress Q to return the home page!\t\n");


return iCount;


}


void SelectColor(int iColor){


HANDLE hConsole =


GetStdHandle((STD_OUTPUT_HANDLE));


SetConsoleTextAttribute(hConsole,iColor);


}


void MoveBox(int aiMap[][16],int iPlayerX,int iPlayerY,int iSelect,int aiMap2[][16]){


int iplayerX1,iPlayerY1;


int iplayerX2,iPlayerY2;


switch(iSelect){


case 1:


iPlayerX1 = iPlayerX - 1;


iPlayerY1 = iPlayerY;


iPlayerX2 = iPlayerX - 2;


iPlayerY2 = iPlayerY;


break;


case 2:


iPlayerX1 = iPlayerX;


iPlayerY1 = iPlayerY - 1;


iPlayerX2 = iPlayerX;


iPlayerY2 = iPlayerY - 2;


break;


case 3:


iPlayerX1 = iPlayerX;


iPlayerY1 = iPlayerY + 1;


iPlayerX2 = iPlayerX;


iPlayerY2 = iPlayerY + 2;


break;


case 4:


iPlayerX1 = iPlayerX + 1;


iPlayerY1 = iPlayerY;


iPlayerX2 = iPlayerX + 2;


iPlayerY2 = iPlayerY;


break;


default:


break;


}


switch aiMap([iPlayerX1][iPlayerY1]){


case WALL:


break;


case SPACE:


case BOX:


case TARGET:


aiMap[iPlayerX1][iPlayerY1] = PERSON;


if(aiMap2[iPlayerX][iPlayerY]==TARGET||aiMap2[iPlayerX][iPlayerY]==TARGET_IN){


aiMap[iPlayerX][iPlayerY]=TARGET;


}else{


aiMap[iPlayerX][iPlayerY]=SPACE;


}


break;


case TARGET_IN:


if(aiMap[iPlayerX][iPlayerY]==TARGET){


aiMap[iPlayerX2][iPlayerY2]=TARGET_IN;


aiMap[iPlayerX1][iPlayerY1]=PERSON;


}else if(aiMap[iPlayerX2][iPlayerY2]==SPACE){


aiMap[iPlayerX2][iPlayerY2]=BOX;


aiMap[iPlayerX1][iPlayerY1]=PERSON;


}else{


break;


}


if(aiMap2[iPlayerX][iPlayerY]==TARGET||aiMap2[iPlayerX][iPlayerY]==TARGET_IN){


aiMap[iPlayerX][iPlayerY]==TARGET;


}else{


aiMap[iPlayerX][iPlayerY]==SPACE;


}


break;


}


}


void GetLevel1(){


int aiMap2[14][16];


int i,j,iSum=0;


int aiMap[14][16]={


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0},


{0,0,0,0,1,1,1,2,2,2,2,1,0,0,0,0},


{0,0,0,1,1,3,4,2,1,1,2,1,1,0,0,0},


{0,0,0,1,2,3,4,6,4,2,2,3,1,0,0,0},


{0,0,0,1,2,3,2,4,2,4,3,1,1,0,0,0},


{0,0,0,1,1,1,1,1,1,2,2,1,0,0,0,0},


{0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


};


for(i=0;i<14;i++){


for(j=0;j<16;j++){


aiMap2[i][j]=aiMap[i][j];


if(aiMap[i][j]==TARGET||aiMap[i][j]==TARGET_IN){


iSum++;


}


}


}


if(PlayGame(aiMap,aiMap2,iSum,2)!=KEY_RETURN){


GetLevel3();


}


}


void GetLevel2(){


int aiMap2[14][16];


int i,j,iSum=0;


int aiMap[14][16]={


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0 《一线大厂 Java 面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】 ,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},


};


for(i=0;i<14;i++){


for(j=0;j<16;j++){


aiMap2[i][j]=aiMap[i][j];


if(aiMap[i][j]==TARGET||aiMap[i][j]==TARGET_IN){


iSum++;


}


}


}


if(PlayGame(aiMap,aiMap2,iSum,2)!=KEY_RETURN){

用户头像

还未添加个人签名 2022.04.13 加入

还未添加个人简介

评论

发布
暂无评论
2021-3-20 【推箱子】_Java_爱好编程进阶_InfoQ写作社区