📄 game.lst
字号:
212 2 }
213 1 if((point[sp_end].x==point[sp_end+1].x)&&(point[sp_end].y==point[sp_end+1].y)){
214 2 sp_end++; //delete a cells lline start move up "1"
215 2 if(sp_end>=255)sp_end=0;
216 2 spoint--; //line long dec "1"
217 2 if(sp_end==sp_start){
218 3 sp_end=1;
219 3 sp_start=0;
220 3 }
221 2 }
222 1 }
223 //----------------------walk ago orient---------------------------------------
224 void walk_old(void){ //the snake is walk front and don't creat cells
225 1 byte tempx,tempx1,tempy,tempy1;
226 1 byte endx,endx1,endy,endy1;
227 1 endx =point[sp_start].x; //move snake head
228 1 endx1=point[sp_start-1].x;
229 1 endy =point[sp_start].y;
230 1 endy1=point[sp_start-1].y;
231 1 if(endx==endx1){ // |
232 2 if(endy>endy1){ // | endx1
233 3 endy++; // V endx
234 3 point[sp_start].y=endy;
235 3 }
236 2 else{ // ^
237 3 endy--; // |
238 3 point[sp_start].y=endy;
239 3 }
240 2 }
241 1 else{
C51 COMPILER V7.02b GAME 04/20/2004 10:37:00 PAGE 5
242 2 if(endx>endx1){ //--->
243 3 endx++;
244 3 point[sp_start].x=endx;
245 3 }
246 2 else{ //<---
247 3 endx--;
248 3 point[sp_start].x=endx;
249 3 }
250 2 }
251 1
252 1
253 1 tempx =point[sp_end].x;
254 1 tempx1=point[sp_end+1].x;
255 1 tempy =point[sp_end].y;
256 1 tempy1=point[sp_end+1].y;
257 1 if(tempx==tempx1){
258 2 clear_big_point(tempx,point[sp_end].y); // "|"
259 2 if(tempy>tempy1){ //move the snake tail
260 3 tempy--; // ^
261 3 point[sp_end].y=tempy;// |
262 3 }
263 2 else{
264 3 tempy++; // |
265 3 point[sp_end].y=tempy;// V
266 3 }
267 2 }
268 1 else{
269 2 clear_big_point(tempx,point[sp_end].y); // "--"
270 2 if(tempx >tempx1){ // move the snake tail
271 3 tempx--; // <----
272 3 point[sp_end].x=tempx;
273 3 }
274 2 else{
275 3 tempx++; // ---->
276 3 point[sp_end].x=tempx;
277 3 }
278 2 }
279 1 if((point[sp_end].x==point[sp_end+1].x)&&(point[sp_end].y==point[sp_end+1].y)){
280 2 sp_end++; //delete a cells lline start move up "1"
281 2 if(sp_end>=255)sp_end=0;
282 2 spoint--; //line long dec "1"
283 2 if(sp_end==sp_start){
284 3 sp_end=1;
285 3 sp_start=0;
286 3 }
287 2 }
288 1 }
289 //----------------------the game model-----------------------------------------
290 void game(){
291 1 byte i,key_in;//i is y length;don,t bigger than 15
292 1 game_on=1;
293 1 orient=0;
294 1 write_square(00,17,126,63,0);
295 1 for(i=0;i<6;i++)
296 1 put_char((16+16*i),0,0,i);
297 1 sp_end=sp_start=spoint=0;
298 1
299 1 point[0].x=1;
300 1 point[0].y=1; // snake tail
301 1
302 1 point[1].x=1;
303 1 point[1].y=5;
C51 COMPILER V7.02b GAME 04/20/2004 10:37:00 PAGE 6
304 1
305 1 point[2].x=17;
306 1 point[2].y=5;
307 1
308 1 point[3].x=17;
309 1 point[3].y=3;
310 1
311 1 point[4].x=25;
312 1 point[4].y=3;
313 1 point[5].x=25;
314 1 point[5].y=8;//sp_end is the snake head pointer
315 1
316 1 last_key=4; //the snake walk to down orient (key record)
317 1 sp_start=5;
318 1 spoint=5; //initialize snake body
319 1 write_body();
320 1 display();
321 1 while(game_on){
322 2 key_in=key();
323 2 orient=key_in;
324 2 if(move_flag){
325 3 move_flag=0;
326 3 switch (orient){
327 4 case 0:
328 4 walk_old();
329 4 break;
330 4 case 1: //creat a new cell for up at now orient
331 4 if((last_key==2)||(last_key==3)){ //input ->1 up ;
332 5 point[sp_start+1].x=point[sp_start].x;
333 5 point[sp_start+1].y=point[sp_start].y -1;
334 5 if(spoint++>=0xff){//last_key must be left(2) or right(3)
335 6 spoint=0; //check line
336 6 }
337 5 sp_start++;
338 5 if(sp_start==sp_end){
339 6 sp_start=1; //line long and end point add "1"
340 6 sp_end=0;
341 6 }
342 5 last_key=1; //change the last key state
343 5 walk_tail();//move snake tail only
344 5 }
345 4 else
346 4 walk_old(); //move snake head and tail
347 4 break;
348 4 case 2: //creat a new cell for left at now orient
349 4 if((last_key==1)||(last_key==4)){ //input ->2 left ;
350 5 point[sp_start+1].x=point[sp_start].x -1;
351 5 point[sp_start+1].y=point[sp_start].y;
352 5 if(spoint++>=0xff){//last_key must be up(1) or down(4)
353 6 spoint=0; //check line
354 6 }
355 5 sp_start++;
356 5 if(sp_start==sp_end){
357 6 sp_start=1; //line long and end point add "1"
358 6 sp_end=0;
359 6 }
360 5 last_key=2; //change the last key state
361 5 walk_tail();
362 5 }
363 4 else
364 4 walk_old();
365 4 break;
C51 COMPILER V7.02b GAME 04/20/2004 10:37:00 PAGE 7
366 4 case 3: //creat a new cell for right at now orient
367 4 if((last_key==1)||(last_key==4)){ //input ->3 right ;
368 5 point[sp_start+1].x=point[sp_start].x +1;
369 5 point[sp_start+1].y=point[sp_start].y;
370 5 if(spoint++>=0xff){//last_key must be up(1) or down(4)
371 6 spoint=0; //check line
372 6 }
373 5 sp_start++;
374 5 if(sp_start==sp_end){
375 6 sp_start=1; //line long and end point add "1"
376 6 sp_end=0;
377 6 }
378 5 last_key=3; //change the last key state
379 5 walk_tail();
380 5 }
381 4 else
382 4 walk_old();
383 4 break;
384 4 case 4: //creat a new cell for down at now orient
385 4 if((last_key==2)||(last_key==3)){ //input ->4 down ;
386 5 point[sp_start+1].x=point[sp_start].x;
387 5 point[sp_start+1].y=point[sp_start].y +1;
388 5 if(spoint++>=0xff){//last_key must be left(2) or right(3)
389 6 spoint=0; //check line
390 6 }
391 5 sp_start++;
392 5 if(sp_start==sp_end){
393 6 sp_start=1; //line long and end point add "1"
394 6 sp_end=0;
395 6 }
396 5 last_key=1; //change the last key state
397 5 walk_tail();
398 5 }
399 4 else
400 4 walk_old();
401 4 break;
402 4 default:
403 4 walk_old();
404 4 break;
405 4 }
406 3 write_body();
407 3 display();
408 3 if(check_point()){
409 4 for(i=0;i<4;i++)
410 4 put_char((32+16*i),32,0,i+6); //print game over
411 4 return;
412 4 }
413 3 }
414 2 }
415 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2781 ----
CONSTANT SIZE = 350 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 5 25
IDATA SIZE = ---- 4
BIT SIZE = 3 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -