|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 lihuapinglee 于 2014-9-28 15:43 编辑
int main()
{
srand((unsigned)time(0)); //srand函数用于产生随机数
int i,j;//双层循环变量
Box play;//定义对象play
play.Cin(0,0,'x');
play.Cin(1,0,'A');play.Cin(0,1,'A');
play.Cin(2,0,'B');play.Cin(0,2,'B');
play.Cin(3,0,'C');play.Cin(0,3,'C');
play.Cin(4,0,'D');play.Cin(0,4,'D');
play.Cin(5,0,'E');play.Cin(0,5,'E');
play.Cin(6,0,'F');play.Cin(0,6,'F');
play.Cin(7,0,'G');play.Cin(0,7,'G');
play.Cin(8,0,'H');play.Cin(0,8,'H');
play.Cin(9,0,'I');play.Cin(0,9,'I');
play.Cin(10,0,'J');play.Cin(0,10,'J');
play.Cin(11,0,'K');play.Cin(0,11,'K');
play.Cin(12,0,'L');play.Cin(0,12,'L');
play.Cin(13,0,'M');play.Cin(0,13,'M');
play.Cin(14,0,'N');play.Cin(0,14,'N');
play.Cin(15,0,'O');play.Cin(0,15,'O');
for(i=1;i<16;i++)
for(j=1;j<16;j++)
play.Cin(i,j,empty);
//------------------------以上语句用于初始化棋盘布局
char GAME='X';
REmain://主菜单
system("cls");
cout<<"\n\n\n 五子棋 ";
cout<<"\n\n\nS 单人模式\n\n\nD 双人模式\n\n\nA AI大战\n\n\nQ 退出程序\n\n\n\n请选择:";
GAME='X';cin>>GAME;
if(GAME!='S'&&GAME!='s'&&GAME!='D'&&GAME!='d'&&GAME!='A'&&GAME!='a'&&GAME!='Q'&&GAME!='q')
{
system("cls");
cout<<"\n\n\n无法辨认指令!系统将会自动跳转……";
Sleep(3000);//暂停3S
cin.clear();cin.sync();
goto REmain;
}
if(GAME=='S'||GAME=='s')
{
system("cls");
cout<<"确认选择了【单人模式】 \n\n";
int ts=0;
reS:
play.clearBox();//棋盘清零
letsgo1:
play.player();play.winGame();
if(play.Victory()==WhiteWin)
{
play.showBox();
cout<<"\n\n\n ※ 玩家获胜 ※";
}
else if(play.Victory()==NobodyWin){play.showBox();cout<<"\n\n\n ※ 平局 ※";ts=1;}
else if(play.Victory()==NeverWin){play.AI(computer);play.winGame();}
if(play.Victory()==BlackWin){play.showBox();cout<<"\n\n\n ※ 电脑获胜 ※";}
else if(play.Victory()==NeverWin) goto letsgo1;
else if(ts!=1&&play.Victory()==NobodyWin){play.showBox();cout<<"\n\n\n ※ 平局 ※";}
cout<<"\n\n本局已结束,是否重新开始?(Y/N)";
recs:
char S;
cin.clear();cin.sync();cin>>S;
if(S!='Y'&&S!='y'&&S!='N'&&S!='n'){cout<<"\n请重新输入:";goto recs;}
if(S=='Y'||S=='y'){system("cls");cout<<"重新开始!\n";goto reS;}
if(S=='N'||S=='n') system("cls");cout<<"退出!";Sleep(2000);//重新开始选定模式n
cout<<"\n\n";
}
if(GAME=='D'||GAME=='d')
{
system("cls");
cout<<"确认选择了【双人模式】\n";
int td=0;
reD:
play.clearBox();//棋盘清零
letsgo2:
play.player1();play.winGame();
if(play.Victory()==WhiteWin)
{
play.showBox();
cout<<"\n\n\n ※ 玩家1获胜 ※";
}
else if(play.Victory()==NobodyWin){play.showBox();cout<<"\n\n\n ※ 平局 ※";td=1;}
else if(play.Victory()==NeverWin){play.player2();play.winGame();}
if(play.Victory()==BlackWin)
{play.showBox();cout<<"\n\n\n ※ 玩家2获胜 ※";}
else if(play.Victory()==NeverWin) goto letsgo2;
else if(td!=1&&play.Victory()==NobodyWin){play.showBox();cout<<"\n\n\n ※ 平局 ※";}
cout<<"\n\n本局已结束,是否重新开始?(Y/N)";
recd:
char S;
cin.clear();cin.sync();cin>>S;
if(S!='Y'&&S!='y'&&S!='N'&&S!='n'){cout<<"\n非法指令!请重新输入:";goto recd;}
if(S=='Y'||S=='y'){system("cls");cout<<"--------------------------------------------------------------------------------\n";cout<<"确认重新开始本模式……\n";goto reD;}
if(S=='N'||S=='n') system("cls");cout<<"--------------------------------------------------------------------------------\n";cout<<"\n确认退出该模式,";Sleep(500);//重新开始选定模式
cout<<"\n\n\n--------------------------------------------------------------------------------\n";
}
if(GAME=='A'||GAME=='a')
{
system("cls");
cout<<"--------------------------------------------------------------------------------\n--------------------------------------------------------------------------------";
cout<<"\n确认选择了【AI大战】……\n";
int t3=0;
re3:
float Sleeptime;cout<<"\n\n请输入你想要的AI思考时间(单位秒,支持小数):";cin>>Sleeptime;if(Sleeptime<0){system("cls");cout<<"--------------------------------------------------------------------------------\n输入出错!";goto re3;}
cout<<"\n\n已确认AI的睡眠时间为"<<Sleeptime<<"秒。\n\n\n\n系统将在AI作出判断前暂停"<<Sleeptime<<"秒钟。\n\n\n\n\n";Sleep(1000);
play.clearBox();//棋盘清零
letsgo3:
cout<<"\n【电脑1】正在冥思苦想……囧";Sleep(1000*Sleeptime);
play.AI(white);play.winGame();
if(play.Victory()==WhiteWin)
{
play.showBox();
cout<<"\n\n\n ※ 电脑1获胜 ※";
}
else if(play.Victory()==NobodyWin){play.showBox();cout<<"\n\n\n ※ 平局 ※";t3=1;}
else if(play.Victory()==NeverWin){play.showBox();cout<<"\n【电脑2】正在冥思苦想……囧 ";Sleep(1000*Sleeptime);play.AI(black);play.winGame();play.showBox();}
if(play.Victory()==BlackWin)
cout<<"\n\n\n ※ 电脑2获胜 ※";
else if(play.Victory()==NeverWin) goto letsgo3;
else if(t3!=1&&play.Victory()==NobodyWin){play.showBox();cout<<"\n\n\n ※ 平局 ※";}
cout<<"\n\n本局已结束,是否重新开始?(Y/N)";
char S;
rec3:
cin.clear();cin.sync();cin>>S;
if(S!='Y'&&S!='y'&&S!='N'&&S!='n'){S='X';cout<<"\n非法指令!请重新输入:";goto rec3;}
if(S=='Y'||S=='y'){system("cls");cout<<"--------------------------------------------------------------------------------\n";cout<<"\n确认重新开始本模式……\n\n";goto re3;}
if(S=='N'||S=='n') system("cls");cout<<"--------------------------------------------------------------------------------\n";cout<<"\n确认退出该模式,";Sleep(500);//重新开始选定模式
cout<<"\n\n\n--------------------------------------------------------------------------------\n";
}
if(GAME=='Q'||GAME=='q')
{system("cls");}
cout<<"\n指令【退出程序】已经执行……\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
Sleep(1000);
return 0;
}
|
|