求助游戏
  • 板块灌水区
  • 楼主he1234QWQ
  • 当前回复6
  • 已保存回复6
  • 发布时间2022/3/5 22:55
  • 上次更新2023/10/28 07:11:24
查看原帖
求助游戏
228451
he1234QWQ楼主2022/3/5 22:55

这个游戏代码出了点问题(后面的输出),求各位大佬帮忙来找错

#include<bits/stdc++.h>
#include<time.h>
#include<windows.h>
using namespace std;
string g[1100];
int n,x=1,y=1,xx,fl;
char ch;
int main()
{
	printf("欢迎来到迷宫游戏"); 
	Sleep(3000);
	system("cls");
	printf("作者:xxx");
	Sleep(3000);
	system("cls");
	printf("请输入迷宫的边长系数(3~30的数字),每个数字之间要用空格隔开,输入完后请按下回车\n");
	cin>>n;
	system("cls");
	freopen("1.in","w",stdout);
	cout<<n<<endl;
	freopen("CON", "w", stdout);
	WinExec("C://Users//Administrator//Desktop//游戏//地图.exe",SW_SHOWMAXIMIZED);
	ShellExecute(NULL,"open","C://Users//Administrator//Desktop//游戏//地图.exe",NULL,NULL,SW_SHOWNORMAL);
	freopen("1.out","r",stdin);
     for(int i=0;i<=2*n+1;i++)
     getline(cin,g[i]);
     g[1][1]='O';
	 g[2*n-1][3*n-1]='@';
     for(int i=0;i<=2*n+1;i++)
     {
     cout<<g[i];
	 cout<<endl;
	 }
	 while(x!=2*n-1||y!=3*n-1)
	 {
	 	cin>>ch;
	 	if(ch=='w'||ch=='W')
	 	{
	 		if(g[x-1][y]!='#')
	 		{
	 			g[x][y]=' ';
	 			x--;
	 			g[x][y]='O';
	 		}
	 		xx++;
	 	}
	 	if(ch=='s'||ch=='S')
	 	{
	 		if(g[x+1][y]!='#')
	 		{
	 			g[x][y]=' ';
	 			x++;
	 			g[x][y]='O';
	 		}
	 		xx++;
	 	}
	 	if(ch=='a'||ch=='A')
	 	{
	 		if(g[x][y-1]!='#')
	 		{
	 			g[x][y]=' ';
	 			y--;
	 			g[x][y]='O';
	 		}
	 		xx++;
	 	}
	 	if(ch=='d'||ch=='D')
	 	{
	 		if(g[x][y+1]!='#')
	 		{
	 			g[x][y]=' ';
	 			y++;
	 			g[x][y]='O';
	 		}
	 		xx++;
	 	}
	 	system("cls");
	  for(int i=0;i<=2*n+1;i++)
      {
      cout<<g[i];
	  cout<<endl;
	  } 
      if(xx>=200)
      {
     	fl=1;
     	break;
      }
	 }
system("cls");
	 if(!fl) 
	 cout<<"你赢了"; 
	 else 
	 cout<<"你已经超过了两百步,你输了"; 
	return 0;
}
2022/3/5 22:55
加载中...