C语言射击游戏练习程序

#include 
#include 
#include 
#define CPRTBLK pos(control_block.x,control_block.y);printf("   ")
#define BPRTBLK pos(ball.x,ball.y);printf(" ")
#define NUM_TARGET 12

void pos(int pos_x,int pos_y){
	HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
	COORD pos={pos_x,pos_y};
	SetConsoleCursorPosition(hOut,pos);
}
void HideCursor(){
	HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO cursor={1,0};
	SetConsoleCursorInfo(hOut,&cursor);
}
//定义一个方块的结构体
typedef struct block{
	int x;
	int y;
}BLK;
//定义一个小球的结构体
typedef struct ball{
	int x;
	int y;
}BALL;
int main(){
	int i;
	//初始化控制体
	BLK control_block={10,20};
	pos(control_block.x,control_block.y);
	printf("000");
	//目标结构体
	BLK target[NUM_TARGET];
	//初始化小球
	BALL ball={11,19};
	pos(ball.x,ball.y);
	printf("x");
	//目标阵列
	for(i=0;i=target[0].y){
				if(ball.y==target[0].y){
					pos(ball.x,ball.y);
					printf(" ");
					ball.y=19;
					break;
				}
				BPRTBLK;
				ball.y--;
				pos(ball.x,ball.y);
				printf("x");
				pos(control_block.x,control_block.y);
				printf("000");
				for(i=0;i=target[i].x && ball.x<=target[i].x+2 && ball.y==target[i].y){
						pos(target[i].x,target[i].y);
						printf("   ");
					}
				}
				Sleep(50);
			}
			break;
		}
		pos(control_block.x,control_block.y);
		printf("000");
		pos(ball.x,ball.y);
		printf("x");
	}
	return 0;
}

你可能感兴趣的:(C语言)