1、通过C+语言来实现一个烂拦猛以windows控制台为展示平台的简单版五子棋程序,通过键盘输入来控制游戏中的行为光标移动,落子,确认。
2、规则要求衡岁某一方在横竖斜方向连续存在五个或五个以上本人所执棋子获得为获胜,要扒一个已存在的程序时,五子棋的程序,可以在互联网里找到很多。
3、可以使用两个int类型的值来表示,白子-1,黑子-2。
4、光标再次移动会改变已记录的落子信息,为了使光标与棋子饥桥不冲突,使用两个图层,表示两个相同的棋盘。
#include <cstdlib>#include <iostream>
using namespace std
void diaohuan(char shuzhu[],int geshu )
int main(int argc, char *argv[])
{
int geshu,yd
cout<<"请输入棋子(一种)的个数(4的倍数)):"<<endl
cin>>geshu
char shuzhu[100]
int in=0,in1=geshu
for(int n=1n<=geshun++)
{
cout<<" 0 "
shuzhu[in]='0'
in++
}
for(n=1n<=geshun++)
{
cout<<" * "
shuzhu[in1]='*'
in1++
}
for( n=geshu*2n<=geshu*2+2n++)
shuzhu[n]='-'
cout<<"\n你想下棋吗?if you want to play chess,请输入0"<猛慎逗<endl
cin>>yd
if(yd!=0)
{
cout<<"不会下就别捣乱!!"<<endl
system("PAUSE")
return EXIT_SUCCESS
}
else
{
cout<<"欢迎来梦幻棋门!"<<孝局endl
cout<<"loding~~~"枝卖<<endl
cout<<"棋阵为:"<<endl
for(int n=0n<geshu*2+2n++)
cout<<" "<<shuzhu[n]
diaohuan(shuzhu,geshu)
cout<<"最后结果为:"<<endl
for(n=0n<geshu*2+2n++)
cout<<" "<<shuzhu[n]
cout<<endl
system("PAUSE")
return EXIT_SUCCESS
}
}
void diaohuan(char shuzhu[],int geshu )
{
int x=0,y=0,z=4
while(y==0)
{
swap(shuzhu[z-1],shuzhu[z*2])
swap(shuzhu[z],shuzhu[z*2+1])
cout<<endl
for(int n=0n<geshu*2+2n++)
cout<<" "<<shuzhu[n]
z--
swap(shuzhu[z],shuzhu[z*2])
swap(shuzhu[z+1],shuzhu[z*2+1])
cout<<endl
z--
for(n=0n<geshu*2+2n++)
cout<<" "<<shuzhu[n]
swap(shuzhu[z],shuzhu[z*2])
swap(shuzhu[z+1],shuzhu[z*2+1])
cout<<endl
z--
for(n=0n<geshu*2+2n++)
cout<<" "<<shuzhu[n]
swap(shuzhu[z],shuzhu[z*2])
swap(shuzhu[z],shuzhu[z*2+1])
cout<<endl
z--
swap(shuzhu[geshu*2-2],shuzhu[z])
swap(shuzhu[geshu*2-1],shuzhu[z+1])
y++
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)