#include <curses.h> /* 关于游戏区域的常量定义 */ #define TOP_ROW 0 // 游戏区域的上边界 #define BOT_ROW LINES // 游戏区域的下边界 #define LEFT_EDGE 0 // 游戏区域的左边界 #define RIGHT_EDGE COLS; // 游戏区域的右边界 /* * 关于挡板的常量定义 */ #define BLANK_BAFFLE " " // 用于擦除使用 #define SYMBOL_BAFFLE "========" // 挡板的字符化表示 #define X_INIT_BAFFLE COLS / 2 - 4 // 挡板 X 坐标的初始值 #define Y_INIT_BAFFLE LINES // 挡板 Y 坐标的初始值 /* 关于球的常量定义 */ #define BLANK_BALL ' ' // 用于擦除使用 #define SYMBOL_BALL 'O' // 球的字符化表示 #define X_INIT_BALL COLS / 2 // 球 X 坐标的初始值 #define Y_INIT_BALL LINES - 1 // 球 Y 坐标的初始值 struct Ball { int x_poi, y_poi; // 球的 X,Y 坐标 int x_speed, y_speed; // 球在 X,Y 方向的速度 char symbol; // 球的字符化表示 }; struct Baffle { int x_poi, y_poi; // 挡板的 X,Y 坐标 int length; // 挡板的长度 int speed; // 挡板的速度(仅在 X 方向上) char *symbol; // 挡板的字符化表示 };
#include <signal.h> #include <sys/time.h> #include <stdio.h> #include <sys/time.h> void set_up(); void wrap_up(); struct Ball ball; int main() { int ch; set_up(); } void set_up() { void ball_move(int); initscr(); box(stdscr, ACS_VLINE, ACS_HLINE); noecho(); crmode(); ball.x }
#define BRICK_LEFT = COLS / 2 - 6; #define BRICK_RIGHT = COLS / 2 + 8; #define BRICK_TOP = 1; #define BRICK_BOTTOM = 5; void init(); void wrap_up(); struct Ball ball; struct Baffle baffle; int matrix[5][15]; int main() { int ch; init(); } void init() { int i,j; for(i = 0; i < 5; i++) { for(j = 0; j < 15; j++) { matrix[i][j] = 0; } } initscr(); box(stdscr, ACS_VLINE, ACS_HLINE); noecho(); crmode(); ball.x_poi = X_INIT_BALL; ball.y_poi = Y_INIT_BALL; ball.x_speed = X_SPEED_INIT; //加上 ball.y_speed = Y_SPEED_INIT; // baffle.x_left = BAFFLE_LEFT_INIT; baffle.y_right = BAFFLE_RIGHT_INIT; for(i = BRICK_LEFT, j = BRICK_TOP; i <= BRICK_RIGHT; i++, j++) { } for() }