文档介绍:1. //这个是背景的单元格数据结构
2. const length = 40;
3. const width = 20;
4. struct square{
5. bool blocked; //是否有障碍物
6. boy);
72. }else{
73. n++;
74. }
75. //createWall(pos_x,pos_y);
76. }
77.}
78.//创建食物
createFood(int x,int y){
80. createBlock(x+10,y+10,BG_BLUE);
81. bg[x][y].food= true;
82.}
83.
84.//随机创建食物
rand_createFood(void){
86. srand((unsigned)time(NULL));87. int n = 1;//rand() % 20;
88. int pos_x = 0;
89. int pos_y = 0;
90. int i = 0;
91. for(i = 0; i < n; i++){
92. pos_x = rand() % length;
93. pos_y = rand() % (width-1);
94. if(checkExisted(pos_x,pos_y)== true){ //防止在障碍物
上生成食物
95. createFood(pos_x,pos_y);
96. }else{
97. n++;
98. }
99. }
100. }
101. //物体信息,这是蛇的单元模型
102. const objLen = 5;
103. struct obj{
104. int x;
105. int y;
106. }snake[objLen];
107.
108. //创建蛇
109. LinList<structobj> newSnake;
110. void createSnake(void){
111. int i = 0;
112. for(i = 0; i < objLen; i++){
113. snake[i].x = i;
114. snake[i].y = 0;
115. (snake[i],i);
116. }
117. }
118.
119. //绘制蛇
120. void drawSnake(int len){
121. int i = 0;
122. struct obj t;
123. for(i = 0; i < len; i++){
124. t = (i);
125.