c++v1.1

#include <conio.h> 
#include <bits/stdc++.h>
#include <windows.h>
#include <time.h>
using namespace std;
int main(){
	srand(unsigned(time(NULL)));
    int x=rand()%31,y=rand()%21,x1=rand()%31,y1=rand()%21;
	if (x==0) x++;
	if (x1==0) x1++;
	if (y==0) y++;
	if (y1==0) y1++; 
	char dt[22][32];
	memset(dt,'#',sizeof(dt));
	for (int i=1;i<21;i++){
		for (int j=1;j<31;j++){
			dt[i][j]=' ';
		}
	}
	for (int i=0;i<100;i++){
		int x2=rand()%31,y2=rand()%21;
		dt[y2][x2]='#';
	}
	for (int i=0;i<20;i++){
		int x2=rand()%31,y2=rand()%21;
		if (dt[y2][x2]!='#')dt[y2][x2]='+';
	}
	dt[y][x]='@';dt[y1][x1]='A';
	int playerhp=1000,bosshp=3000;
	char a;
	int CD=0,lx=0;
	while(playerhp>0&&bosshp>0){
		int move=rand()%9;
		int gl=rand()%10;
		Sleep(1000);
		if (_kbhit()){
			a=getch();
			if (a=='w'&&dt[y-1][x]!='#'&&dt[y-1][x]!='A'){
				dt[y][x]=' ';
				y--;
				if (dt[y][x]=='+'&&playerhp<900){
					playerhp+=100;
					lx=0;
				}
				else if (dt[y][x]=='+'&&playerhp>=900){
					playerhp=1000;
					lx=0;
				}
				dt[y][x]='@';
			}
			else if (a=='s'&&dt[y+1][x]!='#'&&dt[y+1][x]!='A'){
				dt[y][x]=' ';
				y++;
				if (dt[y][x]=='+'&&playerhp<900){
					playerhp+=100;
					lx=0;
				}
				else if (dt[y][x]=='+'&&playerhp>=900){
					playerhp=1000;
					lx=0;
				}
				dt[y][x]='@';
			}
			else if (a=='a'&&dt[y][x-1]!='#'&&dt[y][x-1]!='A'){
				dt[y][x]=' ';
				x--;
				if (dt[y][x]=='+'&&playerhp<900){
					playerhp+=100;
					lx=0;
				}
				else if (dt[y][x]=='+'&&playerhp>=900){
					playerhp=1000;
					lx=0;
				}
				dt[y][x]='@';
			}
			else if (a=='d'&&dt[y][x+1]!='#'&&dt[y][x+1]!='A'){
				dt[y][x]=' ';
				x++;
				if (dt[y][x]=='+'&&playerhp<900){
					playerhp+=100;
					lx=0;
				}
				else if (dt[y][x]=='+'&&playerhp>=900){
					playerhp=1000;
					lx=0;
				}
				dt[y][x]='@';
			}
			else if (a=='1'){
				for (int i=y-1;i>0;i--){
					if (dt[i][x]=='#') break;
					if (dt[i][x]=='A'){
						bosshp-=150;
						if (gl>=7) bosshp-=100;
						break;
					}
					dt[i][x]='|';
				}
				system("cls");
		        for (int i=0;i<22;i++){
			        for (int j=0;j<32;j++){
				        cout<<dt[i][j];
		        	}
		        	cout<<endl;
				}  
				Sleep(300);
				for (int i=y-1;i>0;i--){
				    if (dt[i][x]=='#') break;
					if (dt[i][x]=='A'){
						break;
					}
					dt[i][x]=' ';
				}
				if (gl>=7) continue;
			}
			else if (a=='2'){
				for (int i=1;i<=15;i++){
					if (dt[y-i][x+i]=='#') break;
					if (dt[y-i][x+i]=='A'){
						bosshp-=150;
						if (gl>=7) bosshp-=100;
					    break;
					}
					dt[y-i][x+i]='*';
				}
				system("cls");
				for (int i=0;i<22;i++){
					for (int j=0;j<32;j++){						        
						cout<<dt[i][j];
					}						        
					cout<<endl;
				}  
			    Sleep(300);		     
				for (int i=1;i<=15;i++){
					if (dt[y-i][x+i]=='#') break;
					if (dt[y-i][x+i]=='A'){
						break;
					}
					dt[y-i][x+i]=' ';
				}
				if (gl>=7) continue;
			}
			else if(a=='3'){
				for (int i=x+1;i<=30;i++){
					if (dt[y][i]=='#') break;
					if (dt[y][i]=='A'){
						bosshp-=150;
						if (gl>=7) bosshp-=100;
						break;
					}
					dt[y][i]='-';
				}
				system("cls");
				for (int i=0;i<22;i++){
					for (int j=0;j<32;j++){
					    cout<<dt[i][j];
				    }
					cout<<endl;
				}  
				Sleep(300);
				for (int i=x+1;i<=30;i++){
					if (dt[y][i]=='#') break;
					if (dt[y][i]=='A'){
						break;
					}
					dt[y][i]=' ';
				}	
				if (gl>=7) continue;		
			}
			else if (a=='4'){
				for (int i=1;i<=15;i++){			
					if (dt[y+i][x+i]=='#') break;			
					if (dt[y+i][x+i]=='A'){			
						bosshp-=150;
						if (gl>=7) bosshp-=100;
						break;							    			
					}
					dt[y+i][x+i]='*';
			    }
				system("cls");
				for (int i=0;i<22;i++){
					for (int j=0;j<32;j++){						        
						cout<<dt[i][j];
					}						        
					cout<<endl;
				}  
				Sleep(300);		     
				for (int i=1;i<=15;i++){
					if (dt[y+i][x+i]=='#') break;
					if (dt[y+i][x+i]=='A'){
						break;
					}
					dt[y+i][x+i]=' ';
				}
				if (gl>=7) continue;
			}
			else if (a=='5'){
				for (int i=y+1;i<31;i++){
					if (dt[i][x]=='#') break;
					if (dt[i][x]=='A'){
						bosshp-=150;
						if (gl>=7) bosshp-=100;
						break;
					}
					dt[i][x]='|';
				}
				system("cls");
		        for (int i=0;i<22;i++){
			        for (int j=0;j<32;j++){
				        cout<<dt[i][j];
		        	}
		        	cout<<endl;
				}  
				Sleep(300);
				for (int i=y+1;i<31;i++){
				    if (dt[i][x]=='#') break;
					if (dt[i][x]=='A'){
						break;
					}
					dt[i][x]=' ';
				}
				if (gl>=7) continue;
			}	
			else if (a=='6'){
				for (int i=1;i<=15;i++){			
					if (dt[y+i][x-i]=='#') break;			
					if (dt[y+i][x-i]=='A'){			
						bosshp-=150;
						if (gl>=7) bosshp-=100;
						break;							    			
					}
					dt[y+i][x-i]='*';
			    }
				system("cls");
				for (int i=0;i<22;i++){
					for (int j=0;j<32;j++){						        
						cout<<dt[i][j];
					}						        
					cout<<endl;
				}  
				Sleep(300);		     
				for (int i=1;i<=15;i++){
					if (dt[y+i][x-i]=='#') break;
					if (dt[y+i][x-i]=='A'){
						break;
					}
					dt[y+i][x-i]=' ';
				}
				if (gl>=7) continue;
			}		
			else if(a=='7'){
				for (int i=x-1;i>=1;i--){
					if (dt[y][i]=='#') break;
					if (dt[y][i]=='A'){
						bosshp-=150;
						if (gl>=7) bosshp-=100;
						break;
					}
					dt[y][i]='-';
				}
				system("cls");
				for (int i=0;i<22;i++){
					for (int j=0;j<32;j++){
					    cout<<dt[i][j];
				    }
					cout<<endl;
				}  
				Sleep(300);
				for (int i=x-1;i>=0;i--){
					if (dt[y][i]=='#') break;
					if (dt[y][i]=='A'){
						break;
					}
					dt[y][i]=' ';
				}		
				if (gl>=7) continue;	
			}		
            else if (a=='8'){
				for (int i=1;i<=15;i++){			
					if (dt[y-i][x-i]=='#') break;			
					if (dt[y-i][x-i]=='A'){			
						bosshp-=150;
						if (gl>=7) bosshp-=100;
						break;							    			
					}
					dt[y-i][x-i]='*';
			    }
				system("cls");
				for (int i=0;i<22;i++){
					for (int j=0;j<32;j++){						        
						cout<<dt[i][j];
					}						        
					cout<<endl;
				}  
				Sleep(300);		     
				for (int i=1;i<=15;i++){
					if (dt[y-i][x-i]=='#') break;
					if (dt[y-i][x-i]=='A'){
						break;
					}
					dt[y-i][x-i]=' ';
				}
				if (gl>=7) continue;
			}
			else if(a=='b'&&CD==0){
				CD=10;
				int x3,y3;
				for (int i=0;i<=100;i++){
					x3=rand()%20+1,y3=rand()%19+1;
					if (dt[y3][x3]=='A') bosshp-=rand()%200;
					else if (dt[y3][x3]!='@'&&dt[y3][x3]!='#'&&dt[y3][x3]!='+') dt[y3][x3]='!';
				}  
				system("cls");
				for (int i=0;i<22;i++){
					for (int j=0;j<32;j++){
						cout<<dt[i][j];
						if (dt[i][j]=='!') dt[i][j]=' ';
					}
					cout<<endl;
				}
			}
			else if (a=='0'){
			    for (int i=y-7;i<=y+7;i++){
					for (int j=x-7;j<=x+7;j++){
					    if (dt[i][j]!='@'&&dt[i][j]!='A'&&dt[i][j]!='#'&&dt[i][j]!='+') dt[i][j]='^';
						else if(dt[i][j]=='A') bosshp-=rand()%50;
					}	
				}
				system("cls");
				for (int i=0;i<22;i++){
					for (int j=0;j<32;j++){
						cout<<dt[i][j];
					}
					cout<<endl;
				}
				Sleep(300);
				for (int i=y-7;i<=y+7;i++){
					for (int j=x-7;j<=x+7;j++){
					    if (dt[i][j]!='@'&&dt[i][j]!='A'&&dt[i][j]!='#') dt[i][j]=' ';
					}	
				}				
			}
		}
        if (bosshp>0){
        	if (y1==y&&x1-x<0){
				for (int i=x1+1;i<=30;i++){
					if (dt[y1][i]=='#') break;
					if (dt[y1][i]=='@'){
						playerhp-=50;
						break;
					}
					dt[y1][i]='-';
				}
				system("cls");
				for (int i=0;i<22;i++){
					for (int j=0;j<32;j++){
					    cout<<dt[i][j];
				    }
					cout<<endl;
				}  
				Sleep(300);
				for (int i=x1+1;i<=30;i++){
					if (dt[y1][i]=='#') break;
					if (dt[y1][i]=='@'){
						break;
					}
					dt[y1][i]=' ';
				}			
			}
			else if (y1==y&&x1-x>0){
				for (int i=x1-1;i>=1;i--){
					if (dt[y1][i]=='#') break;
					if (dt[y1][i]=='@'){
						playerhp-=50;
						break;
					}
					dt[y1][i]='-';
				}
				system("cls");
				for (int i=0;i<22;i++){
					for (int j=0;j<32;j++){
					    cout<<dt[i][j];
				    }
					cout<<endl;
				}  
				Sleep(300);
				for (int i=x1-1;i>=1;i--){
					if (dt[y1][i]=='#') break;
					if (dt[y1][i]=='@'){
						break;
					}
					dt[y1][i]=' ';
				}			
			}
			else if (x1==x&&y1-y<0){
				for (int i=y1+1;i<31;i++){
					if (dt[i][x1]=='#') break;
					if (dt[i][x1]=='@'){
						playerhp-=50;
						break;
					}
					dt[i][x1]='|';
				}
				system("cls");
		        for (int i=0;i<22;i++){
			        for (int j=0;j<32;j++){
				        cout<<dt[i][j];
		        	}
		        	cout<<endl;
				}  
				Sleep(300);
				for (int i=y1+1;i<31;i++){
				    if (dt[i][x1]=='#') break;
					if (dt[i][x1]=='@'){
						break;
					}
					dt[i][x1]=' ';
				}
			}
			else if (x1==x&&y1-y>0){
				for (int i=y1-1;i>0;i--){
					if (dt[i][x1]=='#') break;
					if (dt[i][x1]=='@'){
						playerhp-=50;
						break;
					}
					dt[i][x1]='|';
				}
				system("cls");
		        for (int i=0;i<22;i++){
			        for (int j=0;j<32;j++){
				        cout<<dt[i][j];
		        	}
		        	cout<<endl;
				}  
				Sleep(300);
				for (int i=y1-1;i>0;i--){
				    if (dt[i][x1]=='#') break;
					if (dt[i][x1]=='@'){
						break;
					}
					dt[i][x1]=' ';
				}				
			}
			else if (abs(x1-x)<=3&&abs(y1-y)<=3){
			    for (int i=y1-3;i<=y1+3;i++){
					for (int j=x1-3;j<=x1+3;j++){
						if (dt[i][j]=='@') lx+=5;
						else if (dt[i][j]!='A'&&dt[i][j]!='#') dt[i][j]='^';
					}
				}
				system("cls");
		        for (int i=0;i<22;i++){
			        for (int j=0;j<32;j++){
				        cout<<dt[i][j];
		        	}
		        	cout<<endl;
				}  
				Sleep(300);
				for (int i=y1-3;i<=y1+3;i++){
					for (int j=x1-3;j<=x1+3;j++){
						if (dt[i][j]!='A'&&dt[i][j]!='#'&&dt[i][j]!='@') dt[i][j]=' ';
					}
				}
			}
	        if (move==0){
				dt[y1][x1]=' ';
				y1=rand()%20+1;
				x1=rand()%30+1;
				if (y1==y&&x1==x){
					system("cls");
					cout<<"你的运气真逆天";
					return 0;
				}
				dt[y1][x1]='A';
			}	
			else if (move==1&&dt[y1-1][x1]!='@'&&dt[y1-1][x1]!='#'){
				dt[y1][x1]=' ';
				y1--;
				dt[y1][x1]='A';
			}
			else if (move==2&&dt[y1-1][x1+1]!='@'&&dt[y1-1][x1+1]!='#'){
				dt[y1][x1]=' ';
				y1--;
				x1++;
				dt[y1][x1]='A';
			}
			else if (move==3&&dt[y1][x1+1]!='@'&&dt[y1][x1+1]!='#'){
				dt[y1][x1]=' ';
				x1++;
				dt[y1][x1]='A';
			}
			else if (move==4&&dt[y1+1][x1+1]!='@'&&dt[y1+1][x1+1]!='#'){
				dt[y1][x1]=' ';
				x1++;
				y1++;
				dt[y1][x1]='A';
			}
			else if (move==5&&dt[y1+1][x1]!='@'&&dt[y1+1][x1]!='#'){
				dt[y1][x1]=' ';
				y1++;
				dt[y1][x1]='A';
			}
			else if (move==6&&dt[y1+1][x1-1]!='@'&&dt[y1+1][x1-1]!='#'){
				dt[y1][x1]=' ';
				x1--;
				y1++;
				dt[y1][x1]='A';
			}
			else if (move==7&&dt[y1][x1-1]!='@'&&dt[y1][x1-1]!='#'){
				dt[y1][x1]=' ';
				x1--;
				dt[y1][x1]='A';
			}		
	        else if (move==8&&dt[y1-1][x1-1]!='@'&&dt[y1-1][x1-1]!='#'){
				dt[y1][x1]=' ';
				x1--;
				y1--;
				dt[y1][x1]='A';
			}		
		}
		system("cls");
		for (int i=0;i<22;i++){
			for (int j=0;j<32;j++){
				cout<<dt[i][j];
			}
			cout<<endl;
		}  
		cout<<"玩家血量:"<<playerhp<<endl;
		cout<<"BOSS血量:"<<bosshp<<endl; 
		cout<<"大招CD:"<<CD<<endl;
		if (CD>0) CD--; 
		playerhp-=lx;
	}
    return 0;
}
1 个赞

论坛不允许游戏代码哦~(所以关帖)

1 个赞