小游戏:躲避落石1.11.12
2025-08-19 15:10:13
发布于:浙江
#include<bits/stdc++.h>
#include<conio.h>
using namespace std;
int a[55][55];
int x=5,y=5;
int n = 20;
mt19937 rng(time(NULL));
bool pd(int x,int y){
	if(x>1&&x<n&&y>1&&y<n){
		return true;
	}
	return false;
}
void bz(int x,int y){
	for(int i=x-3;i<=x+3;i++){
		for(int j = y-5;j<=y+5;j++){
			if(i<=1||j<=1||i>=n||j>=n)continue;
			a[i][j] = 4;
		}
	}
}
int main(){
	int key;
	int hp = 10;
	int hh = 0;
	while(1){
		hh++;
		key = _getch();
		if(key==75){
			if(pd(x,y-1)){
				y-=1;
			}
		}
		if(key==77){
			if(pd(x,y+1)){
				y+=1;
			}
		}
		if(key==72){
			if(pd(x-1,y)){
				x-=1;
			}
		}
		if(key==80){
			if(pd(x+1,y)){
				x+=1;
			}
		}
		if(hh>100){
			if(hh%5==0){
				a[1][rng()%n+2] = 2;
			}
		}
		if(hh>200){
			if(hh%30==0){
				a[1][rng()%n+2] =3;
			}
		}
		if(hh>3){
			if(hh%30==0){
				a[1][rng()%n+2]  = 5; 
			}
		}
		a[1][rng()%n+2] = 1;
		for(int i=n;i>=1;i--){
			for(int j = 1;j<=n;j++){
				a[i][j] = a[i-1][j];
			}
		}
		for(int i = 1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(a[i][j]==3&&i==x){
					bz(i,j);
				}
				if(i==x&&j==y){
					if(a[i][j]==1||a[i][j]==4||a[i][j]==5){
						hp--;
						cout<<"*";
					}else if(a[i][j]==2){
						hp+=5;
						cout<<"@";
					}else{
						cout<<"@";
					}
				}
				else if(i==1||i==n||j==1||j==n){
					cout<<"#"; 
				}
				else{
					if(a[i][j]==1){
						cout<<"O";
					}else if(a[i][j]==2){
						cout<<"\033[042mO\033[0m";
					}else if(a[i][j]==3){
						cout<<"\033[041mO\033[0m";
					}else if(a[i][j]==4){
						cout<<"\033[107mO\033[0m";
					}else if(a[i][j]==5){
						cout<<"\033[046mO\033[0m";
						int nx,ny;
						if(i<x) nx = i+2;
						if(j<y) ny = j+2;
						if(i>x) nx = i-2;
						if(j>y) ny = j-2;
						a[i][j] = 0;
						a[nx][ny] = 5;
					}
					else{
						cout<<" ";
					}
				}
				
			}
			cout<<endl;
		}
		cout<<"HP:"<<hp;
		system("cls");
		if(hp<=0){
			while(1){
				cout<<"你趋势了"; 
				system("cls");
			}
			
		}
	}
	return 0;
}
按上下左右键游玩
点个赞吧
这里空空如也












有帮助,赞一个