反弹球消砖块,是一款很简单的打砖块游戏,控制你的挡板挡住弹球,打掉上面的砖块,本片博客中,主要使用printf与scanf函数实现消砖块游戏
整体思路
主函数
int main()
{
startup();
while (1)
{
show();
updateWitoutIput();
updateWithInput();
}
return 0;
}
辅助函数
void gotoxy(int x, int y)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle, pos);
}
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor_info = {
1, 0 };
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
全局变量的定义
#define HIGH 20
#define WIDTH 30
#define V 1
#define RIDUS 5
int ball_x, ball_y;
int ball_vx, ball_vy;
int position_x, position_y;
int left, right;
int ball_number;
int block_x, block_y;
int score;
数据的初始化
ball_x = HIGH / 2;
ball_y = WIDTH / 2;
ball_vx = V;
ball_vy = V;
position_x = HIGH / 2;
position_y = WIDTH / 2;
left = position_y - RIDUS;
right = position_y + RIDUS;
block_x = 0;
block_y = WIDTH / 2;
score = 0