- UID
- 70863
注册时间2010-12-2
阅读权限30
最后登录1970-1-1
龙战于野
TA的每日心情 | 开心 2015-12-28 01:47 |
---|
签到天数: 3 天 [LV.2]偶尔看看I
|
楼主 |
发表于 2010-12-30 12:50:16
|
显示全部楼层
早上起来趁着头脑清醒,修改了下代码.
取消了中间的虚线,随时按反方向键都可以缩短蛇身.
然后就是蛇头可以改变方向了,
但是只能完全伸直后才能转弯.
虽然已经是尽我所能的去想了,
但是感觉并不是正确的逻辑.
因为仅仅是这一点就写了好多代码.
如果完整的贪食蛇程序,完全按这种方式写下去.
最少也要500+行代码吧....
可能是现在所能利用的东西太少了?
因为是修改代码,就是为了添加功能而写代码.
感觉很不爽.希望自己早日能够用逻辑构思出一个整体的东西出来.
修改后源码:- main()
- {
- char c[5]={0};
- int x = 40;
- int y = 13;
- int i=3,j = 0;
- char a = 0,b = 0;
- while(*c != 0x30)
- {
- clrscr();
- printf("Please enter '0' to quit. a = %d;b = %d x = %d;y = %d",a,b,x,y);
- gotoxy(70,1);
- printf("By: LShang");
- while(i <= 80)
- {
- if(i<25)
- {
- gotoxy(i-1,2);
- printf("#");
- gotoxy(i-1,25);
- printf("#");
- gotoxy(1,i);
- printf("#");
- gotoxy(80,i);
- printf("#");
- }
- else
- {
- gotoxy(i-1,2);
- printf("#");
- gotoxy(i-1,25);
- printf("#");
- }
- i++;
- }
- if(*c == 0x1e)
- {
- if(a == 0)
- {
- gotoxy(x,y);
- for(i=0;i<5 && i<=abs(b);i++)
- {
- *(c+i+1) = *(c+i);
- *(c+i) = 0xdb;
- gotoxy(x,y+i);
- printf("%c",*(c+i));
- }
- gotoxy(x,y);
- printf("%c",*(c+i));
- gotoxy(x,y);
- }
- else
- {
- gotoxy(x,y);
- printf("%c",*c);
- if(a>0)
- {
- for(j=1;j<=abs(b);j++)
- {
- gotoxy(x,y+j);
- printf("%c",0xdb);
- }
- for(j = a-1;j>0;j--)
- {
- printf("%c",0xdb);
- }
- a--;
- gotoxy(x,y);
- }else if(a<0)
- {
- for(j=1;j<=abs(b);j++)
- {
- gotoxy(x,y+j);
- printf("%c",0xdb);
- }
- for(j = a+1;j<0;j++)
- {
- gotoxy(x+j,y+b);
- printf("%c",0xdb);
- }
- a++;
- gotoxy(x,y);
- }
- }
- }else if(*c == 0x1f)
- {
- if(a == 0)
- {
- gotoxy(x,y);
- for(i=0;i<5 && i<=abs(b);i++)
- {
- *(c+i+1) = *(c+i);
- *(c+i) = 0xdb;
- gotoxy(x,y-i);
- printf("%c",*(c+i));
- }
- gotoxy(x,y);
- printf("%c",*(c+i));
- gotoxy(x,y);
- }else
- {
- gotoxy(x,y);
- printf("%c",*c);
- if(a>0)
- {
- for(j=1;j<=abs(b);j++)
- {
- gotoxy(x,y-j);
- printf("%c",0xdb);
- }
- for(j = a-1;j>0;j--)
- {
- printf("%c",0xdb);
- }
- a--;
- gotoxy(x,y);
- }else if(a<0)
- {
- for(j=1;j<=abs(b);j++)
- {
- gotoxy(x,y-j);
- printf("%c",0xdb);
- }
- for(j = a+1;j<0;j++)
- {
- gotoxy(x+j,y+b);
- printf("%c",0xdb);
- }
- a++;
- gotoxy(x,y);
-
- }
- }
- }else if(*c == 0x11)
- {
- if(b == 0)
- {
- gotoxy(x,y);
- for(i=0;i<5 && i<=abs(a);i++)
- {
- *(c+i+1) = *(c+i);
- *(c+i) = 0xdb;
- gotoxy(x+i,y);
- printf("%c",*(c+i));
- }
- gotoxy(x,y);
- printf("%c",*(c+i));
- gotoxy(x,y);
- }else
- {
- gotoxy(x,y);
- printf("%c",*c);
- if(b>0)
- {
- for(j = 1;j<=abs(a);j++)
- {
- gotoxy(x+j,y);
- printf("%c",0xdb);
- }
- for(j=b-1;j>0;j--)
- {
- gotoxy(x+a,y+j);
- printf("%c",0xdb);
- }
- b--;
- gotoxy(x,y);
- }else if(b<0)
- {
- for(j = 1;j<=abs(a);j++)
- {
- gotoxy(x+j,y);
- printf("%c",0xdb);
- }
- for(j=b+1;j<0;j++)
- {
- gotoxy(x+a,y+j);
- printf("%c",0xdb);
- }
- b++;
- gotoxy(x,y);
- }
- }
- }else if(*c == 0x10)
- {
- if(b == 0)
- {
- gotoxy(x,y);
- for(i=0;i<5 && i<=abs(a);i++)
- {
- *(c+i+1) = *(c+i);
- *(c+i) = 0xdb;
- gotoxy(x-i,y);
- printf("%c",*(c+i));
- }
- gotoxy(x,y);
- printf("%c",*(c+i));
- gotoxy(x,y);
- }else
- {
- gotoxy(x,y);
- printf("%c",*c);
- if(b>0)
- {
- for(j = 1;j<=abs(a);j++)
- {
- gotoxy(x-j,y);
- printf("%c",0xdb);
- }
- for(j=b-1;j>0;j--)
- {
- gotoxy(x+a,y+j);
- printf("%c",0xdb);
- }
- b--;
- gotoxy(x,y);
- }else if(b<0)
- {
- for(j = 1;j<=abs(a);j++)
- {
- gotoxy(x-j,y);
- printf("%c",0xdb);
- }
- for(j=b+1;j<0;j++)
- {
- gotoxy(x+a,y+j);
- printf("%c",0xdb);
- }
- b++;
- gotoxy(x,y);
- }
- }
- }
- i = 3;
- *c = getch();
- if(*c == 0x48)
- {
- y = (y==3)?24:--y;
- *c = 0x1e;
- if(b<4)
- {
- b++;
- }
- }else if(*c == 0x50)
- {
- y = (y == 24)?3:++y;
- *c = 0x1f;
- if(b>-4)
- {
- b--;
- }
- }else if(*c == 0x4b)
- {
- x = (x == 2)?79:--x;
- *c = 0x11;
- if(a<4)
- {
- a++;
- }
- }else if(*c == 0x4d)
- {
- x = (x == 79)?2:++x;
- *c = 0x10;
- if(a>-4)
- {
- a--;
- }
- }
- }
- clrscr();
- }
复制代码 截图:
|
评分
-
查看全部评分
|