控制台主机不能运行,切换终端实现RPG运行

 鄙人转载,主要是移植过程中使用小熊猫C++2.25.1 过程中,字符集不同,导致某些空格 从bilibili专栏粘贴导致出现符号不匹配,但是编辑器不能替换

用原来的devc++ 5.11 发现问题,读出额外的英文? 使用文件替换,一键替换了本文件内全部的?。

 

 

 

然后运行

发现不刷新

换用终端取代控制台主机

重新运行,成功

 

去除乱码符号版本

如有侵权请联系在下 

//作者:青节攻 https://www.bilibili.com/read/cv29583226/ spm_id_from=333.999.0.0&jump_opus=1 出处:bilibili



#include <stdio.h>

#include <windows.h>

#include <conio.h>

#include <time.h>



char ch;

int a[80][28]={0};

int kill=0,O=0;//o是任务o

int X[20]={'\0'},Y[20]={'\0'};//记录敌人坐标 有bug,不能走到左上角0,0处

int Accept=0,Accept2=0,Accept3=0;//判断能否接取任务/对话

int Judge=0;

int coin=0;//金币 



//属性变量

float h=100,sd=1,sp=1,hit;

float *HP=&h,*strong=&sd,*speed=&sp;

float time_HP=100;







//隐藏光标

void HideCursor()

{
	
	 CONSOLE_CURSOR_INFO cursor;   
	
	 cursor.bVisible = FALSE;   
	
	 cursor.dwSize = sizeof(cursor);   
	
	 HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);   
	
	 SetConsoleCursorInfo(handle, &cursor);
	
} 



//玩家的坐标 

static int xx0=2;

static int yy0=13;



//颜色 

int color(int c)

{
	
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);
	
	return 0;
	
}



//坐标

void gotoxy(int x,int y)

{
	
	COORD pos;
	
	pos.X=x;
	
	pos.Y=y;
	
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
	
 } 

 void Coin()//金币系统 

{
	
	gotoxy(43,28);
	
	color(15);
	
	printf("金币:%d         ",coin);
	
}

 //随机生成敌人

void rand_enemy()

{
	
	
	
	int x,y,i;
	
	for(i=0;i<7;i++)
		
	{
		
		x=rand()%75+2;
		
		y=rand()%23+2;
		
		X[i]=x;
		
		Y[i]=y--;
		
		color(12);
		
		gotoxy(x,y);
		
		printf("※"); 
		
		color(13);
		
		gotoxy(x,++y);
		
		printf("■");
		
	}
	
 } 

//地图设计

void Map()

{
	
	int i,j;
	
	for(i=0;i<80;i+=2)//边框 
		
	{
		
		gotoxy(i,0);
		
		color(5);
		
		printf("══");
		
		gotoxy(i,26);
		
		printf("══");
		
	}
	
	for(i=1;i<26;i++)
		
	{
		
		gotoxy(0,i);
		
		color(5);
		
		printf("‖");
		
		a[0][i]=2;
		
		gotoxy(78,i);
		
		printf("‖");
		
		a[78][i]=2;
		
	}
	
 } 

 

 //添加玩家

 void player()

 {
	
	 	gotoxy(xx0,yy0);
	
	 	color(14);
	
	 	printf("●");
	
 } 

  

 void mission(int o)//任务 

 {
	
	 	
	
	 	switch(o)
	
	 	{
		
	 		case 0:
		
		color(6);
		
		gotoxy(85,27);
		
		printf("**********当前没有任务**********");kill=0;//防止未接任务就能显示任务完成 
		
		gotoxy(85,28);
		
		printf("           ");
		
		break;	
		
	case 1:
		
		color(6);
		
		gotoxy(85,27);
		
		printf("当前任务:处理5个匪徒 %d/5        ",kill);
		
		break;
		
	}
	
	if(kill==5)
		
	{O=0;
		
		color(6);
		
		gotoxy(85,27);
		
		printf("**********任务完成!**********");
		
		gotoxy(85,28);
		
		printf("金币+100");
		
		Sleep(1000);
		
		coin=coin+100;
		
		kill=0;Accept=0;
		
	}
	
 }

 //NPC

 void NPC()

 {
	
	 	gotoxy(39,2);
	
	 	color(2);
	
	 	printf("●");//村长 
	
	  	gotoxy(40,13);
	
	 	color(2);
	
	 	printf("●");//牢大 
	
	 	gotoxy(60,6);
	
	 	color(2);
	
	 	printf("●");//小声发 
	
	 	gotoxy(2,16);
	
	color(3);
	
	printf("⑦");//神像 
	
	gotoxy(26,23);
	
	color(2);
	
	printf("●");//董 
	
	gotoxy(14,5);
	
	color(2);
	
	printf("●");//不知名拳师 
	
 }

  

  //触发按键

  void attend()

  {
	
	  	gotoxy(39,3);
	
	 	color(13);
	
	 	printf("■");
	
	  	gotoxy(40,14);
	
	 	color(13);
	
	 	printf("■");
	
	 	gotoxy(60,7);
	
	 	color(13);
	
	 	printf("■");  
	
	gotoxy(77,13);
	
	color(4);
	
	printf("*");
	
	gotoxy(2,17);
	
	color(9);
	
	printf("Ⅲ");
	
	gotoxy(26,24);
	
	color(13);
	
	printf("■");
	
	gotoxy(14,6);
	
	color(13);
	
	printf("■");
	
} 





//文本

int text(int n)

{
	
	switch(n)
	
	{
		
	case 0:
		
		gotoxy(82,10);
		
		printf("                    ");
		
		gotoxy(82,12);
		
		printf("                    ");
		
		gotoxy(82,13);
		
		printf("                    ");
		
		gotoxy(82,18);
		
		printf("                    ");
		
		gotoxy(82,20);
		
		printf("                    ");
		
		gotoxy(82,25);
		
		printf("                    ");
		
		gotoxy(82,26);
		
		printf("                    ");
		
		gotoxy(82,14);
		
		printf("                    ");
		
		gotoxy(82,16);
		
		printf("                    ");
		
		gotoxy(82,15);
		
		printf("                    ");
		
		
		
		break;
		
	case 1:
		
		if(Accept==0)
			
		{
			
			gotoxy(82,25);
			
			printf("按1对话  空格接受任务");
			
			gotoxy(82,26);
			
			printf("不接受任务可以直接离开");
			
			gotoxy(82,10);
			
			printf("村长:你是天师派来的人吗?");
			
		}
		
		if(Accept==0&&ch=='1'||Accept==1)
			
		{
			
			Accept=1;
			
			gotoxy(82,25);
			
			printf("按1对话  空格接受任务");
			
			gotoxy(82,26);
			
			printf("不接受任务可以直接离开");
			
			gotoxy(82,10);
			
			printf("村长:你是天师派来的人吗?");
			
			Sleep(250);
			
			gotoxy(82,12);
			
			printf("村长:最近村子里不太平,有许多山匪作乱");
			
			Sleep(400);
			
			gotoxy(82,14);
			
			printf("村长:你能帮我去清理山里灵活的匪徒吗?");
			
			Sleep(500);
			
			gotoxy(82,16);
			
			color(6);
			
			printf("任务:前往黑沙街道处理5个匪徒"); 
			
		}
		
		if(ch==32&&Accept==1)//空格32 
			
		{
			
			gotoxy(85,18);
			
			color(6);
			
			printf("**********已接受任务**********"); 
			
			O=1;Accept++;
			
		}
		
		if(Accept==2)
			
		{
			
			gotoxy(82,10);
			
			color(7);
			
			printf("村长:干巴爹勇者桑!          ");
			
			Sleep(250);
			
			gotoxy(82,12);
			
			printf("我:村长收收味            ");
			
			gotoxy(82,14);
			
			printf("                   ");
			
			gotoxy(82,16);
			
			printf("                   "); 
			
		}
		
		if(ch==32&&O!=0)
			
		{
			
			gotoxy(82,18);
			
			printf("**********任务栏被占用***********"); 
			
		}
		
		break;
		
		
		
	case 2:
		
		gotoxy(82,25);
		
		printf("按1对话");
		
		gotoxy(82,10);
		
		printf("???");
		
		if(ch=='1')
			
		{
			
			gotoxy(82,10);
			
			printf("牢大:孩子,你从哪儿来?");
			
			Sleep(500);
			
			gotoxy(82,12);
			
			printf("牢大:就当是劝你吧,");
			
			color(13);
			
			printf("黑沙街道");
			
			color(7);
			
			printf("有很多山匪");
			
			Sleep(500);
			
			gotoxy(82,14);
			
			printf("牢大:不要到处乱跑");
			
		}
		
		break;
		
		
		
	case 3:
		
		gotoxy(82,10);
		
		printf("小声发:我到底是不是人啊!");
		
		Sleep(500);
		
		gotoxy(82,12);
		
		printf("我:(看来是已经疯了)");
		
		break; 
		
		
		
	case 4:
		
		gotoxy(82,10);
		
		printf("只要不失去你的崇高");
		
		gotoxy(82,12);
		
		printf("整个世界都会为你敞开");
		
		gotoxy(82,25);
		
		printf("按1治疗");			
		
		if(ch=='1')
			
		{
			
			time_HP=*HP;
			
			gotoxy(82,14);
			
			color(9);
			
			printf("生命值已恢复");
			
		}
		
		break;
		
		
		
	case 5:
		
		gotoxy(82,25);
		
		printf("按1对话 按空格升级");
		
		gotoxy(82,10);
		
		printf("董勇怪戈:新的一年也要努力锻炼啊!?");
		
		if(ch=='1')
			
		{
			
			gotoxy(82,12);
			
			printf("董勇怪戈:加油!奥里给!(40金币)");
			
			Accept2=1;
			
		}
		
		if(ch==32&&Accept2==1&&coin>=40)
			
		{
			
			gotoxy(82,14);
			
			printf("我:奥里给!");
			
			gotoxy(82,16);
			
			color(9);
			
			printf("*生命值上限提升*");
			
			*HP=*HP+15;
			
			time_HP=time_HP+15;
			
			coin=coin-40;
			
			Accept2=0;
			
		}
		
		else if(ch==32&&Accept2==1&&coin<40) 
			
		{
			
			gotoxy(82,14);
			
			printf("董勇怪戈:没关系,要乐观度过每一天!");
			
			Accept=0;
			
		}
		
		break;
		
		
		
	case 6:
		
		gotoxy(82,25);
		
		printf("按1对话 按空格升级");
		
		gotoxy(82,10);
		
		printf("不知名拳师:欧拉欧拉欧拉欧拉!");
		
		if(ch=='1')
			
		{
			
			Accept3=1;
			
			gotoxy(82,12);
			
			printf("不知名拳师:你要跟我学打拳吗?(20金币)");
			
		}
		
		if(ch==32&&Accept3==1&&coin>=20)
			
		{
			
			gotoxy(82,14);
			
			printf("我:你凭什么假定我不会打拳?");
			
			gotoxy(82,16);
			
			printf("*你当着拳师的面来了一套闪电五连鞭*"); 
			
			gotoxy(82,18);
			
			color(9);
			
			printf("*力量点数提升*");
			
			*strong=*strong+2;
			
			Accept3=0;
			
			coin=coin-20;
			
		}
		
		else if(ch==32&&Accept3==1&&coin<20)
			
		{
			
			gotoxy(82,14);
			
			printf("不知名拳师:你还是去别处学肘击吧!");
			
			Accept3=0;
			
		}
		
		break;
		
	}
	
 	} 

 	

//触发 

void take()

{
	
	int n;
	
	if(xx0==39&&yy0==3)
		
		n=1;
	
	else if(xx0==40&&yy0==14)
		
		n=2;
	
	else if(xx0==60&&yy0==7)
		
		n=3;
	
	else if(xx0==2&&yy0==17)
		
		n=4;
	
	else if(xx0==26&&yy0==24)
		
		n=5;
	
	else if(xx0==14&&yy0==6)
		
		n=6;
	
	else n=0;
	
	text(n);
	
}



void clear()//清屏 

{
	
	gotoxy(85,10);
	
	printf("                    ");
	
	gotoxy(85,12);
	
	printf("                    ");
	
	gotoxy(85,13);
	
	printf("                    ");
	
	gotoxy(85,15);
	
	printf("                    ");
	
	gotoxy(85,20);
	
	printf("                    ");
	
	gotoxy(85,25);
	
	printf("                    ");
	
	gotoxy(85,26);
	
	printf("                    ");
	
	gotoxy(85,14);
	
	printf("                    ");
	
	gotoxy(85,16);
	
	printf("                    ");
	
}

void take2()//战斗触发 

{
	
	int i,n;
	
	int hit_enemy,hp;
	
	for(i=0;i<20;i++)
		
		if(xx0==X[i]&&yy0==Y[i])
			
		{
			
			int plus;//记录金币加了多少 
			
			hit_enemy=rand()%15+10;
			
			if(hit-hit_enemy>0&&hit-hit_enemy<10)
				
			{
				
				gotoxy(85,10);
				
				printf("你们苦战许久");
				
				Sleep(500);
				
				gotoxy(85,12);
				
				printf("最终由于对方体力不支被你抓住破绽");
				
				Sleep(500);
				
				gotoxy(85,14);
				
				printf("被你一剑毙命");	
				
				plus=rand()%10+1;			
				
				gotoxy(85,16);
				
				color(6);
				
				printf("金币+%d",plus);
				
				coin=coin+plus;
				
				gotoxy(xx0,yy0-1);
				
				printf("  ");
				
				Sleep(1000);
				
				sd=*strong+rand()%5;
				
				sp=*speed+rand()%5;
				
				time_HP=time_HP-(rand()%10+5);
				
				kill++;X[i]=0;Y[i]=0;
				
			}
			
			if(hit-hit_enemy>10&&hit-hit_enemy<20)
				
			{
				
				gotoxy(85,10);
				
				printf("你们交战不久,对面就败下阵来");
				
				Sleep(500);
				
				gotoxy(85,12);
				
				printf("你抓住破绽");
				
				Sleep(500);
				
				gotoxy(85,14);
				
				printf("一剑毙命");			
				
				plus=rand()%10+1;			
				
				gotoxy(85,16);
				
				color(6);
				
				printf("金币+%d",plus);
				
				coin=coin+plus;
				
				gotoxy(xx0,yy0-1);
				
				printf("  ");
				
				Sleep(1000);
				
				sd=*strong+rand()%3;
				
				sp=*speed+rand()%3;
				
				time_HP=time_HP-(rand()%5+5);
				
				kill++;X[i]=0;Y[i]=0;
				
			}
			
			if(hit-hit_enemy>20)
				
			{
				
				gotoxy(85,10);
				
				printf("你一剑封喉");
				
				plus=rand()%11+10;			
				
				gotoxy(85,16);
				
				color(6);
				
				printf("金币+%d",plus);
				
				coin=coin+plus;
				
				gotoxy(xx0,yy0-1);
				
				printf("  ");
				
				Sleep(750);
				
				sd=*strong+rand()%1;
				
				sp=*speed+rand()%1;
				
				kill++;X[i]=0;Y[i]=0;
				
			}
			
			if(hit-hit_enemy<0)
				
			{
				
				gotoxy(85,10);
				
				printf("你不敌对方");
				
				Sleep(500);
				
				gotoxy(85,12);
				
				printf("艰难逃脱了对方的追击");
				
				gotoxy(xx0,yy0-1);
				
				printf("  ");
				
				time_HP=time_HP-(rand()%30+30);
				
				Sleep(500);X[i]=0;Y[i]=0;
				
			}
			
			clear();
			
			Sleep(250);
			
		}
	
}





  //右边的提示框

  void item()

  {
	
	  		gotoxy(80,3);
	
	  		color(14);
	
	  		printf("提示信息:↑↓←→控制移动 B回城 I状态栏");
	
	  		gotoxy(80,4);
	
	  		color(2);
	
	  		printf("●是NPC\n"); 
	
	  		gotoxy(80,5);
	
	  		color(12);
	
	  		printf("※是敌人\n"); 
	
	  		gotoxy(80,6);
	
	  		color(13);
	
	  		printf("■触发对话/战斗 "); 
	
	
	
} 



//信息框

void info()

{
	
	int i;
	
	color(7);
	
	for(i=80;i<120;i++)
		
	{
		
		gotoxy(i,8);
		
		printf("_");
		
		gotoxy(i,24);
		
		printf("_");
		
	}
	
	
	
} 

//移动--村子 

void move_1()

{
	
	ch=getch();
	
	if(ch==72)//上
		
	{
		
		gotoxy(xx0,yy0);
		
		color(1);
		
		printf(" ");
		
		NPC();
		
		attend();
		
		gotoxy(xx0,--yy0);
		
		color(14);
		
		printf("●");
		
	}
	
	if(ch==80)//下
		
	{
		
		gotoxy(xx0,yy0);
		
		color(1);
		
		printf(" ");
		
		NPC();
		
		attend();
		
		gotoxy(xx0,++yy0);
		
		color(14);
		
		printf("●");
		
	}
	
	if(ch==75)//左 
		
	{
		
		gotoxy(xx0,yy0);
		
		color(1);
		
		printf(" ");
		
		NPC();
		
		attend();
		
		gotoxy(--xx0,yy0);
		
		color(14);
		
		printf("●");
		
	}
	
	if(ch==77)//右
		
	{
		
		gotoxy(xx0,yy0);
		
		color(1);
		
		printf(" ");
		
		NPC();
		
		attend();
		
		gotoxy(++xx0,yy0);
		
		color(14);
		
		printf("●");
		
	}	
	
 }	 

 

 //移动--村子外 

 void move_2()

 {
	
	 	ch=getch();
	
	if(ch==72)//上
		
	{
		
		gotoxy(xx0,yy0);
		
		color(1);
		
		printf(" ");
		
		gotoxy(xx0,--yy0);
		
		color(14);
		
		printf("●");
		
	}
	
	if(ch==80)//下
		
	{
		
		gotoxy(xx0,yy0);
		
		color(1);
		
		printf(" ");
		
		gotoxy(xx0,++yy0);
		
		color(14);
		
		printf("●");
		
	}
	
	if(ch==75)//左 
		
	{
		
		gotoxy(xx0,yy0);
		
		color(1);
		
		printf(" ");
		
		gotoxy(--xx0,yy0);
		
		color(14);
		
		printf("●");
		
	}
	
	if(ch==77)//右
		
	{
		
		gotoxy(xx0,yy0);
		
		color(1);
		
		printf(" ");
		
		gotoxy(++xx0,yy0);
		
		color(14);
		
		printf("●");
		
	}	
	
 } 

 //回城

  void back()

 {
	
	
	
	 			gotoxy(xx0,yy0);
	
	printf(" ");
	
	gotoxy(xx0=2,yy0=13);
	
	Sleep(250);
	
	color(14);
	
	printf("●");
	
	ch='\0';//使缓冲区的b消失,避免反复触发回城 
	
	gotoxy(2,11);
	
	color(9);
	
	printf("\\/");
	
	gotoxy(2,14);
	
	color(9);
	
	printf("/\\");
	
	Sleep(250);
	
	gotoxy(2,11);
	
	printf("  ");
	
	gotoxy(2,14);
	
	printf("  ");
	
	gotoxy(80,7);
	
	color(15);	
	
	printf("****************回家啦!****************");
	
}

  //属性状态 

void player_status()

{
	
	hit=h*0.2+sd*0.5+sp*0.3;
	
	gotoxy(2,27);
	
	color(15);
	
	printf("生命:%.1f/%.1f",time_HP,*HP);
	
	gotoxy(2,28);
	
	printf("战力:%.1f          ",hit);
	
	if(ch=='i')
		
	{
		
		color(15);
		
		gotoxy(82,10);
		
		printf("     生命值上限: %.1f      ",*HP);
		
		gotoxy(82,12);
		
		printf("     力量:%.1f          ",*strong);
		
		gotoxy(82,14);
		
		printf("     敏捷:%.1f          ",*speed);
		
		gotoxy(82,16);
		
		printf("     战力:%.1f          ",hit);
		
	}}



int main()

 {
	
	//地图一 
	
	FLAG:
	
	 	HideCursor();
	
	 	Map();
	
	 	player();
	
	 	NPC();
	
	 	item();
	
	 	attend();
	
	 	info();
	
	 	srand((unsigned int)time(NULL));
	
	 	while(1)
		
	 	{	
		
		 		if(xx0==76&&yy0==13)
			
		{
			
			gotoxy(82,10);
			
			color(13);
			
			printf("    *黑沙街道*");
			
			gotoxy(82,12);
			
			color(7);
			
			printf("    按回车键进入");
			
		}
		
		Coin();
		
		player_status();
		
		 		item();
		
		 		Map();
		
		 		info();
		
		 		if(ch=='b'||ch=='B')
			
			back();
		
		 		mission(O);//任务
		
		if(time_HP<=0)//判断死亡 
			
		{
			
			system("cls");
			
			gotoxy(50,13);
			
			color(12);
			
			printf("  你失血过多昏了过去");
			
			Sleep(1000);
			
			system("cls");
			
			Sleep(1000);
			
			back();
			
			time_HP=30;
			
			Judge--;
			
			goto FLAG;
			
		}
		
		if(time_HP<=30)
			
		{
			
			gotoxy(24,27);
			
			color(12);
			
			printf("*血量过低*");
			
		}
		
		else
			
		{
			
			gotoxy(24,27);
			
			printf("      ");
			
		}
		
		 		if(kbhit())
			
		 		{
			
			 			move_1();
			
			gotoxy(80,7);
			
			color(7);
			
			printf("超级无敌霸王酷炫勇者的x坐标:%2d y坐标:%2d",xx0,yy0);
			
			take();
			
			 
			
			if(ch==13&&xx0==76&&yy0==13) //地图2 
				
			{
				
				system("cls");
				
				Map();
				
				player();
				
				item();
				
				info();
				
				while(1)
					
				{	
					
					if(xx0==76&&yy0==13)
						
					{
						
						gotoxy(82,10);
						
						color(13);
						
						printf("    *村庄*");
						
						gotoxy(82,12);
						
						color(7);
						
						printf("    按回车键进入");
						
					}
					
					Coin();
					
					item();
					
					 					Map();
					
					 					info();
					
					if(time_HP<=0)//判断死亡 
						
					{
						
						system("cls");
						
						gotoxy(50,13);
						
						color(12);
						
						printf("  你失血过多昏了过去");
						
						Sleep(1000);
						
						system("cls");
						
						Sleep(1000);
						
						back();
						
						time_HP=30;
						
						Judge--;
						
						goto FLAG;
						
					}
					
					if(time_HP<=30)
						
					{
						
						gotoxy(24,27);
						
						color(12);
						
						printf("*血量过低*");
						
					}
					
					else
						
					{
						
						gotoxy(24,27);
						
						printf("      ");
						
					}
					
					mission(O);//任务 
					
					player_status();
					
					if(Judge==0)//进图刷敌人 
						
					{
						
						rand_enemy();
						
						++Judge;
						
					}
					
					if(kbhit())
						
					{
						
						
						
						clear();
						
						move_2();
						
						gotoxy(80,7);
						
						color(7);
						
						printf("超级无敌霸王酷炫勇者的x坐标:%2d y坐标:%2d",xx0,yy0);
						
						take2();//战斗触发 
						
						gotoxy(77,13);
						
						color(4);
						
						printf("*");//传送门 
						
						if(ch=='b'||ch=='B')//地图二回城 
							
						{
							
							Judge--;
							
							back();
							
							system("cls");
							
							goto FLAG;
							
						}
						
						if(ch==13&&xx0==76&&yy0==13)//传送  
							
						{	
							
							system("cls");
							
							Judge--;
							
							goto FLAG;
							
						}
						
						
						
					}
					
				}
				
			}
			
		}
		
	}
	
	 	return 0;
	
 } 
//作者:青节攻 https://www.bilibili.com/read/cv29583226/ spm_id_from=333.999.0.0&jump_opus=1 出处:bilibili

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值