我是指针,却丢失了目标地址! 我是循环,却缺少了结束条件! 我是函数,却没有人来调用!
在c语言之家看到一篇代码,“五彩贪吃蛇”
效果也很不错,借此帖转帖一下。
五彩贪吃蛇 C源代码 原创 作者:Marlio Sky
Hello!好久没来C语言之家了, 由于最近工作太忙了, 我自己的空余时间太少, 个人的PROJECT就没法进行下去, 这个代码是我在最近一个星期内才完成的.
首先我个人先介绍一下, 我是一个PC机游戏的开发爱好者. 我的这个游戏代码其实是应该用VC++6.0 加 Direct X 9.0 来完成的, 但是, 由于VC太复杂, DIRECT也有点难, 我个人正在学习中, 我个人知道只有这样才能迎合MICRO SOFT的PC开发平台.
Turbo C 2.0 的开发平台虽然说有些过时, 但是对于锻炼一些'C的技巧'和'项目的思路'还是很有帮助的! 在这个代码中, 我主要引用了面向对象的思路, 成员数据, 成员方法, 事件 ... 好了, 看一下代码吧!
/*
The Game: Greedy Snake which be developed by Marlio in Turbo C 2.0
Copyright (c) Feb 25th, 2006 -- ... Wind_Dancing Studio All copy rights reserved.
*//*
GLO_GS.h info:
1. constants defined
2. data struct
3. global variable
*/#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <graphics.h>
#include <bios.h>
#include <dos.h>/* size and position of vessal(pixel) */
#define LEFT_MARGIN 140
#define FRAME_UNIT_WIDTH 25
#define FRAME_UNIT_HEIGHT 15
#define BOX_SIZE 15/* the display mode (640*480) */
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480/*
When the game starts, the default position which the
snake will appear in the frame.
*/
#define SNAK_DEFAULT_POS_X 10
#define SNAK_DEFAULT_POS_Y 5/* direction of the snake move towards to */
#define SMD_UP 1
#define SMD_DOWN 2
#define SMD_RIGHT 3
#define SMD_LEFT 4/* the event of keyboard(ASCI code) */
#define UP_MOVE 72
#define DOWN_MOVE 80
#define LEFT_MOVE 75
#define RIGHT_MOVE 77
#define STEP_MOVE 7
#define GAME_STOP 57
#define ESC_OUT 1
#define GENERAT_EGG 8
#define NO_EVENT 0/* data type defined (Bool) */
#define Boolean int
#define TRUTH 1
#define FALS 0/* data type defined (Game Status) */
#define Type_GAMESTATUS int
#define ON_PALYING 2
#define WINNER 1
#define GAMEOVER 0/* clock interval */
#define TIMEINTERVAL 6typedef struct
{
int p_X;
int p_Y;
}POS_in_Fram;typedef struct SNode
{
POS_in_Fram cur_pos;
int color;
struct SNode *next;
}SNode, *LSNode;typedef struct
{
int direction;
int len;
POS_in_Fram Head_pre_pos;
POS_in_Fram Head_cur_pos;
int Head_color;
LSNode next;
Boolean Dead;
}SNAK;typedef struct
{
POS_in_Fram egg_pos;
int egg_color;
}EggType;/*
The head of snake: It is only head node in the link list.
There are some body nodes at the tail of head.
*/
SNAK obj_snake;/*
the egg which the snake will eat in the frame.
*/
EggType obj_egg;int Message_Event;
int ScoreTotal;
int SpeedLevel;
/* the flag label: sign the game status */
Type_GAMESTATUS GameStat;/*
GS_ALG.c info:
In this file, basic method of data object, the function which used to initialize some data struct,
and graphic drawing interface defined in some method will be listed here.
*//* Message_Event.Method: 1 */
void set_Message_Event(int T)
{
Message_Event = T;
}
/* Message_Event.Method: 2 */
int get_Message_Event()
{
return(Message_Event);
}/* ScoreTotal.Method: 1 */
void clear_ScoreTotal()
{
ScoreTotal = 0;
}
/* ScoreTotal.Method: 2 */
int get_ScoreTotal()
{
return(ScoreTotal);
}
/* ScoreTotal.Method: 3 */
void draw_ScoreTotal()
{
char text_buffer[20];
int ul_X, ul_Y;
ul_X = LEFT_MARGIN;
ul_Y = WINDOW_HEIGHT - BOX_SIZE * (FRAME_UNIT_HEIGHT - 4);
/* erase the previous score in window */
setcolor(BLUE);
sprintf(text_buffer, \"Score Total: %d\", get_ScoreTotal());
moveto(ul_X, ul_Y);
outtext(text_buffer);
/* draw the new score in window */
setcolor(YELLOW);
ScoreTotal++;
sprintf(text_buffer, \"Score Total: %d\", get_ScoreTotal());
moveto(ul_X, ul_Y);
outtext(text_buffer);
}/* SpeedLevel.Method: 1 */
void init_SpeedLevel()
{
SpeedLevel = 1;
}
/* SpeedLevel.Method: 2 */
int get_SpeedLevel()
{
return(SpeedLevel);
}
/* SpeedLevel.Method: 3 */
void draw_SpeedLevel(int old_l, int new_l)
{
char text_buffer[20];
int ul_X, ul_Y;
ul_X = LEFT_MARGIN;
ul_Y = WINDOW_HEIGHT - BOX_SIZE * (FRAME_UNIT_HEIGHT - 4);
/* erase the old speed level */
setcolor(BLUE);
sprintf(text_buffer, \"Speed Level: %d\", old_l);
moveto(ul_X, ul_Y + textheight(\"H\") * 2);
outtext(text_buffer);
/* draw the new speed level */
setcolor(YELLOW);
sprintf(text_buffer, \"Speed Level: %d\", new_l);
moveto(ul_X, ul_Y + textheight(\"H\") * 2);
outtext(text_buffer);
}
/* SpeedLevel.Method: 4 */
void setSpeedLevel(int score)
{
if(score >= 0 && score < 20)
{
draw_SpeedLevel(get_SpeedLevel(), 1);
SpeedLevel = 1;
}
else if(score >= 20 && score < 50)
{
draw_SpeedLevel(get_SpeedLevel(), 2);
SpeedLevel = 2;
}
else if(score >= 50 && score < 100)
{
draw_SpeedLevel(get_SpeedLevel(), 3);
SpeedLevel = 3;
}
else
{
draw_SpeedLevel(get_SpeedLevel(), 4);
SpeedLevel = 4;
}
}/* GameStat.Method: 1 */
void set_GameStat(Type_GAMESTATUS state)
{
GameStat = state;
}
/* GameStat.Method: 2 */
Type_GAMESTATUS get_GameStat()
{
return(GameStat);
}/* obj_snake.Dead.Method: 1 */
void set_SnakeDead(Boolean T)
{
obj_snake.Dead = T;
}
/* obj_snake.Dead.Method: 2 */
Boolean Is_SnakeDead()
{
return(obj_snake.Dead);
}/* get the opposit direction of the snake head */
int get_SHOD(int T)
{
switch(T)
{
case SMD_UP:
return(SMD_DOWN);
case SMD_DOWN:
return(SMD_UP);
case SMD_RIGHT:
return(SMD_LEFT);
case SMD_LEFT:
return(SMD_RIGHT);
}
}/* get the current direction of the snake head */
int get_SHD()
{
return(obj_snake.direction);
}/* To find certian node in the snake link list */
Boolean findPointInSnake(int pX, int pY)
{
LSNode p;
if((obj_snake.Head_cur_pos.p_X == pX) && (obj_snake.Head_cur_pos.p_Y == pY))
return(TRUTH);
for(p = obj_snake.next;p != NULL;p = p->next)
{
if((p->cur_pos.p_X == pX) && (p->cur_pos.p_Y == pY))
return(TRUTH);
}
return(FALS);
}/* judge that whether the snake is eating the egg */
Boolean Is_SnakEating()
{
if((obj_snake.Head_pre_pos.p_X == obj_egg.egg_pos.p_X) && (obj_snake.Head_pre_pos.p_Y == obj_egg.egg_pos.p_Y))
return(TRUTH);
else
return(FALS);
}void Init_obj_snake()
{
obj_snake.direction = SMD_RIGHT;
obj_snake.len = 1;
obj_snake.Head_cur_pos.p_X = SNAK_DEFAULT_POS_X;
obj_snake.Head_cur_pos.p_Y = SNAK_DEFAULT_POS_Y;
obj_snake.Head_pre_pos = obj_snake.Head_cur_pos;
obj_snake.Head_color = RED;
obj_snake.next = NULL;
obj_snake.Dead = FALS;
}void Init_obj_egg()
{
obj_egg.egg_pos.p_X = 0;
obj_egg.egg_pos.p_Y = 0;
obj_egg.egg_color = BLACK;
}void RegistryGraphicMode()
{
int Driver, Mode;
/* display mode(640*480) */
detectgraph(&Driver, &Mode);
registerbgidriver(EGAVGA_driver);
initgraph(&Driver, &Mode, \"c:\\turboc2\");
}void Draw_FrameInWindow(int f_ul_X, int f_ul_Y, int f_dr_X, int f_dr_Y, int W, int H)
{
int i, x, y;
rectangle(f_ul_X - 1, f_ul_Y - 1, f_dr_X + 1, f_dr_Y + 1);
setfillstyle(SOLID_FILL, BLACK);
bar(f_ul_X, f_ul_Y, f_dr_X, f_dr_Y);
setcolor(DARKGRAY);
for(i = 1;i < W;i++)
{
x = f_ul_X + i * BOX_SIZE;
line(x, f_ul_Y, x, f_dr_Y);
}
for(i = 1;i < H;i++)
{
y = f_ul_Y + i * BOX_SIZE;
line(f_ul_X, y, f_dr_X, y);
}
}void Draw_mainGraphWindow()
{
int ul_X, ul_Y, dr_X, dr_Y;
char text_buffer[33];
setfillstyle(SOLID_FILL, BLUE);
bar(0, 0, WINDOW_WIDTH - 1, WINDOW_HEIGHT - 1);
ul_X = LEFT_MARGIN;
ul_Y = WINDOW_HEIGHT - BOX_SIZE * (FRAME_UNIT_HEIGHT * 2 - 3);
dr_X = LEFT_MARGIN + BOX_SIZE * FRAME_UNIT_WIDTH;
dr_Y = WINDOW_HEIGHT - BOX_SIZE * (FRAME_UNIT_HEIGHT - 3);
Draw_FrameInWindow(ul_X, ul_Y, dr_X, dr_Y, FRAME_UNIT_WIDTH, FRAME_UNIT_HEIGHT);
ul_X = LEFT_MARGIN;
ul_Y = WINDOW_HEIGHT - BOX_SIZE * (FRAME_UNIT_HEIGHT - 4);settextjustify(LEFT_TEXT, TOP_TEXT);
settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
setcolor(YELLOW);
sprintf(text_buffer, \"Score Total: %d\", get_ScoreTotal());
moveto(ul_X, ul_Y);
outtext(text_buffer);
sprintf(text_buffer, \"Speed Level: %d\", get_SpeedLevel());
moveto(ul_X, gety() + textheight(\"H\") * 2);
outtext(text_buffer);
strcpy(text_buffer, \"EXIT: ESC Button\");
moveto(ul_X, gety() + textheight(\"H\") * 2);
outtext(text_buffer);
strcpy(text_buffer, \"Created By: Marlio Sky\");
moveto(ul_X, gety() + textheight(\"H\") * 2);
outtext(text_buffer);
strcpy(text_buffer, \"Studio: Wind Dancing\");
moveto(ul_X, gety() + textheight(\"H\") * 2);
outtext(text_buffer);
strcpy(text_buffer, \"UP: Up Arrow\");
moveto(ul_X + textwidth(\"H\") * 30, ul_Y);
outtext(text_buffer);
strcpy(text_buffer, \"DOWN: Down Arrow\");
moveto(ul_X + textwidth(\"H\") * 30, gety() + textheight(\"H\") * 2);
outtext(text_buffer);
strcpy(text_buffer, \"LEFT: Left Arrow\");
moveto(ul_X + textwidth(\"H\") * 30, gety() + textheight(\"H\") * 2);
outtext(text_buffer);
strcpy(text_buffer, \"RIGHT: Right Arrow\");
moveto(ul_X + textwidth(\"H\") * 30, gety() + textheight(\"H\") * 2);
outtext(text_buffer);
strcpy(text_buffer, \"STOP: Space Button\");
moveto(ul_X + textwidth(\"H\") * 30, gety() + textheight(\"H\") * 2);
outtext(text_buffer);
}/*
draw the egg in the Frame
Boolean T: -- TRUTH draw the egg with its own color in Frame
-- FALS draw the egg with BLACK color in Frame(erase snake)
*/
void draw_egg(Boolean T)
{
int ul_X, ul_Y;
int color;
ul_X = LEFT_MARGIN;
ul_Y = WINDOW_HEIGHT - BOX_SIZE * (FRAME_UNIT_HEIGHT * 2 - 3);
if(T == FALS)
color = BLACK;
else
color = obj_egg.egg_color;
setfillstyle(SOLID_FILL, color);
bar(ul_X + BOX_SIZE * obj_egg.egg_pos.p_Y + 1, ul_Y + BOX_SIZE * obj_egg.egg_pos.p_X + 1, ul_X + BOX_SIZE * (obj_egg.egg_pos.p_Y + 1) - 1, ul_Y + BOX_SIZE * (obj_egg.egg_pos.p_X + 1) - 1);
}/*
refresh the runtime environment
Boolean T: -- TRUTH draw the snake node with their own color in Frame
-- FALS draw the snake node with BLACK color in Frame(erase snake)
*/
void Mapped_Draw(Boolean T)
{
int ul_X, ul_Y;
int Ax, Ay, Bx, By;
int color;
LSNode p;
ul_X = LEFT_MARGIN;
ul_Y = WINDOW_HEIGHT - BOX_SIZE * (FRAME_UNIT_HEIGHT * 2 - 3);
if(T == FALS)
color = BLACK;
else
color = obj_snake.Head_color;
setfillstyle(SOLID_FILL, color);
Ax = ul_X + BOX_SIZE * obj_snake.Head_cur_pos.p_Y + 1;
Ay = ul_Y + BOX_SIZE * obj_snake.Head_cur_pos.p_X + 1;
Bx = ul_X + BOX_SIZE * (obj_snake.Head_cur_pos.p_Y + 1) - 1;
By = ul_Y + BOX_SIZE * (obj_snake.Head_cur_pos.p_X + 1) - 1;
bar(Ax, Ay, Bx, By);
if(T == TRUTH)
{
setfillstyle(SOLID_FILL, YELLOW);
bar(Ax + 4, Ay + 4, Ax + 4 + 5, Ay + 4 + 5);
}
for(p = obj_snake.next;p != NULL;p = p->next)
{
if(T == FALS)
color = BLACK;
else
color = p->color;
setfillstyle(SOLID_FILL, color);
Ax = ul_X + BOX_SIZE * p->cur_pos.p_Y + 1;
Ay = ul_Y + BOX_SIZE * p->cur_pos.p_X + 1;
Bx = ul_X + BOX_SIZE * (p->cur_pos.p_Y + 1) - 1;
By = ul_Y + BOX_SIZE * (p->cur_pos.p_X + 1) - 1;
bar(Ax, Ay, Bx, By);
}
}/* draw 'game start' or 'game over' surface */
void draw_GS_GO_Surface(Type_GAMESTATUS T)
{
char text_buffer[40];
settextjustify(LEFT_TEXT, TOP_TEXT);
switch(T)
{
case ON_PALYING:
settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 4);
setcolor(LIGHTCYAN);
strcpy(text_buffer, \"ITEM - 2: Game.Greed Snake\");
moveto(100, 100);
outtext(text_buffer);
settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 1);
setcolor(YELLOW);
strcpy(text_buffer, \"Please press any key to continue ...\");
moveto(150, 300);
outtext(text_buffer);
break;
case GAMEOVER:
settextstyle(GOTHIC_FONT, HORIZ_DIR, 8);
setcolor(RED);
strcpy(text_buffer, \"GAME OVER\");
moveto(70, 80);
outtext(text_buffer);
settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 2);
setcolor(YELLOW);
strcpy(text_buffer, \"Sorry!\");
moveto(160, 320);
outtext(text_buffer);
sprintf(text_buffer, \"Total Score: %d\", get_ScoreTotal());
moveto(240, 320);
outtext(text_buffer);
sprintf(text_buffer, \"Speed Level: %d\", get_SpeedLevel());
moveto(240, 350);
outtext(text_buffer);
break;
case WINNER:
settextstyle(GOTHIC_FONT, HORIZ_DIR, 8);
setcolor(RED);
strcpy(text_buffer, \"YOU WIN !\");
moveto(80, 80);
outtext(text_buffer);
settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 2);
setcolor(YELLOW);
strcpy(text_buffer, \"Congratulation!\");
moveto(120, 320);
outtext(text_buffer);
sprintf(text_buffer, \"Total Score: %d\", get_ScoreTotal());
moveto(280, 320);
outtext(text_buffer);
sprintf(text_buffer, \"Speed Level: %d\", get_SpeedLevel());
moveto(280, 350);
outtext(text_buffer);
break;
default:
break;
}
}/*
GS_ALG1.c info:
In this file, some function and module is main caculation for Russion Block.
The dispatcher will directly invoke the action procedure.
*//* According to incoming parameter, set the predictly position of snake head. */
void set_SH_Pre_Pos(int T)
{
int H_pX, H_pY;
H_pX = obj_snake.Head_cur_pos.p_X;
H_pY = obj_snake.Head_cur_pos.p_Y;
switch(T)
{
case SMD_UP:
if((H_pX - 1) < 0 || findPointInSnake(H_pX - 1, H_pY) == TRUTH)
{
set_SnakeDead(TRUTH);
return;
}
obj_snake.Head_pre_pos.p_X = H_pX - 1;
obj_snake.Head_pre_pos.p_Y = H_pY;
break;
case SMD_DOWN:
if((H_pX + 1) >= FRAME_UNIT_HEIGHT || findPointInSnake(H_pX + 1, H_pY) == TRUTH)
{
set_SnakeDead(TRUTH);
return;
}
obj_snake.Head_pre_pos.p_X = H_pX + 1;
obj_snake.Head_pre_pos.p_Y = H_pY;
break;
case SMD_RIGHT:
if((H_pY + 1) >= FRAME_UNIT_WIDTH || findPointInSnake(H_pX, H_pY + 1) == TRUTH)
{
set_SnakeDead(TRUTH);
return;
}
obj_snake.Head_pre_pos.p_X = H_pX;
obj_snake.Head_pre_pos.p_Y = H_pY + 1;
break;
case SMD_LEFT:
if((H_pY - 1) < 0 || findPointInSnake(H_pX, H_pY - 1) == TRUTH)
{
set_SnakeDead(TRUTH);
return;
}
obj_snake.Head_pre_pos.p_X = H_pX;
obj_snake.Head_pre_pos.p_Y = H_pY - 1;
break;
}
}/* set the direction of snake head */
Boolean set_SHD(int T)
{
if(get_SHD() == T || get_SHOD(get_SHD()) == T)
return(FALS);
obj_snake.direction = T;
return(TRUTH);
}/*
the main processing algorithem flow:
+--------+ +------------+ +-----------+ +-----------+
| | | | | | | |
+-------+-------+----+ +-------+----+ +-------+----+ +-------+----+
|pre_pos|cur_pos|next---->|cur_pos|next---->|cur_pos|next---->|cur_pos|next---->
+-------+-------+----+ +-------+----+ +-------+----+ +-------+----+
snake head snake body 1 snake body 2 snake body3
*/
void process_SnakeNode(Boolean eated)
{
int i;
POS_in_Fram temp1_cur_pos, temp2_cur_pos;
LSNode p, q;
temp1_cur_pos = obj_snake.Head_cur_pos;
obj_snake.Head_cur_pos = obj_snake.Head_pre_pos;
p = obj_snake.next;
for(i = 1;i < obj_snake.len;i++)
{
temp2_cur_pos = p->cur_pos;
p->cur_pos = temp1_cur_pos;
temp1_cur_pos = temp2_cur_pos;
p = p->next;
}
if(eated == TRUTH)
{
q = (LSNode)malloc(sizeof(SNode));
q->color = obj_egg.egg_color;
q->cur_pos = temp1_cur_pos;
if(obj_snake.len == 1)
{
q->next = obj_snake.next;
obj_snake.next = q;
obj_snake.len++;
return;
}
for(p = obj_snake.next;p->next != NULL;p = p->next);
q->next = p->next;
p->next = q;
obj_snake.len++;
}
}/* When an egg is eated, generating an new egg */
void generate_Egg()
{
int temp_pX, temp_pY, temp_color;
draw_egg(FALS);
temp_pX = random(FRAME_UNIT_HEIGHT);
temp_pY = random(FRAME_UNIT_WIDTH);
while(findPointInSnake(temp_pX, temp_pY) == TRUTH)
{
temp_pX = random(FRAME_UNIT_HEIGHT);
temp_pY = random(FRAME_UNIT_WIDTH);
}
obj_egg.egg_pos.p_X = temp_pX;
obj_egg.egg_pos.p_Y = temp_pY;
for(temp_color = random(16);temp_color == BLACK;temp_color = random(16));
obj_egg.egg_color = temp_color;
draw_egg(TRUTH);
set_Message_Event(NO_EVENT);
}/* These movement includes Up, Down, Left, Right and Step move. */
void move_To(int T, Boolean step)
{
if(step == FALS)
{
if(set_SHD(T) == FALS)
goto Skip_1;
}
set_SH_Pre_Pos(T);
if(Is_SnakeDead() == TRUTH)
goto Skip_2;
if(Is_SnakEating() == TRUTH)
{
Mapped_Draw(FALS);
process_SnakeNode(TRUTH);
Mapped_Draw(TRUTH);
draw_ScoreTotal();
setSpeedLevel(get_ScoreTotal());
goto Skip_3;
}
else
{
Mapped_Draw(FALS);
process_SnakeNode(FALS);
Mapped_Draw(TRUTH);
goto Skip_1;
}
Skip_1:
set_Message_Event(NO_EVENT);
return;
Skip_2:
set_Message_Event(ESC_OUT);
return;
Skip_3:
set_Message_Event(GENERAT_EGG);
return;
}void pause_game()
{
while((bioskey(0) >> 8) != GAME_STOP);
set_Message_Event(NO_EVENT);
}void process_GameStat(Type_GAMESTATUS T)
{
LSNode p, q;
switch(T)
{
case ON_PALYING:
draw_GS_GO_Surface(ON_PALYING);
break;
case WINNER:
cleardevice();
draw_GS_GO_Surface(WINNER);
getch();
break;
case GAMEOVER:
cleardevice();
draw_GS_GO_Surface(GAMEOVER);
getch();
break;
default:
break;
}
/* delete the snake, free the node */
p = obj_snake.next;
while(p != NULL)
{
q = p->next;
free(p);
p = q;
}
}/*
GS_ALG2.c info:
In this file, \"the kernal of game\".
Main function:
the clock time dispatched, getting message, dispatching the event
*/Boolean IsWinner()
{
if(get_SpeedLevel() == 4)
return(TRUTH);
else
return(FALS);
}Boolean IsGameOver()
{
if(get_Message_Event() == ESC_OUT)
return(TRUTH);
else
return(FALS);
}Boolean IsTimeOut()
{
static long temp, sourc;
temp = biostime(0, sourc);
if((temp - sourc) < (TIMEINTERVAL - SpeedLevel))
return FALS;
else
{
sourc = temp;
return TRUTH;
}
}void getMessageEvent()
{
if(get_Message_Event() == GENERAT_EGG || get_Message_Event() == ESC_OUT || get_Message_Event() == GAME_STOP)
return;
if(IsTimeOut() == TRUTH)
{
set_Message_Event(STEP_MOVE);
return;
}
if(bioskey(1))
{
set_Message_Event(bioskey(0) >> 8);
return;
}
}void dispatchMessage_Event()
{
switch(get_Message_Event())
{
case UP_MOVE:
move_To(SMD_UP, FALS);
break;
case DOWN_MOVE:
move_To(SMD_DOWN, FALS);
break;
case LEFT_MOVE:
move_To(SMD_LEFT, FALS);
break;
case RIGHT_MOVE:
move_To(SMD_RIGHT, FALS);
break;
case STEP_MOVE:
move_To(get_SHD(), TRUTH);
break;
case GENERAT_EGG:
generate_Egg();
break;
case GAME_STOP:
pause_game();
break;
case ESC_OUT:
break;
default:
set_Message_Event(NO_EVENT);
}
}void main()
{
RegistryGraphicMode();
set_GameStat(ON_PALYING);
process_GameStat(get_GameStat());
clear_ScoreTotal();
Init_obj_snake();
Init_obj_egg();
init_SpeedLevel();
randomize();
set_Message_Event(GENERAT_EGG);
getch();
cleardevice();
Draw_mainGraphWindow();
do
{
getMessageEvent();
dispatchMessage_Event();
if(IsWinner() == TRUTH)
{
set_GameStat(WINNER);
break;
}
if(IsGameOver() == TRUTH)
{
set_GameStat(GAMEOVER);
break;
}
}
while(1);
process_GameStat(get_GameStat());
closegraph();
}
[此贴子已经被作者于2007-3-9 17:50:04编辑过]