贪吃蛇源程序(2) #define SCALE 8 #define UP_KEY 0x4800 #define DOWN_KEY 0x5000 #define LEFT_KEY 0x4b00 #define RIGHT_KEY 0x4d00 #define MOVE_UP 1 #define MOVE_LEFT 2 #define MOVE_DOWN 3 #define MOVE_RIGHT 4 #define INVALID_DIRECTION 0 #define QUIT_KEYC 0x1051 #define QUIT_KEY 0x1071 #define SELECT_KEYC 0x1f53 #define SELECT_KEY 0x1f73 #define PAUSE_KEYC 0x1950 #define PAUSE_KEY 0x1970 #define DEFAULT_LEVEL 1 #define HELP_COLOR WHITE #define WELCOME_COLOR WHITE #define DEFAULT_COLOR GREEN /* define the macro as follows to improve the game in future */ #define FOOD_COLOR YELLOW #define SNAKE_HEAD_COLOR RED #define DEFAULT_SNAKE_COLOR YELLOW
#define EXIT_COLOR WHITE #define SCORE_COLOR YELLOW
/* sturcture for snake body mainly ,and food also */ typedef strUCt food_infor *FOOD_INFOR_PTR; typedef struct food_infor{ int posx; /* position for each piece of snake body */ int posy; int next_move; /* next move direction */ int pre_move; /* previous move direction,seems unuseful */ int beEaten; /* xidentifier for snake body or food */ FOOD_INFOR_PTR next; /* pointer to next piece of snake body */ FOOD_INFOR_PTR pre; /* pointer to previous piece of snake body */