c++贪吃蛇(手动版不到90行)


#include 
#include 
#include 
#include 
//wsad,上下左右
using namespace std;
char arr[24][42];
char flag = '+';
int w = 1,h = 3;
int w_flag = 1, h_flag = 1;
int snake_body_a[100000];
int snake_body_b[100000];
int snake_len = 3;
int p = 1;
int food_a = 5;
int food_b = 5;
char ch;

void init_arr(){
	int i,j;
	for(i=0; i<24; ++i){
		for(j=0;j<42; ++j){
			if(i == 0 || i == 23)
				arr[i][j] = '*';
			else if(j==0 || j==41)
				arr[i][j] = '€';
			else arr[i][j] = ' ';			
		}
	}	
	if(w>=1 && w<=22 && h>=1 && h<=40){		
		p++;
		snake_body_a[p] = w;
		snake_body_b[p] = h;
	}	
	for(int i=snake_len-1; i>=0; --i){
		arr[snake_body_a[p - i]][snake_body_b[p - i]] = flag;	
	}
	arr[food_a][food_b] = '@';
}
void show_arr(){
	int i,j;	
	for(i=0; i<24; ++i){
		for(j=0;j<42;++j){
			printf("%c",arr[i][j]);
		}		
		if(i == 23) printf("  snake_len: %d -- £¨wsad 上下左右",snake_len);
		printf("\n");		
	}
}
void process_graph(char ch){
	system("CLS");		
	show_arr();	
	if (ch == 115) w++;
	if (ch == 119) w--;
	if (ch == 97) h--;
	if (ch == 100) h++;			
	if(food_a == w && food_b == h){
		int a = rand()%40 + 1;
		int b = rand()%22 + 1;
		food_a = b;
		food_b = a;
		snake_len++;			
	}		
	init_arr();	
	int time_count = 1<<28;
	while(time_count--);
}
int main(){	
	int len_a[] = {1, 1, 1};
	int len_b[] = {1, 2, 3};
	for(int i=0; i<3; ++i){
		snake_body_a[i] = len_a[i];
		snake_body_b[i] = len_b[i];	
	}
	show_arr();
	init_arr();
	ch = 115;
	while(true){		
		if(_kbhit()){
			int temp = ch;			
			ch = getch();
			if(!(ch == 97 || ch == 100 || ch == 115 || ch == 119)){
				ch = temp;
			}
			cout<

 

你可能感兴趣的:(其他)