c++小游戏,简单易懂,萌新也能写出来

移动小游戏第一版

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int main(){
	cout<<"移动小游戏1.1.5\n\n\n\n\n游戏规则:\n '@' is you.Press 'w/a/s/d' to move '@' to '#'\nPress 'q' to stop.\n";
	cout<<"打出start开始\n";
	string aa;
	cin>>aa;
	if(aa!="start"){
		cout<<"游戏关闭……";
		return 0;
	}
	system("cls");
	char a,r[100][100]={"**********","*@       *","*        *","*       #*","**********"};
	for(int i=0;i<=10;i++)
		puts(r[i]);
	int x=1,y=1;
	while(a!='q'){
		a=getch();
		if(a=='a'){
			if(r[x][y-1]!='*'){
				r[x][y]=' ';
				y--;
				if(r[x][y]=='#'){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='s'){
			if(r[x+1][y]!='*'){
				r[x][y]=' ';
				x++;
				if(r[x][y]=='#'){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='d'){
			if(r[x][y+1]!='*'){
				r[x][y]=' ';
				y++;
				if(r[x][y]=='#'){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='w'){
			if(r[x-1][y]!='*'){
				r[x][y]=' ';
				x--;
				if(r[x][y]=='#'){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='q')
			break;
	}
	return 0;
}

第二版

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int main(){
	cout<<"移动小游戏1.2.1\n\n\n\n\n游戏规则:\n '@'=你.\n'|'=障碍\n'#'=终点\nPress 'w/a/s/d' to move '@' to '#'\nPress 'q' to stop.\n";
	cout<<"打出start开始\n";
	string aa;
	cin>>aa;
	if(aa!="start"){
		cout<<"游戏关闭……";
		return 0;
	}
	system("cls");
	char a,r[100][100]={"*************************","*@|   |      |||||      *","* | ||    |         |   *","* |        ||   | | |   *","*   ||         |    |   *","*|||   ||   | |||  ||  #*","*************************"};
	for(int i=0;i<=10;i++)
		puts(r[i]);
	int x=1,y=1;
	while(a!='q'){
		a=getch();
		if(a=='a'){
			if(r[x][y-1]!='*'&&r[x][y-1]!='|'){
				r[x][y]=' ';
				y--;
				if(r[x][y]=='#'){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='s'){
			if(r[x+1][y]!='*'&&r[x+1][y]!='|'){
				r[x][y]=' ';
				x++;
				if(r[x][y]=='#'){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='d'){
			if(r[x][y+1]!='*'&&r[x][y+1]!='|'){
				r[x][y]=' ';
				y++;
				if(r[x][y]=='#'){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='w'){
			if(r[x-1][y]!='*'&&r[x-1][y]!='|'){
				r[x][y]=' ';
				x--;
				if(r[x][y]=='#'){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='q')
			break;
	}
	return 0;
}

第三版

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int main(){
	cout<<"移动小游戏1.3.2\n\n\n\n\n游戏规则:\n '@'=你.\n'|'=障碍\n(number)=传送门(注意:传送门不能传两次且单数为传送出地点,双数为传送后地点)\n'#'=终点\nPress 'w/a/s/d' to move '@' to '#'\nPress 'q' to stop.\n";
	cout<<"打出start开始\n";
	string aa;
	cin>>aa;
	if(aa!="start"){
		cout<<"游戏关闭……";
		return 0;
	}
	system("cls");
	char a,r[100][100]={"**************************************************",
						"*@|   |      |||||  |2|  |                       *",
						"* | ||    |         |      |||||||||||| |||||    *",
						"* |        ||   | | ||||||  |          |        |*",
						"*   ||         |    |  |                   ||||| *",
						"*|||1  ||   | |||  ||     ||||||||||||||| 3|4   #*",
						"**************************************************"};
	for(int i=0;i<=10;i++)
		puts(r[i]);
	int x=1,y=1;
	while(a!='q'){
		a=getch();
		if(a=='a'){
			if(r[x][y-1]!='*'&&r[x][y-1]!='|'){
				r[x][y]=' ';
				y--;
				if(r[x][y]=='#'){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				if(r[x][y]=='1'){
					r[x][y]=' ';
					x=1,y=21;
					r[x][y]='@';
				}
				if(r[x][y]=='3'){
					r[x][y]=' ';
					x=5,y=47;
					r[x][y]='@';
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='s'){
			if(r[x+1][y]!='*'&&r[x+1][y]!='|'){
				r[x][y]=' ';
				x++;
				if(r[x][y]=='#'){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				if(r[x][y]=='1'){
					r[x][y]=' ';
					x=1,y=21;
					r[x][y]='@';
				}
				if(r[x][y]=='3'){
					r[x][y]=' ';
					x=5,y=44;
					r[x][y]='@';
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='d'){
			if(r[x][y+1]!='*'&&r[x][y+1]!='|'){
				r[x][y]=' ';
				y++;
				if(r[x][y]=='#'){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				if(r[x][y]=='1'){
					r[x][y]=' ';
					x=1,y=21;
					r[x][y]='@';
				}
				if(r[x][y]=='3'){
					r[x][y]=' ';
					x=5,y=44;
					r[x][y]='@';
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='w'){
			if(r[x-1][y]!='*'&&r[x-1][y]!='|'){
				r[x][y]=' ';
				x--;
				if(r[x][y]=='#'){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				if(r[x][y]=='1'){
					r[x][y]=' ';
					x=1,y=21;
					r[x][y]='@';
				}
				if(r[x][y]=='3'){
					r[x][y]=' ';
					x=5,y=44;
					r[x][y]='@';
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='q')
			break;
	}
	return 0;
}

第四版

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int main(){
	cout<<"移动小游戏1.4.2\n\n\n\n\n游戏规则:\n '@'=你.\n'|'=障碍(有一个障碍是假的)\n(number)=传送门(注意:传送门不能传两次且单数为传送出地点,双数为传送后地点)\n'#'=终点(有一个终点是假的)\nPress 'w/a/s/d' to move '@' to '#'\nPress 'q' to stop.\n";
	cout<<"打出start开始\n";
	string aa;
	cin>>aa;
	if(aa!="start"){
		cout<<"游戏关闭……";
		return 0;
	}
	system("cls");
	char a,r[100][100]={"**************************************************",
						"*@                               |    ||||||||| 1*",
						"*||||||||||||||||||||||||||||||  |             | *",
						"*   2|||||||3                    |  |            *",
						"*      |                         |    |||||||||||*",
						"*#     |                         |    |       4 #*",
						"**************************************************"};
	for(int i=0;i<=10;i++)
		puts(r[i]);
	int x=1,y=1;
	while(a!='q'){
		a=getch();
		if(a=='a'){
			if(x==5&&y==38){
				cout<<"你发现了暗门!\n你走了进去……";
				Sleep(2500);
				r[x][y]=' ';
				x--;
				r[x][y]='@';
			}
			if(r[x][y-1]!='*'&&r[x][y-1]!='|'){
				r[x][y]=' ';
				y--;
				if(x==5&&y==1){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				if(x==5&&y==48){
					cout<<"你走进了假的终点!You Died!\n";
					return 0; 
				}
				if(r[x][y]=='1'){
					r[x][y]=' ';
					x=3,y=4;
					r[x][y]='@';
				}
				if(r[x][y]=='3'){
					r[x][y]=' ';
					x=5,y=46;
					r[x][y]='@';
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='s'){
			if(x==5&&y==39){
				cout<<"你发现了暗门!\n你走了进去……";
				r[x][y]=' ';
				x--;
				r[x][y]='@';
			}
			if(r[x+1][y]!='*'&&r[x+1][y]!='|'){
				r[x][y]=' ';
				x++;
				if(x==5&&y==1){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				if(x==5&&y==48){
					cout<<"你走进了假的终点!You Died!\n";
					return 0; 
				}
				if(r[x][y]=='1'){
					r[x][y]=' ';
					x=3,y=4;
					r[x][y]='@';
				}
				if(r[x][y]=='3'){
					r[x][y]=' ';
					x=5,y=46;
					r[x][y]='@';
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='d'){
			if(x==5&&y==39){
				cout<<"你发现了暗门!\n你走了进去……";
				r[x][y]=' ';
				x--;
				r[x][y]='@';
			}
			if(r[x][y+1]!='*'&&r[x][y+1]!='|'){
				r[x][y]=' ';
				y++;
				if(x==5&&y==1){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				if(x==5&&y==48){
					cout<<"你走进了假的终点!You Died!\n";
					return 0; 
				}
				if(r[x][y]=='1'){
					r[x][y]=' ';
					x=3,y=4;
					r[x][y]='@';
				}
				if(r[x][y]=='3'){
					r[x][y]=' ';
					x=5,y=46;
					r[x][y]='@';
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='w'){
			if(x==5&&y==39){
				cout<<"你发现了暗门!\n你走了进去……";
				r[x][y]=' ';
				x--;
				r[x][y]='@';
			}
			if(r[x-1][y]!='*'&&r[x-1][y]!='|'){
				r[x][y]=' ';
				x--;
				if(x==5&&y==1){
					cout<<"闯关成功!\n下一关敬请期待";
					return 0;
				}
				if(x==5&&y==48){
					cout<<"你走进了假的终点!You Died!\n";
					return 0; 
				}
				if(r[x][y]=='1'){
					r[x][y]=' ';
					x=3,y=4;
					r[x][y]='@';
				}
				if(r[x][y]=='3'){
					r[x][y]=' ';
					x=5,y=46;
					r[x][y]='@';
				}
				r[x][y]='@';
			}
			system("cls");
			for(int i=0;i<=10;i++)
				puts(r[i]);
		}
		if(a=='q')
			break;
	}
	return 0;
}

第五版代码找不到了,游戏地址在这里

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值