推箱子

#include <bits/stdc++.h>
using namespace std;
int col=4;//行 
int row=6;//列
int box1_x[3],box1_y[3];
char ct;
int mcol=16;
int mrow=16;
void box_p(char fx){
	for(int i=0;i<3;i++){
		if(box1_x[i]==col && box1_y[i]==row){
			if(fx=='w'){
				box1_x[i]--;
			}else if(fx=='s'){
				box1_x[i]++;
			}else if(fx=='a'){
				box1_y[i]--;
			}else if(fx=='d'){
				box1_y[i]++;
			}
			break;
		}
	}	
}
int main(int argc, char** argv) {
	srand(time(0));
	for(int i=0;i<3;i++){
		box1_x[i]=rand()%16;
		box1_y[i]=rand()%16;
	}
	while(1){
		for(int i=0;i<mcol;i++){
			for(int j=0;j<mrow;j++){
				if(i==col&&j==row){
					cout<<setw(3)<<'A';
				}else{
					bool a=true;
					for(int k=0;k<3;k++){
						if(box1_x[k]==i&&box1_y[k]==j){
							cout<<setw(3)<<"口";
							a=false;
						}
					}
					if(a){
						cout<<setw(3)<<'.';
					}
					
				}
			}
		cout<<endl;
		}
		cout<<"请输入:wasd"<<endl;
		cin>>ct;
		if(ct=='w'||ct=='W'){
			col--;
			if(col<0){
			col=0;
			}
			box_p('w');
		}else if(ct=='s'||ct=='S'){
			col++;
			if(col>=mcol){
			col=mcol-1;
			}
			box_p('s');
		}else if(ct=='a'||ct=='A'){
			row--;
			if(row<0){
			row=0;
			}
			box_p('a');
		}else if(ct=='d'||ct=='D'){
			row++;
			if(row>=mrow){
			row=mrow-1;
			}
			box_p('d');
		}else if(ct=='q'||ct=='Q'){
			cout<<"拜拜了,您嘞!";
			break;
		}
		system("cls");
	}
	return 0;
}

  

posted @ 2023-08-08 20:31  fushuxuan1  阅读(28)  评论(0)    收藏  举报