双人竞走游戏.docx
《双人竞走游戏.docx》由会员分享,可在线阅读,更多相关《双人竞走游戏.docx(22页珍藏版)》请在冰豆网上搜索。
双人竞走游戏
/*
·Ïß¾º×ßÓÎÏ·
*/
#include
/*¹¦ÄܼüÉèÖÃ*/
#defineESC0x001b/*Í˳öÓÎÏ·*/
#defineF10x3b00/*²é¿´°ïÖúÐÅÏ¢£¬µ÷ÓÃHelpMassage()º¯Êý*/
#defineF20x3c00/*É趨ÓÎÏ·Ëٶȵȼ¶£¬µ÷ÓÃSet_Level()º¯Êý*/
#defineF30x3d00/*É趨ÓÎÏ·Õß1µÄÑÕÉ«£¬µ÷ÓÃSet_Color()º¯Êý*/
#defineF40x3e00/*É趨ÓÎÏ·Õß2µÄÑÕÉ«£¬µ÷ÓÃSet_Color()º¯Êý*/
#defineF50x3f00/*ÒÔϹ¦ÄܼüÔÝʱ±£Áô£¬Èç¹ûÔö¼Ó¹¦ÄÜ¿ÉʹÓÃ*/
#defineF60x4000
#defineF70x4100
#defineF80x4200
#defineF90x4300
#defineF100x4400
/*Player1hotkeyÓÎÏ·Õß1ÈȼüÉÏÏÂ×óÓÒ·Ö±ðÓÃRFDG¿ØÖÆ*/
#defineRIGHT171
#defineLEFT168
#defineUP182
#defineDOWN170
/*Player2hotkeyÓÎÏ·Õß2Èȼü£¬Ëĸö¹â±ê¼ü¿ØÖÆ·½Ïò*/
#defineRIGHT0x4d00
#defineLEFT0x4b00
#defineUP0x4800
#defineDOWN0x5000
/*¶¨Òå»·½¿òµÄ×ø±êX£¬Y£¬ÒÔ¼°ÑÕÉ«Color£¬DrawΪÊÇ
(1)·ñ(0)ÒÑ×ß¹ý*/
structinformation
{
intcolor,draw;
intx,y;
};
typedefstructinformationINFOR;
/*¼Ç¼ÓÎÏ·ÕßÔÚ°ÑÔÚλÖã¬XÓëYÆäʵ¾ÍÊÇÈ«¾ÖÊý×écoordinate[][]µÄÁ½¸öϱê*/
structplayerxy
typedefstructplayerxyCurrentCoor;
/*´ËÈ«¾ÖÊý×éÊǼǼ»Ã¿¸ö¿òµÄ×ø±ê¼°ÑÕÉ«ÒÔ¼°ÊÇ·ñÒÑ×ß¹ý*/
INFORcoordinate[80][60];
time_tTimeout=1;/*ÏÞÖÆÓÎÏ·µÄ¿ìÂý£¬¿ÉÓÃSet_Level()É趨*/
intsize=8,maxX=79,maxY=56;/*size¶¨Ò廿òµÄ´óС£¬µ¥Î»ÎªÏñËØ,maxX,maxYΪÊý×écoordinateϱêµÄ×î´óÖµ*/
/*BackColorΪÓÎÏ·±³¾°É«,Player1ColorÓëPlayer2ColorΪÓÎÏ·ÕßĬÈÏÑÕÉ«,¿Éµ÷ÓÃSet_Color()º¯ÊýÉ趨*/
intBackColor=LIGHTBLUE,Player1Color=WHITE,Player2Color=LIGHTRED;
/*³õʼ»¯Í¼ÐÎģʽ*/
voidInitialGraphics(void)
intgraphdriver=VGA,graphmode=VGAHI;
interrorcode;
initgraph(&graphdriver,&graphmode,"C:
\\turboc2");
errorcode=graphresult();
if(errorcode!
=grOk)
printf("Graphicserror:
%s\n",grapherrormsg(errorcode));
GoodBye();
}
/*Í˳öÓÎÏ·ÏÔʾÌáʾÐÅÏ¢£¬Ö»Óв»Äܳõʼ»¯Í¼ÐνçÃæ²Å»áµ÷Óô˺¯Êý*/
intGoodBye(void)
printf("Thankyouforyourplaying!
\n");
printf("Pressanykeytoquit...\n");
GetKey();
exit(0);
/*³õʼ»¯ÓÎÏ·½çÃæ*/
voidInitFace(void)
setbkcolor(BackColor);
cleardevice();
setcolor(WHITE);
rectangle(0,0,639,479);
setcolor(LIGHTGREEN);
rectangle(3,3,636,452);
setcolor(LIGHTRED);
rectangle(3,455,250,476);
rectangle(253,455,636,476);
/*³õʼ»¯È«¾ÖÊý×écoordinate[][]*/
voidInitCoordinate(void)
for(x=0;xfor(y=0;y{coordinate[x][y].color=BackColor;coordinate[x][y].draw=0;coordinate[x][y].x=size*x+4;coordinate[x][y].y=size*y+4;}}/*³õʼ»¯ÓÎÏ·Õß¿ªÊ¼Î»ÖÃ*/voidInitPlayerPlace(CurrentCoor*player1,CurrentCoor*player2){player1->x=maxX/3;player2->x=maxX/3*2;player1->y=maxY/2;player2->y=maxY/2;}/*»¿òº¯Êý£¬playerΪ»¿òλÖã¬whoΪÄÄÒ»¸öÓÎÏ·Õß*/voidDrawbar(CurrentCoorplayer,intwho){intx,y;/*¸ù¾ÝÓÎÏ·ÕßËùÔÚcoordinateµÄϱêλÖÃÈ¡³öÔÚÆÁÄ»ÉϵÄλÖÃ*/x=coordinate[player.x][player.y].x;y=coordinate[player.x][player.y].y;if(who==1){setfillstyle(1,Player1Color);coordinate[player.x][player.y].color=Player1Color;}else{setfillstyle(1,Player2Color);coordinate[player.x][player.y].color=Player2Color;}bar(x,y,x+7,y+7);coordinate[player.x][player.y].draw=1;}/*°ïÖúÐÅÏ¢£¬°´F1µ÷Óô˺¯Êý*/voidHelpMassage(void){setfillstyle(1,WHITE);bar(150,160,500,340);setcolor(LIGHTRED);rectangle(152,162,498,338);setcolor(BLACK);rectangle(154,164,496,180);rectangle(154,182,496,336);setcolor(GREEN);outtextxy(250,170,"RaceWalkingV1.0");setcolor(BLACK);outtextxy(160,190,"Player1controlkey:");outtextxy(160,200,"Player2controlkey:");outtextxy(160,220,"Help:Level:Exit:");outtextxy(160,230,"Playercolor:");setcolor(LIGHTMAGENTA);outtextxy(220,260,"Pressanykeytostart...");setcolor(RED);outtextxy(330,190,"r,f,d,g");outtextxy(330,200,"up,down,left,right");outtextxy(160,220,"F1F2Esc");outtextxy(160,230,"F3/F4");setcolor(BLUE);outtextxy(175,290,"Ifyouhaveanyquestionormodifythese");outtextxy(160,300,"code,Pleasesendemailtome.Thankyou");outtextxy(160,310,"playthisgame!");setcolor(BLACK);outtextxy(410,320,"30/04/2004");}/*»ñÈ¡°´¼ü£¬Èç¹ûµÍ°Ëλ·Ç0ÔòΪASCIIÂ룬ÈçΪ0ÔòΪ¿ØÖƼü*/intGetKey(void){intkey;key=bioskey(0);if(key<<8){key=key&0x00ff;if(isalpha(key))/*Èç¹ûΪ×ÖĸÔòת»»Îª´óд*/key=toupper(key);}returnkey;}/*³õʼ»¯¿ªÊ¼·½Ïò£¬Ö»ÓÐÁ½¸öÓÎÏ·Õ߶¼°´ÏÂÁË·½Ïò¼ü²Å¿ªÊ¼ÓÎÏ·*/voidInitfx(int*player1fx,int*player2fx){intkey;while(!(*player1fx)||!(*player2fx)){key=GetKey();if(key==RIGHT1||key==LEFT1||key==UP1||key==DOWN1)(*player1fx)=key;elseif(key==RIGHT||key==LEFT||key==UP||key==DOWN)(*player2fx)=key;}}/*×îÖ÷Òªº¯Êý£¬¿ØÖÆ»¿ò·½ÏòÒÔ¼°ÅжÏÊÇ·ñÒÑËÀ*/intManageMove(CurrentCoorplayer1,CurrentCoorplayer2){intplayer1fx=0,player2fx=0;/*¼Ç¼ÓÎÏ·Õߵķ½Ïò*/intdie=0,die1=0,die2=0;/*¼Ç¼ÓÎÏ·ÕßÊÇ·ñÒÑËÀ*/intkey;intcurrentfx1,currentfx2;/*¼Ç¼ÓÎÏ·ÕßËù°´µÄ·½Ïò¼ü£¬ËüÐèÓëplayer1fxÓëplayer2fx±È½Ï,È·¶¨ÊÇ·ñתÏò*/clock_tcurrent_time,front_time;/*ÓÃÓÚ¿ØÖÆÓÎÏ·ËٶȵıäÁ¿*/Initfx(&player1fx,&player2fx);currentfx1=player1fx;currentfx2=player2fx;front_time=clock();while(die==0){if(bioskey(1)){key=GetKey();if(key==DOWN1||key==UP1||key==LEFT1||key==RIGHT1)currentfx1=key;elseif(key==DOWN||key==UP||key==LEFT||key==RIGHT)currentfx2=key;}current_time=clock();if((current_time-front_time)>Timeout)/*Èç¹û³¬¹ýÓÎÏ·¼ä¸ôÔò¿ªÊ¼»*/{front_time=current_time;if(player1fx==RIGHT1||player1fx==LEFT1)/*Èç¹ûÏÖÔÚ·½ÏòΪ×ó»òÓÒÔòÖ»Óа´ÏÂÉÏϼü²Å¸Ä±ä·½Ïò£¬·´Ö®Ïàͬ*/{if(currentfx1==UP1||currentfx1==DOWN1){if(currentfx1==UP1)player1.y-=1;elseplayer1.y+=1;player1fx=currentfx1;}else{if(player1fx==RIGHT1)player1.x+=1;elseplayer1.x-=1;}}elseif(player1fx==UP1||player1fx==DOWN1){if(currentfx1==RIGHT1||currentfx1==LEFT1){if(currentfx1==RIGHT1)player1.x+=1;elseplayer1.x-=1;player1fx=currentfx1;}else{if(player1fx==UP1)player1.y-=1;elseplayer1.y+=1;}}if(player2fx==RIGHT||player2fx==LEFT){if(currentfx2==UP||currentfx2==DOWN){if(currentfx2==UP)player2.y-=1;elseplayer2.y+=1;player2fx=currentfx2;}else{if(player2fx==RIGHT)player2.x+=1;elseplayer2.x-=1;}}elseif(player2fx==UP||player2fx==DOWN){if(currentfx2==RIGHT||currentfx2==LEFT){if(currentfx2==RIGHT)player2.x+=1;elseplayer2.x-=1;player2fx=currentfx2;}else{if(player2fx==UP)player2.y-=1;elseplayer2.y+=1;}}if(player1.x<0||player1.x>=maxX||player1.y<0||player1.y>=maxY||coordinate[player1.x][player1.y].draw==1)/*ÅжÏÊÇ·ñµ½±ß½ç»òÊÇÒÑ×ß·£¬Èç¹ûÊÇÔòÍ˳ö£¬·ñÔò»¿ò*/{die1=1;die=1;}elseDrawbar(player1,1);if(player2.x<0||player2.x>=maxX||player2.y<0||player2.y>=maxY||coordinate[player2.x][player2.y].draw==1){die2=1,die=2;}elseDrawbar(player2,2);}}if(die1&&die2)die=3;returndie;}/*É趨ÓÎÏ·µÈ¼¶º¯Êý*/voidSet_Level(void){intkey,pass=0,i=0;clock_tfront_time,current_time;front_time=clock();setfillstyle(1,WHITE);bar(180,150,460,300);setcolor(LIGHTRED);rectangle(182,152,458,298);setcolor(BLACK);rectangle(184,154,456,174);rectangle(184,176,456,296);setcolor(RED);outtextxy(260,160,"LevelSetting");setcolor(BLACK);outtextxy(190,200,"Herehavethreelevel:");outtextxy(190,260,"Pleaseinputanumber[0,1,2]:");setcolor(BLUE);outtextxy(200,220,"0:fast");outtextxy(200,230,"1:normal");outtextxy(200,240,"2:slow");while(pass==0){if(bioskey(1)){key=GetKey();if(key=='0'||key=='1'||key=='2')/*ͨ¹ýÉèÖÃÈ«¾Ö±äÁ¿TimeoutÀ´È·¶¨ÓÎÏ·ËÙ¶È*/{pass=1;if(key=='0')Timeout=0;elseif(key=='1')Timeout=1;elseTimeout=2;}else{setcolor(LIGHTRED);outtextxy(190,280,"Pleaseinput0,1,2!");}}else{current_time=clock();if(current_time-front_time>6)/*¹â±êÉÁ¶¯Ð§¹û£¬²»ÖªËÓиüÓÐЧµÄ·½·¨£¿*/{front_time=current_time;i=(i+1)%2;if(i==0)setcolor(BLACK);elsesetcolor(WHITE);outtextxy(420,260,"_");}}}}/*ÉèÖÃÓÎÏ·ÕßÑÕÉ«£¬Æäʵ¾ÍÊÇÉèÖÃÈ«¾Ö±äÁ¿Player2ColorÓëPlayer1Color£¬¸ù¾ÝwhoÀ´ÅжÏÄÄÒ»¸öÓÎÏ·Õß*/voidSet_Color(intwho){intpass=0,color,key,i=0;intx,y,count;clock_tfront_time,current_time;setfillstyle(1,WHITE);bar(150,160,500,340);setcolor(LIGHTRED);rectangle(152,162,498,338);setcolor(BLACK);rectangle(154,164,496,180);rectangle(154,182,496,336);setcolor(LIGHTRED);if(who==1)outtextxy(245,170,"Player1");elseif(who==2)outtextxy(245,170,"Player2");setcolor(GREEN);outtextxy(245,170,"ColorSetting");setcolor(BLACK);outtextxy(160,190,"Youcanselectundersidecolor:");outtextxy(160,300,"Pleaseinputcolornumber[1-f]:");for(count=1;count<16;count++){x=189+count*16;y=220;setfillstyle(1,count);bar(x,y,x+14,y+40);rectangle(x,y,x+14,y+40);}outtextxy(210,265,"123456789ABCDEF");front_time=clock();while(pass==0){if(bioskey(1)){key=GetKey();if(key>='1'&&key<='9'){pass=1;color=key-'0';}elseif(key>='A'&&key<='F'){pass=1;color=key-55;/*key-'A'+10*/}else{setcolor(LIGHTRED);outtextxy(160,320,"Pleaseinput1to9,oratof!");}}else{current_time=clock();if(current_time-front_time>6){front_time=current_time;i=(i+1)%2;if(i==0)setcolor(BLACK);elsesetcolor(WHITE);outtextxy(410,300,"_");}}
for(y=0;y{coordinate[x][y].color=BackColor;coordinate[x][y].draw=0;coordinate[x][y].x=size*x+4;coordinate[x][y].y=size*y+4;}}/*³õʼ»¯ÓÎÏ·Õß¿ªÊ¼Î»ÖÃ*/voidInitPlayerPlace(CurrentCoor*player1,CurrentCoor*player2){player1->x=maxX/3;player2->x=maxX/3*2;player1->y=maxY/2;player2->y=maxY/2;}/*»¿òº¯Êý£¬playerΪ»¿òλÖã¬whoΪÄÄÒ»¸öÓÎÏ·Õß*/voidDrawbar(CurrentCoorplayer,intwho){intx,y;/*¸ù¾ÝÓÎÏ·ÕßËùÔÚcoordinateµÄϱêλÖÃÈ¡³öÔÚÆÁÄ»ÉϵÄλÖÃ*/x=coordinate[player.x][player.y].x;y=coordinate[player.x][player.y].y;if(who==1){setfillstyle(1,Player1Color);coordinate[player.x][player.y].color=Player1Color;}else{setfillstyle(1,Player2Color);coordinate[player.x][player.y].color=Player2Color;}bar(x,y,x+7,y+7);coordinate[player.x][player.y].draw=1;}/*°ïÖúÐÅÏ¢£¬°´F1µ÷Óô˺¯Êý*/voidHelpMassage(void){setfillstyle(1,WHITE);bar(150,160,500,340);setcolor(LIGHTRED);rectangle(152,162,498,338);setcolor(BLACK);rectangle(154,164,496,180);rectangle(154,182,496,336);setcolor(GREEN);outtextxy(250,170,"RaceWalkingV1.0");setcolor(BLACK);outtextxy(160,190,"Player1controlkey:");outtextxy(160,200,"Player2controlkey:");outtextxy(160,220,"Help:Level:Exit:");outtextxy(160,230,"Playercolor:");setcolor(LIGHTMAGENTA);outtextxy(220,260,"Pressanykeytostart...");setcolor(RED);outtextxy(330,190,"r,f,d,g");outtextxy(330,200,"up,down,left,right");outtextxy(160,220,"F1F2Esc");outtextxy(160,230,"F3/F4");setcolor(BLUE);outtextxy(175,290,"Ifyouhaveanyquestionormodifythese");outtextxy(160,300,"code,Pleasesendemailtome.Thankyou");outtextxy(160,310,"playthisgame!");setcolor(BLACK);outtextxy(410,320,"30/04/2004");}/*»ñÈ¡°´¼ü£¬Èç¹ûµÍ°Ëλ·Ç0ÔòΪASCIIÂ룬ÈçΪ0ÔòΪ¿ØÖƼü*/intGetKey(void){intkey;key=bioskey(0);if(key<<8){key=key&0x00ff;if(isalpha(key))/*Èç¹ûΪ×ÖĸÔòת»»Îª´óд*/key=toupper(key);}returnkey;}/*³õʼ»¯¿ªÊ¼·½Ïò£¬Ö»ÓÐÁ½¸öÓÎÏ·Õ߶¼°´ÏÂÁË·½Ïò¼ü²Å¿ªÊ¼ÓÎÏ·*/voidInitfx(int*player1fx,int*player2fx){intkey;while(!(*player1fx)||!(*player2fx)){key=GetKey();if(key==RIGHT1||key==LEFT1||key==UP1||key==DOWN1)(*player1fx)=key;elseif(key==RIGHT||key==LEFT||key==UP||key==DOWN)(*player2fx)=key;}}/*×îÖ÷Òªº¯Êý£¬¿ØÖÆ»¿ò·½ÏòÒÔ¼°ÅжÏÊÇ·ñÒÑËÀ*/intManageMove(CurrentCoorplayer1,CurrentCoorplayer2){intplayer1fx=0,player2fx=0;/*¼Ç¼ÓÎÏ·Õߵķ½Ïò*/intdie=0,die1=0,die2=0;/*¼Ç¼ÓÎÏ·ÕßÊÇ·ñÒÑËÀ*/intkey;intcurrentfx1,currentfx2;/*¼Ç¼ÓÎÏ·ÕßËù°´µÄ·½Ïò¼ü£¬ËüÐèÓëplayer1fxÓëplayer2fx±È½Ï,È·¶¨ÊÇ·ñתÏò*/clock_tcurrent_time,front_time;/*ÓÃÓÚ¿ØÖÆÓÎÏ·ËٶȵıäÁ¿*/Initfx(&player1fx,&player2fx);currentfx1=player1fx;currentfx2=player2fx;front_time=clock();while(die==0){if(bioskey(1)){key=GetKey();if(key==DOWN1||key==UP1||key==LEFT1||key==RIGHT1)currentfx1=key;elseif(key==DOWN||key==UP||key==LEFT||key==RIGHT)currentfx2=key;}current_time=clock();if((current_time-front_time)>Timeout)/*Èç¹û³¬¹ýÓÎÏ·¼ä¸ôÔò¿ªÊ¼»*/{front_time=current_time;if(player1fx==RIGHT1||player1fx==LEFT1)/*Èç¹ûÏÖÔÚ·½ÏòΪ×ó»òÓÒÔòÖ»Óа´ÏÂÉÏϼü²Å¸Ä±ä·½Ïò£¬·´Ö®Ïàͬ*/{if(currentfx1==UP1||currentfx1==DOWN1){if(currentfx1==UP1)player1.y-=1;elseplayer1.y+=1;player1fx=currentfx1;}else{if(player1fx==RIGHT1)player1.x+=1;elseplayer1.x-=1;}}elseif(player1fx==UP1||player1fx==DOWN1){if(currentfx1==RIGHT1||currentfx1==LEFT1){if(currentfx1==RIGHT1)player1.x+=1;elseplayer1.x-=1;player1fx=currentfx1;}else{if(player1fx==UP1)player1.y-=1;elseplayer1.y+=1;}}if(player2fx==RIGHT||player2fx==LEFT){if(currentfx2==UP||currentfx2==DOWN){if(currentfx2==UP)player2.y-=1;elseplayer2.y+=1;player2fx=currentfx2;}else{if(player2fx==RIGHT)player2.x+=1;elseplayer2.x-=1;}}elseif(player2fx==UP||player2fx==DOWN){if(currentfx2==RIGHT||currentfx2==LEFT){if(currentfx2==RIGHT)player2.x+=1;elseplayer2.x-=1;player2fx=currentfx2;}else{if(player2fx==UP)player2.y-=1;elseplayer2.y+=1;}}if(player1.x<0||player1.x>=maxX||player1.y<0||player1.y>=maxY||coordinate[player1.x][player1.y].draw==1)/*ÅжÏÊÇ·ñµ½±ß½ç»òÊÇÒÑ×ß·£¬Èç¹ûÊÇÔòÍ˳ö£¬·ñÔò»¿ò*/{die1=1;die=1;}elseDrawbar(player1,1);if(player2.x<0||player2.x>=maxX||player2.y<0||player2.y>=maxY||coordinate[player2.x][player2.y].draw==1){die2=1,die=2;}elseDrawbar(player2,2);}}if(die1&&die2)die=3;returndie;}/*É趨ÓÎÏ·µÈ¼¶º¯Êý*/voidSet_Level(void){intkey,pass=0,i=0;clock_tfront_time,current_time;front_time=clock();setfillstyle(1,WHITE);bar(180,150,460,300);setcolor(LIGHTRED);rectangle(182,152,458,298);setcolor(BLACK);rectangle(184,154,456,174);rectangle(184,176,456,296);setcolor(RED);outtextxy(260,160,"LevelSetting");setcolor(BLACK);outtextxy(190,200,"Herehavethreelevel:");outtextxy(190,260,"Pleaseinputanumber[0,1,2]:");setcolor(BLUE);outtextxy(200,220,"0:fast");outtextxy(200,230,"1:normal");outtextxy(200,240,"2:slow");while(pass==0){if(bioskey(1)){key=GetKey();if(key=='0'||key=='1'||key=='2')/*ͨ¹ýÉèÖÃÈ«¾Ö±äÁ¿TimeoutÀ´È·¶¨ÓÎÏ·ËÙ¶È*/{pass=1;if(key=='0')Timeout=0;elseif(key=='1')Timeout=1;elseTimeout=2;}else{setcolor(LIGHTRED);outtextxy(190,280,"Pleaseinput0,1,2!");}}else{current_time=clock();if(current_time-front_time>6)/*¹â±êÉÁ¶¯Ð§¹û£¬²»ÖªËÓиüÓÐЧµÄ·½·¨£¿*/{front_time=current_time;i=(i+1)%2;if(i==0)setcolor(BLACK);elsesetcolor(WHITE);outtextxy(420,260,"_");}}}}/*ÉèÖÃÓÎÏ·ÕßÑÕÉ«£¬Æäʵ¾ÍÊÇÉèÖÃÈ«¾Ö±äÁ¿Player2ColorÓëPlayer1Color£¬¸ù¾ÝwhoÀ´ÅжÏÄÄÒ»¸öÓÎÏ·Õß*/voidSet_Color(intwho){intpass=0,color,key,i=0;intx,y,count;clock_tfront_time,current_time;setfillstyle(1,WHITE);bar(150,160,500,340);setcolor(LIGHTRED);rectangle(152,162,498,338);setcolor(BLACK);rectangle(154,164,496,180);rectangle(154,182,496,336);setcolor(LIGHTRED);if(who==1)outtextxy(245,170,"Player1");elseif(who==2)outtextxy(245,170,"Player2");setcolor(GREEN);outtextxy(245,170,"ColorSetting");setcolor(BLACK);outtextxy(160,190,"Youcanselectundersidecolor:");outtextxy(160,300,"Pleaseinputcolornumber[1-f]:");for(count=1;count<16;count++){x=189+count*16;y=220;setfillstyle(1,count);bar(x,y,x+14,y+40);rectangle(x,y,x+14,y+40);}outtextxy(210,265,"123456789ABCDEF");front_time=clock();while(pass==0){if(bioskey(1)){key=GetKey();if(key>='1'&&key<='9'){pass=1;color=key-'0';}elseif(key>='A'&&key<='F'){pass=1;color=key-55;/*key-'A'+10*/}else{setcolor(LIGHTRED);outtextxy(160,320,"Pleaseinput1to9,oratof!");}}else{current_time=clock();if(current_time-front_time>6){front_time=current_time;i=(i+1)%2;if(i==0)setcolor(BLACK);elsesetcolor(WHITE);outtextxy(410,300,"_");}}
coordinate[x][y].color=BackColor;
coordinate[x][y].draw=0;
coordinate[x][y].x=size*x+4;
coordinate[x][y].y=size*y+4;
/*³õʼ»¯ÓÎÏ·Õß¿ªÊ¼Î»ÖÃ*/
voidInitPlayerPlace(CurrentCoor*player1,CurrentCoor*player2)
player1->x=maxX/3;
player2->x=maxX/3*2;
player1->y=maxY/2;
player2->y=maxY/2;
/*»¿òº¯Êý£¬playerΪ»¿òλÖã¬whoΪÄÄÒ»¸öÓÎÏ·Õß*/
voidDrawbar(CurrentCoorplayer,intwho)
intx,y;/*¸ù¾ÝÓÎÏ·ÕßËùÔÚcoordinateµÄϱêλÖÃÈ¡³öÔÚÆÁÄ»ÉϵÄλÖÃ*/
x=coordinate[player.x][player.y].x;
y=coordinate[player.x][player.y].y;
if(who==1)
{setfillstyle(1,Player1Color);
coordinate[player.x][player.y].color=Player1Color;
else
{setfillstyle(1,Player2Color);
coordinate[player.x][player.y].color=Player2Color;
bar(x,y,x+7,y+7);
coordinate[player.x][player.y].draw=1;
/*°ïÖúÐÅÏ¢£¬°´F1µ÷Óô˺¯Êý*/
voidHelpMassage(void)
setfillstyle(1,WHITE);
bar(150,160,500,340);
rectangle(152,162,498,338);
setcolor(BLACK);
rectangle(154,164,496,180);
rectangle(154,182,496,336);
setcolor(GREEN);
outtextxy(250,170,"RaceWalkingV1.0");
outtextxy(160,190,"Player1controlkey:
");
outtextxy(160,200,"Player2controlkey:
outtextxy(160,220,"Help:
Level:
Exit:
outtextxy(160,230,"Playercolor:
setcolor(LIGHTMAGENTA);
outtextxy(220,260,"Pressanykeytostart...");
setcolor(RED);
outtextxy(330,190,"r,f,d,g");
outtextxy(330,200,"up,down,left,right");
outtextxy(160,220,"F1F2Esc");
outtextxy(160,230,"F3/F4");
setcolor(BLUE);
outtextxy(175,290,"Ifyouhaveanyquestionormodifythese");
outtextxy(160,300,"code,Pleasesendemailtome.Thankyou");
outtextxy(160,310,"playthisgame!
outtextxy(410,320,"30/04/2004");
/*»ñÈ¡°´¼ü£¬Èç¹ûµÍ°Ëλ·Ç0ÔòΪASCIIÂ룬ÈçΪ0ÔòΪ¿ØÖƼü*/
intGetKey(void)
intkey;
key=bioskey(0);
if(key<<8)
key=key&0x00ff;
if(isalpha(key))/*Èç¹ûΪ×ÖĸÔòת»»Îª´óд*/
key=toupper(key);
returnkey;
/*³õʼ»¯¿ªÊ¼·½Ïò£¬Ö»ÓÐÁ½¸öÓÎÏ·Õ߶¼°´ÏÂÁË·½Ïò¼ü²Å¿ªÊ¼ÓÎÏ·*/
voidInitfx(int*player1fx,int*player2fx)
while(!
(*player1fx)||!
(*player2fx))
key=GetKey();
if(key==RIGHT1||key==LEFT1||key==UP1||key==DOWN1)
(*player1fx)=key;
elseif(key==RIGHT||key==LEFT||key==UP||key==DOWN)
(*player2fx)=key;
/*×îÖ÷Òªº¯Êý£¬¿ØÖÆ»¿ò·½ÏòÒÔ¼°ÅжÏÊÇ·ñÒÑËÀ*/
intManageMove(CurrentCoorplayer1,CurrentCoorplayer2)
intplayer1fx=0,player2fx=0;/*¼Ç¼ÓÎÏ·Õߵķ½Ïò*/
intdie=0,die1=0,die2=0;/*¼Ç¼ÓÎÏ·ÕßÊÇ·ñÒÑËÀ*/
intcurrentfx1,currentfx2;/*¼Ç¼ÓÎÏ·ÕßËù°´µÄ·½Ïò¼ü£¬ËüÐèÓëplayer1fxÓëplayer2fx±È½Ï,È·¶¨ÊÇ·ñתÏò*/
clock_tcurrent_time,front_time;/*ÓÃÓÚ¿ØÖÆÓÎÏ·ËٶȵıäÁ¿*/
Initfx(&player1fx,&player2fx);
currentfx1=player1fx;
currentfx2=player2fx;
front_time=clock();
while(die==0)
if(bioskey
(1))
if(key==DOWN1||key==UP1||key==LEFT1||key==RIGHT1)
currentfx1=key;
elseif(key==DOWN||key==UP||key==LEFT||key==RIGHT)
currentfx2=key;
current_time=clock();
if((current_time-front_time)>Timeout)/*Èç¹û³¬¹ýÓÎÏ·¼ä¸ôÔò¿ªÊ¼»*/
front_time=current_time;
if(player1fx==RIGHT1||player1fx==LEFT1)/*Èç¹ûÏÖÔÚ·½ÏòΪ×ó»òÓÒÔòÖ»Óа´ÏÂÉÏϼü²Å¸Ä±ä·½Ïò£¬·´Ö®Ïàͬ*/
if(currentfx1==UP1||currentfx1==DOWN1)
if(currentfx1==UP1)
player1.y-=1;
player1.y+=1;
player1fx=currentfx1;
if(player1fx==RIGHT1)
player1.x+=1;
player1.x-=1;
elseif(player1fx==UP1||player1fx==DOWN1)
if(currentfx1==RIGHT1||currentfx1==LEFT1)
if(currentfx1==RIGHT1)
if(player1fx==UP1)
if(player2fx==RIGHT||player2fx==LEFT)
if(currentfx2==UP||currentfx2==DOWN)
if(currentfx2==UP)
player2.y-=1;
player2.y+=1;
player2fx=currentfx2;
if(player2fx==RIGHT)
player2.x+=1;
player2.x-=1;
elseif(player2fx==UP||player2fx==DOWN)
if(currentfx2==RIGHT||currentfx2==LEFT)
if(currentfx2==RIGHT)
if(player2fx==UP)
if(player1.x<0||player1.x>=maxX||player1.y<0||player1.y>=maxY||coordinate[player1.x][player1.y].draw==1)/*ÅжÏÊÇ·ñµ½±ß½ç»òÊÇÒÑ×ß·£¬Èç¹ûÊÇÔòÍ˳ö£¬·ñÔò»¿ò*/
{die1=1;die=1;}
Drawbar(player1,1);
if(player2.x<0||player2.x>=maxX||player2.y<0||player2.y>=maxY||coordinate[player2.x][player2.y].draw==1)
{die2=1,die=2;}
Drawbar(player2,2);
if(die1&&die2)
die=3;
returndie;
/*É趨ÓÎÏ·µÈ¼¶º¯Êý*/
voidSet_Level(void)
intkey,pass=0,i=0;
clock_tfront_time,current_time;
bar(180,150,460,300);
rectangle(182,152,458,298);
rectangle(184,154,456,174);
rectangle(184,176,456,296);
outtextxy(260,160,"LevelSetting");
outtextxy(190,200,"Herehavethreelevel:
outtextxy(190,260,"Pleaseinputanumber[0,1,2]:
outtextxy(200,220,"0:
fast");
outtextxy(200,230,"1:
normal");
outtextxy(200,240,"2:
slow");
while(pass==0)
if(key=='0'||key=='1'||key=='2')/*ͨ¹ýÉèÖÃÈ«¾Ö±äÁ¿TimeoutÀ´È·¶¨ÓÎÏ·ËÙ¶È*/
pass=1;
if(key=='0')Timeout=0;
elseif(key=='1')Timeout=1;
elseTimeout=2;
outtextxy(190,280,"Pleaseinput0,1,2!
if(current_time-front_time>6)/*¹â±êÉÁ¶¯Ð§¹û£¬²»ÖªËÓиüÓÐЧµÄ·½·¨£¿*/
i=(i+1)%2;
if(i==0)setcolor(BLACK);
elsesetcolor(WHITE);
outtextxy(420,260,"_");
/*ÉèÖÃÓÎÏ·ÕßÑÕÉ«£¬Æäʵ¾ÍÊÇÉèÖÃÈ«¾Ö±äÁ¿Player2ColorÓëPlayer1Color£¬¸ù¾ÝwhoÀ´ÅжÏÄÄÒ»¸öÓÎÏ·Õß*/
voidSet_Color(intwho)
intpass=0,color,key,i=0;
intx,y,count;
outtextxy(245,170,"Player1");
elseif(who==2)
outtextxy(245,170,"Player2");
outtextxy(245,170,"ColorSetting");
outtextxy(160,190,"Youcanselectundersidecolor:
outtextxy(160,300,"Pleaseinputcolornumber[1-f]:
for(count=1;count<16;count++)
x=189+count*16;
y=220;
setfillstyle(1,count);
bar(x,y,x+14,y+40);
rectangle(x,y,x+14,y+40);
outtextxy(210,265,"123456789ABCDEF");
if(key>='1'&&key<='9')
color=key-'0';
elseif(key>='A'&&key<='F')
color=key-55;/*key-'A'+10*/
outtextxy(160,320,"Pleaseinput1to9,oratof!
if(current_time-front_time>6)
outtextxy(410,300,"_");
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1