1。比代码长度.一个字符计 2 分
2。必须完成的功能:
1.方向键控制蛇行方向
2.随机布食
3.吃食蛇长节
4.蛇死法 除吃到自己必死,其它不作限制
3。加分(实际应是减分^_^)
每增加一功能减去10分.比如:蛇身着色,食物闪亮等等
[如有不同意见,跟贴]
#include <stdio.h> #include <dos.h> #define G gotoxy #define C printf #define A rand int k,f,g,q,p, m=0,n=1,d=0, e=0,a=2,b=5,c= 5,t=1,M[22] [76]={-1,4};L( ){return a% 2?(f=0,g=a/2?- 1:1):(g=0,f =a/2?1:-1),(!M [m+f][n+g]|| M[m+f][n+g] == 10||M[m+f][n +g]==-1);}K(){ M[m+f][ n+g] ==-1&&E(),M[m+ f][n+g]!=10? F(m,n):(t= 0), M[m+f][n+g]= (a+2)%4+1;}D( ){a-0||((m+f >=0&&L())?(K(),m=m+f):(a=A ()%2?3:1)),a-2 ||((m+f<22&& L())?(K(),m=m+ f):(a=A()%2? 1:3)),a-1||((n +g<76&&L())? (K(),n=n+g):(a =A()%2?0:2)), a- 3||((n+g>=0 &&L())?(K(),n =n+g):(a=A()%2 ?2:0));}F(x,y) {M[x][y]%2?(p= 0,q=M[x][y]/2? 1:-1):(q=0,p=M [x][y]/3?-1:1), M[x+q] [y+p]== -1?(M[x+q][y+p] =0,b=x+q,c=y+p ,M[x][y]=-1):F(x +q,y+p);} R(){ int x,y;x=A()%22,y= A()%76,M[x][y] ==0?(M[x][y]=10,G(y+ 1,x+2),C("X")) :R();}P(){G(c+1,b+2), C(" "),G(n+1,m +2),C("O"),G(e+1,d+2),C("o");}E(){G (10,10), C("The game is over!"), getch(), exit();} main(){R(); while(1){while(bioskey(1)==0)d=m,e=n,D (),P(),t==0&&(R(),t =1),delay(4500);k =bioskey(0)>> 8,k-75||(a=3),k-77||(a=1),k-72||(a=0),k-80||(a=2);}}
/*union REGS regs; regs.h.ah=1; regs.h.ch=13; regs.h.cl=0; int86(0x10,®s,®s); */
[此贴子已经被作者于2005-1-25 9:23:38编辑过]