首页 > 其他分享 >【转载】Game 2

【转载】Game 2

时间:2023-06-17 22:44:54浏览次数:29  
标签:case cml cc system break Game 转载 col

改版五子棋 version 3.0

更新日志:

  1. v1.0 修改了bug【源码来源:链接 | yzmyyds】
  2. v2.0 添加了command mode
  3. v3.0 添加了脚本模式(代码长度从196行加到660行

脚本示例

0000000000001820000

0000000000000000100

0000000000000010000

0000000000000000200

0000000001000000000

0000000000000000200

0000022200000000000

0000000000000000200

0000000000000000100

0000000000000000100

0000000000000000000

0000000000000000000

0000000000000000000

0000000000000000000

0000000000000000000

0000000000000000000

0000000000000000000

0000000000000000000

0000000000000000200

off record

gamerule set black at bw true

gameevent clean black

gameevent put black a b

gemeevent remove

gameevent become 1 to 2

win black


#include<iostream>
#include<string> 
#include<windows.h> 
#include<conio.h>
#include <stdio.h>
using namespace std;
    int shu=1,heng=1,pie=1,na=1;//横竖撇捺 
    int col=1;
    char a[3]={'1','0','\0'},a1[3]={'2','0','\0'},a2[3]={'3','0','\0'},a3[3]={'4','0','\0'},a4[3]={'5','0','\0'},a5[3]={'6','0','\0'},a6[3]={'7','0','\0'},a7[3]={'8','0','\0'},a8[3]={'9','0','\0'};
    bool cci=0,ifd=0,wcan=0,bcan=0; int qiPan[19][19]; int qiPanTwo[19][19]; 
void cml()
{
    if(cci==1)
 {

    char cc[8]={'c','o','l','o','r',' ',NULL,NULL};
    switch(col)
     {
        case 1:
        strcat(cc,a);
        system(cc); 
        col++;

        if(col>=7)
        {
            col=1;
        }
        break;
        case 2:
        strcat(cc,a1);
        system(cc); 
        col++;

        if(col>=7)
        {
            col=1;
        }
        break;
        case 3:
        strcat(cc,a2);
        system(cc); 
        col++;

        if(col>=7)
        {
            col=1;
        }
        break;
        case 4:
        strcat(cc,a3);
        system(cc); 
        col++;

        if(col>=7)
        {
            col=1;
        }
        break;
        case 5:
        strcat(cc,a4);
        system(cc); 
        col++;

        if(col>=7)
        {
            col=1;
        }
        break;
        case 6:
        strcat(cc,a5);
        system(cc); 
        col++;

        if(col>=7)
        {
            col=1;
        }
        break;
        case 7:
        strcat(cc,a6);
        system(cc); 
        col++;

        if(col>=7)
        {
            col=1;
        }
        break;
        case 8:
        strcat(cc,a7);
        system(cc); 
        col++;

        if(col>=7)
        {
            col=1;
        }
        break;
        case 9:
        strcat(cc,a8);
        system(cc); 
        col++;
        if(col>=7)
        {
            col=1;
        }
        break;
      } 

  }}
  void pr()
  {
     system("cls");  
    for(int h=0;h<19;h++) 
 {
  for(int l=0;l<19;l++)
  {
  if(qiPan[h][l]==8)
  {
   cout<<"+";
  }
  else if(qiPanTwo[h][l]==0)
  {
   cout<<"·";
  }
  else if(qiPanTwo[h][l]==1)
  {

   cout<<"○";
  }
  else if(qiPanTwo[h][l]==2)
  {
    cout<<"●";

  } 
  }
  cout<<endl;
 }
   } 

int main()
{
pr();
 FILE * fp;
 FILE * set;
 fp = fopen ("record.txt", "w+");
 int player=2;  //定义一个玩家,当1时为白方,2时为黑方 
 system("title 请黑棋子");
 system("color f0");
 int tot=0,toa=0,tob=0;
 MessageBox(NULL,"华夏旧戏:五子棋","迎",MB_ICONINFORMATION);
 MessageBox(NULL,"一.汝勿在棋上置棋\n二.wasd制移,按j键子","法",MB_ICONINFORMATION);
 //................................棋盘1..............................................
 //1.声明一个19行19列的数组来存储棋盘 1 
 for(int h=0;h<19;h++) //对数组进行遍历,所有元素进行初始化(赋值),默认为0值 
 {cml();
 for(int l=0;l<19;l++)
 {cml();
  qiPan[h][l]=0; //对当前元素进行初始化(赋值),默认为0值
 }
 }
 //...............................棋盘2................................................
 //声明一个19行19列的数组来存储棋盘 2
 for(int h=0;h<19;h++) //对数组进行遍历,所有元素进行初始化(赋值),默认为0值 
 {cml();
 for(int l=0;l<19;l++)
 {cml();
  qiPanTwo[h][l]=0; //对当前元素进行初始化(赋值),默认为0值
 }
 }
 //...............................光标声明.............................................
 int X=9;   //2.声明并初始化光标的横纵坐标 
 int Y=9;   
 qiPan[9][9]=8;
 //..............................显示...................................................
 for(int h=0;h<19;h++) 
 {
  for(int l=0;l<19;l++)
  {
  if(qiPan[h][l]==8)
  {
   cout<<"  ";
  }
  else if(qiPanTwo[h][l]==0)
  {
   cout<<" ·";
  }
  else if(qiPanTwo[h][l]==1)
  {
    cout<<" ○";
  }
  else if(qiPanTwo[h][l]==2)
  {
   cout<<" ●";
  } 
  }
  cout<<endl;cml();
 }
 pr();
 //..............................输入控制...............................................
 while(true)
 {
    cml();
 a: 
 if(_kbhit())
 {
 string cmd;
 char xx=getch();cml();  //控制台从键盘获得一个字符 
 switch(xx)   //控制
 {
    cml();
  case 'c':
  system("title Commend Mode");
  cin>>cmd;
  if(cmd=="read")
  {
  	char cm[100];
  	cin>>cm;
  	set=fopen(cm,"r");
  	cout<<cm<<" ";
  	rewind(set);
   char nowin,y[100];
   do
   {
      if( feof(set) )
      {
      	cout<<"end";
          break ;
      }
//      fgets(y,100,set);
//      if(strcmp(y,"not have map")!=NULL)
//      {
//      	goto as;
//	  }
	  fgets(y,100,set);
      cout<<"&"<<y<<"&"<<endl;
      if(strstr(y,"not have map")) goto aaa;
      for(int i=0;i<=19;i++)
      {
      	for(int j=0;j<=19;j++)
      	{
      		nowin=fgetc(set);
      		cout<<nowin<<" ";
			  if(nowin!='8'&&(nowin=='1'||nowin=='2'||nowin=='0'))
			  {
			  	qiPanTwo[i][j]=(int)nowin-48;
			  }
			  if(nowin=='8')
			  {
			  	qiPan[i][j]=8;
			  }
		}
	  }
aaa:	  
	  for(int i=0;i<19;i++)
      {
      	for(int j=0;j<19;j++)
      	{
      		cout<<qiPanTwo[i][j]<<" ";
		}
		cout<<'\n';
	  }
	 as: 
	  while(1)
	  {
	  	if( feof(set) )
      {
      	cout<<"end";
          break ;
      }
      fgets(y,100,set);
      cout<<"&"<<y<<"&"<<endl;
      if(strstr(y,"off")) fclose(fp);
      if(strstr(y,"on"))
      {
      	 FILE * fp;
         fp = fopen ("record.txt", "w+");cml();system("title 等待用户操作");
         break;
	  }
	  
	  if(strstr(y,"set"))
	  {
	  	if(strstr(y,"gamerule"))
	  	{
	  		if(strstr(y,"black"))
	  		{
	  			if(strstr(y,"true"))
	  			{
	  				bcan=1;
				  }
				  if(strstr(y,"false"))
	  			{
	  				bcan=0;
				  }
			  }
			  if(strstr(y,"white"))
	  		{
	  			if(strstr(y,"true"))
	  			{
	  				wcan=1;
				  }
				  if(strstr(y,"false"))
	  			{
	  				wcan=0;
				  }
			  }
		  }
	}
	 if(strstr(y,"change"))
	  	{
	  		if(strstr(y,"black"))
	  		{
	  			player=2;
			  }
			  if(strstr(y,"white"))
	  		{
	  		player=1;
			  }
		  }
		  if(strstr(y,"put"))
	  	{
	  		if(strstr(y,"black"))
	  		{
	  			int x=(int)y[20]-97,yy=(int)y[22]-97;
	  			cout<<"*"<<y[20]<<"|"<<y[22]<<"*";
	  			cout<<x<<" "<<yy<<"|";
	  			qiPanTwo[x][yy]=2;
	  			pr();
			  }
			  if(strstr(y,"white"))
	  		{
	  		int x=(int)y[20]-97,yy=(int)y[22]-97;
	  		cout<<"*"<<y[20]<<"|"<<y[22]<<"*";
	  			qiPanTwo[x][yy]=1;
	  			pr();
			  }
			  if(strstr(y,"none"))
			  {
			  	int x=(int)y[20]-97,yy=(int)y[22]-97;
	  		cout<<"*"<<y[20]<<"|"<<y[22]<<"*";
	  			qiPanTwo[x][yy]=0;
	  			pr();
			  }
		  }
	  if(strstr(y,"win"))
	  	{
	  		if(strstr(y,"black"))
	  		{
	  			goto n;cml();
			  }
			  if(strstr(y,"white"))
	  		{
	  		goto m;cml();
			  }
		  }
		  if(strstr(y,"remove"))
	  	{
	  		for(int i=0;i<=19;i++)
      {
      	for(int j=0;j<=19;j++)
      	{
      		if(qiPanTwo[i][j]==2)
      		{
      			qiPanTwo[i][j]=1;
			  }
			  if(qiPanTwo[i][j]==1)
			  {
			  	qiPanTwo[i][j]=2;
			  }
      	}
		  }
		  pr();
		  }
		  if(strstr(y,"become"))
	  	{
	  	int x=(int)y[17]-48,yy=(int)y[22]-48;//17 22
	  	cout<<x<<" "<<yy<<endl;
	  	for(int i=0;i<=19;i++)
      {
      	for(int j=0;j<=19;j++)
      	{
      		if(qiPanTwo[i][j]==x)
      		{
      			qiPanTwo[i][j]=yy;
			  }
      	}
		  }
		  pr();
		  }
		  if(strstr(y,"clean"))
	  	{
	  		if(strstr(y,"black"))
	  		{
	  	for(int i=0;i<=19;i++)
      {
      	for(int j=0;j<=19;j++)
      	{
      		if(qiPanTwo[i][j]==2)
      		{
      			qiPanTwo[i][j]=0;
			  }
      	}
		  }
      	
			  }
			  if(strstr(y,"white"))
	  		{
	  		for(int i=0;i<=19;i++)
      {
      	for(int j=0;j<=19;j++)
      	{
      		if(qiPanTwo[i][j]==1)
      		{
      			qiPanTwo[i][j]=0;
			  }
      	}
		  }
			  }
			  pr();
		  }
		  }	
   }while(1);
	system("pause");
   fclose(set);	
  }
    if(cmd=="win_b") 
      {system("title 等待用户操作");
        goto n;cml();
        break;
      }
    if(cmd=="win_w")
      {system("title 等待用户操作");
        goto m;cml();
        break;
       } 
    if(cmd=="down_at_this_b") 
      {system("title 等待用户操作");
        goto ac;cml();
        break;
      } 
    if(cmd=="down_at_this_w") 
      {system("title 等待用户操作");
        goto ab;cml();
        break;
      }
    if(cmd=="game_title")
    {
    cout<<'\n';
        char ls[50];cml();
        cin>>ls;cml();
        char lls[100]={'t','i','t','l','e',' '};cml();
        strcat(lls,ls);cml();
        system(lls);cml();
        ifd=1;
        break;
      }
    if(cmd=="off_record")
    {
        fclose(fp);cml();system("title 等待用户操作");
        break;
      }
    if(cmd=="on_record")
    {
        FILE * fp;
         fp = fopen ("record.txt", "w+");cml();system("title 等待用户操作");
         break;
      } 
      if(cmd=="dj")
      {
        cci=1;cml();system("title 等待用户操作");
        break;
      }
    system("title 等待用户操作");
  break;
  cml();
  case 'w':   //上
  if(Y==0)
  {
  	cml();
        MessageBox(NULL,"汝不可越界","不讲武德!",MB_ICONEXCLAMATION); 
        goto a;
  }
  Y=Y-1; cml(); //使光标纵坐标-1 
  qiPan[Y][X]=8; //讲光标写入棋盘 
  qiPan[Y+1][X]=0; //使原本位置的值还原 
  break;
  case 's':  //下
  if(Y==18)
  {
  	cml();
        MessageBox(NULL,"汝不可越界","不讲武德!",MB_ICONEXCLAMATION); 
        goto a;
  }
  Y=Y+1;cml();
  qiPan[Y][X]=8;
  qiPan[Y-1][X]=0; 
  break; 
  case 'a':  //左
  if(X==0)
  {
  	cml();
        MessageBox(NULL,"汝不可越界","不讲武德!",MB_ICONEXCLAMATION); 
        goto a;
  }
  X=X-1;cml();
  qiPan[Y][X]=8;
  qiPan[Y][X+1]=0; 
  break;
  case 'd':  //右
  if(X==18)
  {
  	cml();
        MessageBox(NULL,"汝不可越界","不讲武德!",MB_ICONEXCLAMATION); 
        goto a;
  }
  X=X+1;cml();
  qiPan[Y][X]=8;
  qiPan[Y][X-1]=0; 
  break; 
  case 'j':   //落子 
  if(player==1)  //如果当前玩家为白色方时 
  {cml();
    if(qiPanTwo[Y][X]!=0&&wcan==0)
    {
        cml();
        MessageBox(NULL,"汝不可在棋上置棋","不讲武德!",MB_ICONEXCLAMATION); 
        fprintf(fp,"白棋不讲武德!\n");
        player=1;
        toa++;
        goto a;
      }
      cml();
      ab:
      fprintf(fp,"%c %d %d \n",'w',Y,X);
   qiPanTwo[Y][X]=1; //通过棋盘1中的光标位置更改棋盘2中对应元素的值为1,也就是白棋落子
   player=2;  //白棋落子后更换玩家 
   if(ifd==0)
   {
    system("title 请黑棋子");
    } 

   tot++; cml();
  }
  else if(player==2) 
  {
    if(qiPanTwo[Y][X]!=0&&bcan==0)
    {
        cml();
        MessageBox(NULL,"汝不可在棋上置棋","不讲武德!",MB_ICONEXCLAMATION); 
        fprintf(fp,"黑棋不讲武德!\n");
        player=2;
        tob++;
        goto a;
      }
      ac:
        cml();
      fprintf(fp,"%c %d %d \n",'b',Y,X);
   qiPanTwo[Y][X]=2;
   player=1;
   if(ifd==0)
   {
    system("title 请白棋子"); 
    } 

   tot++;
  }
  break;    
 }
 pr(); 

}

 //................................清屏操作................................................ 

 //...............................打印.....................................................

 shu=1,heng=1,pie=1,na=1;cml();
 //.........................游戏规则..............................................
 for(int i=1;i<=4;i++) //上 
 {cml();
  if(qiPanTwo[Y+i][X]==qiPanTwo[Y][X]&&qiPanTwo[Y][X]!=0)
  shu++;
  else
  break; 
 }cml();
 for(int i=1;i<=4;i++) //下 
 {cml();
  if(qiPanTwo[Y-i][X]==qiPanTwo[Y][X]&&qiPanTwo[Y][X]!=0)
  shu++;
  else
  break; 
 }cml();
 for(int i=1;i<=4;i++) //左 
 {cml();
  if(qiPanTwo[Y][X-i]==qiPanTwo[Y][X]&&qiPanTwo[Y][X]!=0)
  heng++;
  else
  break; 
 }
 for(int i=1;i<=4;i++) //右 
 {cml();
  if(qiPanTwo[Y][X+i]==qiPanTwo[Y][X]&&qiPanTwo[Y][X]!=0)
  heng++;
  else
  break; 
 }cml();
 for(int i=1;i<=4;i++) //左下 
 {cml();
  if(qiPanTwo[Y+i][X-i]==qiPanTwo[Y][X]&&qiPanTwo[Y][X]!=0)
  pie++;
  else
  break; 
 }cml();
 for(int i=1;i<=4;i++) //右上 
 {cml();
  if(qiPanTwo[Y-i][X+i]==qiPanTwo[Y][X]&&qiPanTwo[Y][X]!=0)
  pie++;
  else
  break; 
 }cml();
 for(int i=1;i<=4;i++) //右下 
 {cml();
  if(qiPanTwo[Y+i][X+i]==qiPanTwo[Y][X]&&qiPanTwo[Y][X]!=0)
  na++;
  else
  break; 
 }
 for(int i=1;i<=4;i++) //左上 
 {cml();
  if(qiPanTwo[Y-i][X-i]==qiPanTwo[Y][X]&&qiPanTwo[Y][X]!=0)
  na++;
  else
  break; 
 }
 if(shu==5||heng==5||pie==5||na==5)
 {cml();
  if(qiPanTwo[Y][X]==1)
  {cml();
m:
   cout<<"白子胜!";
   MessageBox(NULL,"请查看Record.txt","终",MB_ICONEXCLAMATION);
   fprintf(fp,"白子胜!");
   system("pause");
   break;
  }
  else
  {
n:  cml();
   cout<<"黑子胜!";
   MessageBox(NULL,"请查看Record.txt","终",MB_ICONEXCLAMATION);
   fprintf(fp,"黑子胜!");
   system("pause");
   break;
  }
 }
 cml();
 } 
 fclose(fp);
 return 0; 
}

标签:case,cml,cc,system,break,Game,转载,col
From: https://www.cnblogs.com/haozexu/p/17488427.html

相关文章

  • 【转载】Game 1
    奇葩贪吃蛇#include<cstdio>#include<algorithm>#include<iostream>#include<conio.h>#include<windows.h>#include<winable.h>#include<ctime>#definerandom(a,b)(rand()%(b-a+1))+a;#definesrsrand((unsigned)......
  • 转载-linux与soc-移植U-Boot思路和实践 | 基于RK3399
    原文链接:https://mp.weixin.qq.com/s/T1BmaP2-XbJIpLNsFxKeEQ0.背景介绍我们手里这块RK3399开发板出厂时带的是2017.09版本的U-Boot。 U-Boot 2017.09 (Sep 26 2021 - 08:53:15 +0000)   Model: Forlinx OK3399 Evaluation Board Pr......
  • Python 字符编码转换(转载)
    Python字符编码转换1.在python2默认编码是ASCII,python3里默认是unicode2.unicode分为utf-32(占4个字节),utf-16(占两个字节),utf-8(占1-4个字节),soutf-16就是现在最常用的unicode版本,不过在文件里存的还是utf-8,因为utf8省空间3.在py3中encode,在转码的同时......
  • Python 文件操作(转载)
    Python文件操作操作文件时,一般需要经历如下步骤打开文件操作文件一、打开文件文件句柄=open('文件路径','模式')打开文件时,需要指定文件路径和以何等方式打开文件,打开后,即可获取该文件句柄,日后通过此文件句柄对该文件操作。打开文件的模式有r,只读模式(默认)。w,只......
  • [转载]探索 StableDiffusion:生成高质量图片学习及应用
    转自公众号大淘宝技术 本文主要介绍了StableDiffusion在图片生成上的内容,然后详细说明了StableDiffusion的主要术语和参数,并探讨了如何使用prompt和高级技巧(如图像修复、训练自定义模型和图像编辑)来生成高质量的图片。 介绍StableDiffusion ▐ ......
  • [转载]ChatGPT:智能化游戏测试的新尝试
    转自公众号网易雷火测试中心当下,ChatGPT红遍了全网,作为一个被认为会对人类社会产生威胁的聊天机器人。ChatGPT是不是真的有那么神奇?好奇心驱使下,作者对ChatGPT做了一些简单的试用,并思考了ChatGPT以及类似相关的AI工具能给我们的游戏测试工作带来哪些启发和效率提......
  • Ubuntu 12.04LTS 更换源(转载)
    2022-03实测可用前言 本文主要介绍如何为已经不再支持的Ubuntu12.04LTS更换源,网上查到的源(很多是13-14年的帖子)都无法直接使用了,例如下面这个1234debhttp://archive.ubuntu.com/ubuntuprecisemainuniverserestrictedmultiversedebhttp://archive.ubu......
  • createelement的用法(转载)
    document.createElement()是在对象中创建一个对象,要与appendChild()或insertBefore()方法联合使用。其中,appendChild()方法在节点的子节点列表末添加新的子节点。insertBefore()方法在节点的子节点列表任意位置插入新的节点。​下面,举例说明document.createElement()的用......
  • wpf特殊属性:正确理解ContentPresenter(转载)
    原文地址:https://www.cnblogs.com/shawnzxx/p/3346975.html下图显示继承关系:ContentControl:Control(在Control類並沒有Content屬性,所以在這之上再寫了一個ContentControl,使控件有Content屬性可以顯示內容)ContentPresenter:FrameworkElement(ContentPresenter一般用在C......
  • ORA-00054: 资源正忙, 但指定以 NOWAIT 方式获取资源, 或者超时失效(oracle 锁表)(转载
    1、查看数据库内产生了哪些锁selectt2.username,t2.sid,t2.serial#,t2.logon_timefromv$locked_objectt1,v$sessiont2wheret1.session_id=t2.sidorderbyt2.logon_time;如:   USERNAMESIDSERIAL#LOGON_TIMElurou851241832013/7/3011:44:45知道被锁的用户l......