飞行棋的代码.docx
- 文档编号:30322590
- 上传时间:2023-08-13
- 格式:DOCX
- 页数:18
- 大小:17.07KB
飞行棋的代码.docx
《飞行棋的代码.docx》由会员分享,可在线阅读,更多相关《飞行棋的代码.docx(18页珍藏版)》请在冰豆网上搜索。
飞行棋的代码
#include
#include
#include
#include
#include
#include"windows.h"
charPlayer1[10];//玩家1姓名
charPlayer2[10];//玩家2姓名
charName1[10]="Sun";//可选择的玩家姓名
charName2[10]="Lun";
charName3[10]="Run";
charName4[10]="Aun";
intPlayer1X=11;//玩家1,X的坐标
intPlayer1Y=0;//玩家1,Y的坐标
intPlayer2X=11;//玩家2,X的坐标
intPlayer2Y=0;//玩家2,Y的坐标
intn=0;//记录掷骰子的局数
intMap[13][30]=
{1,1,1,5,1,1,1,3,1,1,1,1,1,5,1,1,1,1,1,1,1,4,1,1,1,1,1,1,3,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,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,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,4,
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,
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,2,1,1,3,1,1,1,1,1,2,1,1,1,1,3,5,1,1,1,1,1,4,1,1,1,5,1,
4,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,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,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,
5,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,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,4,1,1,5,1,1,1,1,4,1,1,3,1,1,1,1,1,1,4,1,1,1,3,1,1,1,1};//地图的数组
//使走过的关卡变成道路
voidGoToXYSpace(intx,inty)
{
COORDpos={x,y};
HANDLEhOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
printf(":
:
");
}
//闯关完成的提示
voidGoToXYEnd(intx,inty,inti)
{
COORDpos={x,y};
HANDLEhOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
printf("玩家%d闯关成功!
!
!
!
",i);
}
//抹掉幸运轮盘底部的提示
voidGOToK(intx,inty)
{
COORDpos={x,y};
HANDLEhOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
printf("\n");
}
//地图底部的提示
voidGoToPrompt(intx,inty,intnum1,intnum2,inti)
{
COORDpos={x,y};
HANDLEhOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
fflush(stdin);
printf("玩家%d掷出了%d点按回车键继续.第%d回合玩家%d掷骰子",num2,i,n,num1);
}
//停止关卡的提示
voidGoToStop(intx,inty,intnum)
{
COORDpos={x,y};
HANDLEhOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
fflush(stdin);
printf("按回车键继续.第%d回合玩家%d此回合停止",n,num);
}
//玩家1的打印
voidGoToXYP1(intx,inty)//玩家1
{
COORDpos={x,y};
HANDLEhOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
printf("%c%c",Player1[0],Player1[0]);
}
//玩家2的打印
voidGoToXYP2(intx,inty)//玩家2
{
COORDpos={x,y};
HANDLEhOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
printf("%c%c",Player2[0],Player2[0]);
}
//幸运轮盘的提示
voidGoToLuck(intx,inty)
{
COORDpos={x,y};
HANDLEhOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
fflush(stdin);
printf("恭喜你可以实现一个愿望,请选择:
\n");
printf("1.与对方交换位置\n");
printf("2.轰炸对方使其退后6步\n");
printf("请选择:
");
}
//游戏开始的提示
voidGoToStart(intx,inty)//开始
{
COORDpos={x,y};
HANDLEhOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
fflush(stdin);
printf("按回车键开始.玩家1开始掷骰子");
}
//产生随机数
intRandom()
{
srand(time(NULL));
return(rand()%6+1);
}
//对玩家1的各种判断
voidDice1(inti)
{
if(Player1X==Player2X&&Player1Y==Player2Y)
GoToXYP2(Player1X,Player1Y);
else
GoToXYSpace(Player1X,Player1Y);//打印道路
Map[Player1Y][(Player1X-11)/2]=1;
if(Player1X<69&&Player1Y==0)//第一横行
{
Player1X+=i*2;
if(Player1X>69)
{
Player1Y+=(Player1X-69)/2;
Player1X=69;
}
GoToXYP1(Player1X,Player1Y);
}
elseif(Player1X==69&&Player1Y<=6)//第一竖行
{
Player1Y+=i;
if(Player1Y>6)
{
Player1X-=(Player1Y-6)*2;
Player1Y=6;
}
GoToXYP1(Player1X,Player1Y);
}
elseif(Player1X<69&&Player1Y==6)//逆行
{
Player1X-=i*2;
if(Player1X<11)
{
Player1Y+=(11-Player1X)/2;
Player1X=11;
}
GoToXYP1(Player1X,Player1Y);
}
elseif(Player1X==11&&Player1Y>=6)//第二竖行
{
Player1Y+=i;
if(Player1Y>12)
{
Player1X+=(Player1Y-12)*2;
Player1Y=12;
}
GoToXYP1(Player1X,Player1Y);
}
elseif(Player1X<=69&&Player1Y==12)//最后一行
{
Player1X+=i*2;
if(Player1X>69)
Player1X=69;
GoToXYP1(Player1X,Player1Y);
}
}
//对玩家2的各种打印,步骤如玩家1
voidDice2(inti)
{
if(Player1X==Player2X&&Player1Y==Player2Y)
GoToXYP1(Player2X,Player2Y);
else
GoToXYSpace(Player2X,Player2Y);
Map[Player2Y][(Player2X-11)/2]=1;
if(Player2X<69&&Player2Y==0)
{
Player2X+=i*2;
if(Player2X>69)
{
Player2Y+=(Player2X-69)/2;
Player2X=69;
}
GoToXYP2(Player2X,Player2Y);
}
elseif(Player2X==69&&Player2Y<=6)
{
Player2Y+=i;
if(Player2Y>6)
{
Player2X-=(Player2Y-6)*2;
Player2Y=6;
}
GoToXYP2(Player2X,Player2Y);
}
elseif(Player2X<69&&Player2Y==6)//逆行
{
Player2X-=i*2;
if(Player2X<11)
{
Player2Y+=(11-Player2X)/2;
Player2X=11;
}
GoToXYP2(Player2X,Player2Y);
}
elseif(Player2X==11&&Player2Y>=6)
{
Player2Y+=i;
if(Player2Y>12)
{
Player2X+=(Player2Y-12)*2;
Player2Y=12;
}
GoToXYP2(Player2X,Player2Y);
}
elseif(Player2X<=69&&Player2Y==12)
{
Player2X+=i*2;
if(Player2X>69)
Player2X=69;
GoToXYP2(Player2X,Player2Y);
}
}
//地图的打印
voidPrintMap(intMap[][30])
{
inti,j;
for(i=0;i<13;i++)
for(j=0;j<30;j++)
{
if(j==0)
printf("");
switch(Map[i][j])
{
case0:
printf("");break;
case1:
printf(":
:
");break;
case2:
printf("¤");break;
case3:
printf("★");break;
case4:
printf("■");break;
case5:
printf("〓");break;
}
if(j==29)
printf("\n");
}
}
//开始界面的打印
voidPrintstart()
{
printf("|¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤|\n");
printf("||\n");
printf("|骑士飞行棋|\n");
printf("||\n");
printf("|¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤|\n");
printf("\n两人对战\n\n");
printf("请选择角色:
1.Sun\n");
printf("2.Lun\n");
printf("3.Run\n");
printf("4.Aun");
}
//游戏说明的打印
voidPrintEx()
{
printf("|¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤|\n");
printf("||\n");
printf("|游戏说明|\n");
printf("||\n");
printf("|¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤|\n");
printf("玩家选择的角色以两个首字母为代表如Saber(SS)\n");
printf("\n图标:
:
代表普通道路\n");
printf("\n图标■代表暂停一回合掷骰子\n");
printf("\n图标★代表地雷踩中退后6步\n");
printf("\n图标¤代表幸运轮盘可选择与对方互换或轰炸对方\n");
printf("\n图标〓代表时空隧道前进10步\n");
printf("\n地图共100步,谁率先到达终点则胜利\n");
printf("按回车键开始游戏:
");
}
//角色的选择
voidSelect()
{
inti;
printf("\n请玩家1选择角色:
");
scanf("%d",&i);
if(i==1)
strcpy(Player1,Name1);
elseif(i==2)
strcpy(Player1,Name2);
elseif(i==3)
strcpy(Player1,Name3);
elseif(i==4)
strcpy(Player1,Name4);
printf("\n请玩家2选择角色:
");
scanf("%d",&i);
if(i==1)
strcpy(Player2,Name1);
elseif(i==2)
strcpy(Player2,Name2);
elseif(i==3)
strcpy(Player2,Name3);
elseif(i==4)
strcpy(Player2,Name4);
}
//主函数
intmain()
{
system("colora");
charch;
Printstart();//打印开始
Select();//角色
system("cls");//清屏
PrintEx();
ch=getch();
system("cls");
PrintMap(Map);//打印地图
while
(1)
{
n++;//记录局数
inti,j,a;
if(Player1X==11&&Player1Y==0)//开始提示的条件
{
GoToStart(11,15);
ch=getch();
}
if(Map[Player1Y][(Player1X-11)/2]==4)//是否暂停
{
Map[Player1Y][(Player1X-11)/2]=1;
GoToStop(11,15,1);
getchar();
GoToPrompt(11,15,2,1,i);
getchar();
}
else
{
i=Random();
Dice1(i);
if(Player1X==69&&Player1Y==12)//是否到终点
{
GoToXYEnd(24,20,1);
getchar();
return0;
}
GoToPrompt(11,15,2,1,i);
if(Map[Player1Y][(Player1X-11)/2]==5)//是否时空隧道
{
i=10;
Dice1(i);
}
if(Map[Player1Y][(Player1X-11)/2]==3)//炸弹
{
i=-6;
Dice1(i);
}
if(Map[Player1Y][(Player1X-11)/2]==2)//幸运轮盘
{
GoToLuck(11,16);
scanf("%d",&j);
getchar();
if(j==1)
{
a=Player1X;
Player1X=Player2X;
Player2X=a;
a=Player1Y;
Player1Y=Player2Y;
Player2Y=a;
GoToXYP1(Player1X,Player1Y);
GoToXYP2(Player2X,Player2Y);
}
if(j==2)
{
i=-6;
Dice2(i);
}
GOToK(10,16);
GOToK(10,17);
GOToK(10,18);
GOToK(10,19);
}
getchar();
}
if(Map[Player2Y][(Player2X-11)/2]==4)
{
Map[Player2Y][(Player2X-11)/2]=1;
GoToStop(11,15,2);
getchar();
GoToPrompt(11,15,1,2,i);
getchar();
}
else
{
i=Random();
Dice2(i);
if(Player2X==69&&Player2Y==12)
{
GoToXYEnd(24,20,2);
getchar();
return0;
}
GoToPrompt(11,15,1,2,i);
if(Map[Player2Y][(Player2X-11)/2]==5)
{
i=10;
Dice2(i);
}
if(Map[Player2Y][(Player2X-11)/2]==3)
{
i=-6;
Dice2(i);
}
if(Map[Player2Y][(Player2X-11)/2]==2)
{
GoToLuck(11,16);
scanf("%d",&j);
getchar();
if(j==1)
{
a=Player1X;
Player1X=Player2X;
Player2X=a;
a=Player1Y;
Player1Y=Player2Y;
Player2Y=a;
GoToXYP1(Player1X,Player1Y);
GoToXYP2(Player2X,Player2Y);
}
if(j==2)
{
i=-6;
Dice1(i);
}
GOToK(10,16);
GOToK(10,17);
GOToK(10,18);
GOToK(10,19);
}
getchar();
}
}
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 飞行 代码
![提示](https://static.bdocx.com/images/bang_tan.gif)