小游戏2.1(加了提示)
  • 板块灌水区
  • 楼主ypb20120702
  • 当前回复11
  • 已保存回复13
  • 发布时间2024/7/9 19:34
  • 上次更新2024/7/9 20:45:10
查看原帖
小游戏2.1(加了提示)
1307796
ypb20120702楼主2024/7/9 19:34

双来了!!!

#include<bits/stdc++.h>
#include<conio.h>
#include<time.h>
using namespace std;
long long hp=30,bp=2000,a[30][30],px,py,kx,ky,op;
char p[30][30];
char cse[30][30]={
"#####################",
"1                   #",
"2                   #",
"3                   #",
"#                   #",
"#                   #",
"#####################",
};
void pause(double t)
{
	int s;
	for(int i=1;i<=t*760000000;i++) s=1;
}
void out()
{
	cout<<"打败kkksc03!"<<endl;
	cout<<"kkk血量:"<<bp<<"     你的血量:"<<hp<<endl;
	cout<<"用wasd移动     空格发射子弹"<<endl;
	for(int i=1;i<=20;i++) cout<<"__";
	cout<<"__"<<endl;
	for(int i=1;i<=20;i++){
		cout<<"|";
		for(int j=1;j<=20;j++){
			if(a[i][j]==0) cout<<" ";
			else if(a[i][j]==1)cout<<"#";
			else if(a[i][j]==2)cout<<"kkksc03";
			else if(a[i][j]==3) cout<<"=";
			else if(a[i][j]==4) cout<<"<";
			cout<<" ";
		}
		cout<<'|'<<endl;
	}
	cout<<"|";
	for(int i=1;i<=20;i++) cout<<"__";
	cout<<"|";
	cout<<endl;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	srand(time(NULL));
	cout<<"欢迎来到wsy自创小游戏——打败kkksc03!"<<endl;
	px=1;
	py=10;
	cse[px][py]='T';
	char s;
	while(true){
		for(int i=0;i<=6;i++){
			for(int j=0;j<=20;j++){
				cout<<cse[i][j];
			}
			cout<<endl;
		}
		if(px==1&&py==0){
			op=1;
			break;
		} else if(px==2&&py==0) {
			op=2;
			break;
		} else if(px==3&&py==0) {
			op=3;
			break;
		} else if(px<1||py<1||px>6||py>20) {
			cout<<"真厉害,没有开始就撞墙死了。";
			return 0;
		}
		s=getch();
		if(s=='w'){
			px--;
			cse[px][py]='T';
			cse[px+1][py]=' ';
		} else if(s=='a'){
			py--;
			cse[px][py]='T';
			cse[px][py+1]=' ';
		} else if(s=='s'){
			px++;
			cse[px][py]='T';
			cse[px-1][py]=' ';
		} else if(s=='d'){
			py++;
			cse[px][py]='T';
			cse[px][py-1]=' ';
		}
		system("cls");
	}
	system("cls");
	px=rand()%20+1;
	py=rand()%20+1;
	kx=rand()%20+1;
	ky=rand()%20+1;
	a[px][py]=1;
	p[px][py]='#';
	a[kx][ky]=2;
	out();
	system("pause");
	system("color CF");
	pause(0.15);
	system("color AC");
	pause(0.15);
	system("color D3");
	pause(0.15);
	system("color 06");
	pause(2);
	system("color F0");
	pause(0.5);
	system("cls");
	out();
	for(;;){
		char o=getch();
		if(o=='w'){
			a[px][py]=0;
			p[px][py]=' ';
			a[px-1][py]=1;
			p[px-1][py]='#';
			px--;
			system("cls");
			out();
		} else if(o=='a'){
			a[px][py]=0;
			p[px][py]=' ';
			a[px][py-1]=1;
			p[px][py-1]='#';
			py-=1;
			system("cls");
			out();
		} else if(o=='s'){
			p[px][py]=' ';
			a[px][py]=0;
			a[px+1][py]=1;
			p[px+1][py]='#';
			px+=1;
			system("cls");
			out();
		} else if(o=='d'){
			p[px][py]=' ';
			a[px][py]=0;
			a[px][py+1]=1;
			p[px][py+1]='#';
			py+=1;
			system("cls");
			out();
		} else if(o==' '){
			int gx=px,gy=py;
			a[gx][gy+1]=3;
			gy++;
			while(gy+1<=20&&(kx!=gx||ky!=gy)){
				system("cls");
				gy++;
				a[gx][gy-1]=0;
				a[gx][gy]=3;
				out();
			}
			if(gx==kx&&gy==ky){
				bp-=rand()%150;
			}
			a[gx][gy]=0;
			system("cls");
			out();
		}
		if(px>20||py>20||px<1||py<1){
			cout<<"你不幸撞到墙死了。";
			pause(1.5);
			return 0;
		}
		else if(kx>20||ky>20||kx<1||ky<1){
			system("color 60");
			system("cls");
			cout<<"kkksc03不幸撞到墙死了。所以你赢了。";
			pause(1.5);
			return 0;
		}
		else if(px==kx&&py==ky){
			hp-=rand()%10;
			bp-=rand()%15;
		}
		if(bp<=0){
			system("color 60"); 
			system("cls");
			cout<<"血量:"<<bp<<endl; 
			cout<<"你赢了!"; 
			return 0; 
		} 
		if(hp<=0){
			system("cls");
			cout<<"你失败了!";
			pause(1.5);
			return 0;
		}
		a[kx][ky]=0;
		if(op==3){
			if(px>kx){kx++;}
			else if(py>ky){ky++;}
			else if(px<kx){kx--;}
			else if(py<ky){ky--;}
		} else if(op==2) {
			kx+=(rand()%2==0)?-1:1;
			ky+=(rand()%2==0)?-1:1;
		}
		a[kx][ky]=2; 
		pause(0.1);
	}
	return 0;
}
2024/7/9 19:34
加载中...