赞
踩
c语言贪吃蛇游戏源码.doc
/*运行是按任意键开始,不过呢,反向也算输哟*/include include include include include include include define UP 0 x4800define DOWN 0 x5000define LEFT 0 x4b00define RIGHT 0 x4d00define ESC 0 x011bdefine SPACE 0 x3920define M 25define N 25define blue 1define green 2define red 4define yellow 14define yes 1define no 0struct snake int l,t,r,b;int color;int direction; /*0不动 1 上 2 下 3 左 4 右 蛇头的方向*/qu1M*N;int d4-25,25,-1,1; /*蛇头移动的方向 */int length; /*蛇身长度 */int speed50000000; /*移动的速度 */int head; /*蛇头的位置 */int food;int appear;int key;int direct;int all_food;int tail,mark;int Q1;void draw_map /*地图 */int i,j,n17,v1;int a2525;fori0;i10printf“d“,all_food;elseprintf“0d“,all_food;ifall_food0 setcolorredclass;outtextxy50,450, “ Congratulation and Please any key goto the next “;break;ifappearnodofoodrandom600;whilequ1food.coloryellowqu1food.colorredqu1food.colorgreenfood0;qu1food.colorred;qu1food.direction0;setfillstyle1,red; barqu1food.l, qu1food.t, qu1food.r, qu1food.b; appearyes; star do tailhead; marklength;switchqu1head.direction case 1 headheadd0; direct1;break;case 2 headheadd1;direct2;break;case 3 headheadd2;direct3;break; case 4 headheadd3;direct4;ifqu1head.direction0qu1head.colorgreen /*撞墙或撞自己*/ ifQ1setcolorred;outtextxy450,200, “ Any key to exit “; getch;closegraph; exit0; elseQ1; qu1head.directiondirect;ifheadfood appearno;delayspeed;all_food;length;continue; qu1head.coloryellow;setfillstyle1,yellow; barqu1head.l, qu1head.t, qu1head.r, qu1head.b; setfillstyle1,red; bar qu1tail.l, qu1tail.t, qu1tail.r, qu1tail.b;for;length1;length tailtail-dqu1tail.direction-1;setfillstyle1,blue; bar qu1tail.l, qu1tail.t, qu1tail.r, qu1tail.b; qu1tail.colorblue;qu1tail.direction0;lengthmark;delayspeed; whilekbhit; keybioskey0; ifqu1head.direction1 ifkeyUPQ0;continue; ifqu1head.direction2ifkeyDOWNQ0;continue; ifqu1head.direction3ifkeyLEFTQ0;continue; ifqu1head.direction4ifkeyRIGHTQ0;continue; tailhead; marklength;switchkey case UP headheadd0; direct1;break;case DOWN headheadd1;direct2;break;case LEFT headheadd2;direct3;break; case RIGHT headheadd3;direct4;break;case ESC exit0;case SPACE getch; goto star; /* 暂停*/ifqu1head.direction0qu1head.colorgreen /*撞墙或撞自己*/ ifQ1setcolorred;outtextxy450,200, “ Any key to exit “; getch;closegraph; exit0; elseQ1; qu1head.directiondirect;ifheadfood appearno;delayspeed;all_food;length;continue; qu1head.coloryellow;setfillstyle1,yellow; barqu1head.l, qu1head.t, qu1head.r, qu1head.b; setfillstyle1,red; bar qu1tail.l, qu1tail.t, qu1tail.r, qu1tail.b;for;length1;lengthtailtail-dqu1tail.direction-1;setfillstyle1,blue; bar qu1tail.l, qu1tail.t, qu1tail.r, qu1tail.b; qu1tail.colorblue;qu1tail.direction0;lengthmark;delayspeed; speedspeed-15000;setcolorLIGHTRED;outtextxy200,460,“ You are wining the game .“; getch;closegraph;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。