栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

### C++走迷宫小游戏(自编)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

### C++走迷宫小游戏(自编)

———————————禁止转发,需要向作者申请,想玩的私信我———————————

//#include
//#include
//#include
//#include
//#include
//#include
#define E 100000
#include "tool.cpp"
using namespace std;

unsigned long long coin=E,silver=E;

//char a[10005][10005];

struct skill{
	int quantity;
	bool have;
};

struct skin{
	char appearance;
	bool have;
};

struct player{
	skin S;
	skin W;
	skin L;
	skin K;
	skin D;
	skin F;
	skin G;
	skin Q;
	skin R;
	char ys;
	int hp;
	skill wall_breaking;
	skill skip_off;
	skill wall_climbing;
	skill creating_from_noting;
}you;

//void get_map(char in[]){
//	freopen(in,"s",stdin);
//	int n,m;
//	cin>>n>>m;
//	for(int i=0;i>a[i][j];
//		a[i][m]='';
//	}
//	fclose(stdin);
//}
//
//void put_map(int n,int m,char out[]){
//	freopen(out,"w",stdout);
//	cout<=0;--i){
//    	d+=c[i];
//	}
//    return d;
//}

bool main_game(int b){
	int w;
	int q[5]={0,-1,1,0,0},p[5]={0,0,0,1,-1};
//		char map[4];
//		map[0]=b+'0';
//		map[1]='.';
//		map[2]='i';
//		map[3]='n';
//		get_map(map);
		if(b==1){
  			bool key[15];
   			memset(key,false,sizeof(key));
      		char a[100][100]={"#####################",
			  				  "# #   #   #   #   #@#",
							  "# # # # # # # # # # #",
							  "#   #   #   #   #   #",
							  "###################&#",
							  "#@#   #   #   #   # #",
							  "# # # # #   # & # # #",
							  "#   #   # #   #@#   #",
							  "#&###################",
							  "#                   #",
							  "################### #",
							  "#F                  #",
							  "#####################"};
    		int  i, x, y;
   			 x = 1; y = 1;
    		char ch;
    		for (i = 0; i <=15; i++)
        		puts(a[i]);
    		quckilyout("key:");
   	 		for(int i=1;i<=10;++i)
        		if(key[i])
        			quckilyout(int_to_string(i));
			int cnt_key=1,cnt_door=1;
    		while (true){
        ch = _getch();
        switch(ch){
        	case 'w':
        	case 'W':
        		w = 1;
        		break;
        	case 's':
			case 'S':
        		w = 2;
        		break;
        	case 'd':
			case 'D':
        		w = 3;
        		break;
        	case 'a':
			case 'A':
        		w = 4;
        		break;
			default :
				w = 0;
		}
        if (a[x + q[w]][y + p[w]] == 'F') break;
        if (a[x +q[w]][y + p[w]] == '@'){
        	key[cnt_key]=1;
            ++cnt_key;
            a[x + q[w]][y + p[w]] = ' ';
		}
        if (a[x + q[w]][y + p[w]] == '&'){
            if(key[cnt_door]){
            	++cnt_door;
            	a[x + q[w]][y + p[w]] = ' ';
			}
		}
        if (a[x + q[w]][y + p[w]] != '#'&&a[x + q[w]][y + p[w]] != '&'){
           	a[x][y] = ' ';
            x += q[w],y += p[w];
            a[x][y] = 'O';
        }
   	    		system("cls");
        		for (i = 0; i <= 15; i++)
            		puts(a[i]);
				quckilyout("Where:");
	    		cout<=500){
						coin-=500;
						if(!you.wall_breaking.have) you.wall_breaking.have=true;
						++you.wall_breaking.quantity;
					}else{
						slowout("Sorry , you don't have 500 coin .");
						Sleep(500);
					}
				}else if(cnt2=='2'){
					if(coin>=50000){
						coin-=50000;
						if(!you.wall_breaking.have) you.skip_off.have=true;
						++you.skip_off.quantity;
					}else{
						slowout("Sorry , you don't have 50000 coin .");
						Sleep(500);
					}
				}else if(cnt2=='3'){
					if(coin>=450){
						coin-=450;
						if(!you.wall_breaking.have) you.wall_climbing.have=true;
						++you.wall_climbing.quantity;
					}else{
						slowout("Sorry , you don't have 450 coin .");
						Sleep(500);
					}
				}else if(cnt2=='4'){
					if(coin>=650){
						coin-=650;
						if(!you.creating_from_noting.have) you.creating_from_noting.have=true;
						++you.creating_from_noting.quantity;
					}else{
						slowout("Sorry , you don't have 650 coin .");
						Sleep(500);
					}
				}
			}
		}else if(cnt1=='2'){
    		while(true){
    			system("cls");
  	 	 		slowout("The silver :"+int_to_string(silver));
    			back();
    			slowout("What kind of the skin do you like ?");
    			back();
    			slowout("w. W ( 1 / 4500 silver )");
   				back();
    			slowout("s. S ( 1 / 5000 silver )");
   		 		back();
   		 		slowout("l. L ( 1 / 6500 silver )");
    			back();
    			slowout("0. back");
    			back();
			    char cnt2=_getch();
			    while(cnt2!='w'&&cnt2!='s'&&cnt2!='l'&&cnt2!='0'){
			        slowout("You should to try again.");
			        cnt2=_getch();
			    }
			    if(cnt2=='0') break;
			    else if(cnt2=='w'){
			    	if(silver>=4500&&!you.W.have){
						silver-=4500;
						you.W.have=true;
						you.ys='W';
					}else if(!you.W.have){
						slowout("Sorry , you don't have 4500 silver .");
						Sleep(500);
					}else{
						slowout("Sorry , you are already have this skin -- W");
						back();
						slowout("So , now changing you skin ... ...");
						back();
						Sleep(100);
						you.ys='W';
					}
				}else if(cnt2=='s'){
					if(silver>=5000&&!you.S.have){
						silver-=5000;
						you.S.have=true;
						you.ys='S';
					}else if(!you.S.have){
						slowout("Sorry , you don't have 5000 silver .");
						Sleep(500);
					}else{
						slowout("Sorry , you are already have this skin -- S");
						back();
						slowout("So , now changing you skin ... ...");
						back();
						Sleep(100);
						you.ys='S';
					}
				}else if(cnt2=='l'){
					if(silver>=6500&&!you.L.have){
						silver-=6500;
						you.L.have=true;
						you.ys='L';
					}else if(!you.L.have){
						slowout("Sorry , you don't have 6500 silver .");
						Sleep(500);
					}else{
						slowout("Sorry , you are already have this skin -- L");
						back();
						slowout("So , now changing you skin ... ...");
						back();
						Sleep(100);
						you.ys='L';
					}
				}
			}
		}
	}
}

void begin(){
    system("cls");
    string c[1005]={"zero",
				    "first",
				    "second",
				    "third",
				    "fourth",
				    "fifth",
					"sixth",
					"seventh",
					"eighth",
					"ninth",
					"tenth",
					"eleventh",
					"twenlfth",
					"thirteenth",
					"fourteenth",
					"fifiteenth",
					"sixteenth",
					"seventeenth",
					"eighteenth",
					"nineteenth",
					"twentieth"};
	for(int i = 1;i<=20;++i){
		slowout("1. Shop");
		back();
		slowout("2. Go on");
		back();
        char cnt1=_getch();
        while(cnt1!='1'&&cnt1!='2'){
            slowout("You should to try again.");
            cnt1=_getch();
        }
		bool d=false;
		switch (cnt1){
            case '1':
                shop();
                d=true;
                break;
            case '2':
				slowout("The "+c[i]+" one:");
				back();
				Sleep(150);
				if(!main_game(i)){
                    slowout("You die!");
					d=true;
				}
				system("cls");
        }
        if(d) --i;
	}
}

void about(){
	system("cls");
	slowout("write by Laolizi");
	system("pause");
}

void rule(){
	Sleep(100);
	system("cls");
	slowout("The rules:");
	back();
	slowout("1. 'w' means up");
	back();
	slowout("2. 's' means down.");
	back();
	slowout("3. 'a' means left.");
	back();
	slowout("4. 'd' means right.");
	back();
	slowout("5. '#' means wall.");
	back();
	slowout("6. '@' means key.");
	back();
	slowout("7. '&' means door.");
	back();
	slowout("8. '$' means portal.");
	back();
	slowout("9. 'F' means end.");
	back();
	slowout("10. '^' means spikes");
	back();
	system("pause");
	back();
}

int main(){
	slowout("Welcome to the game.");
	system("color 30");
    you.hp=15;
    you.ys='O';
    you.skip_off.have=false;
    you.skip_off.quantity=0;
    you.wall_breaking.have=false;
	you.wall_breaking.quantity=0;
	you.wall_climbing.have=false;
	you.wall_climbing.quantity=0;
    while(1){
    	system("cls");
        slowout("1.game start ");
        back();
        slowout("2.about the game ");
        back();
        slowout("3.the rule");
        back();
        char cnt1=_getch();
        while(cnt1!='1'&&cnt1!='2'&&cnt1!='3'){
            slowout("You should to try again.");
            cnt1=_getch();
        }
        bool c=false;
        switch (cnt1){
            case '1':
                slowout("———————begin———————");
                back();
                begin();
                break;
            case '2':
                about();
				c=true;
				break;
			case '3':
				rule();
				c=true;
				break;
        }
        if(c) continue;
        system("cls");
        slowout("You win!");
        back();
        slowout("try again?(Y/N)");
        back();
        cnt1=_getch();
        if(cnt1=='N'||cnt1=='n')
            break;
		system("cls");
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/302381.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号