level 1
小弟我正式进入“暑假”状态!培训机构居然有暑假?俺们这里第三学期选java方向的人太少了。最起码要等一个月,等后面的班级,第二阶段上完才能凑够人啊!!!java不好么?咋这么少人学呢?
2008年07月24日 13点07分
1
level 1
这是我第一学期写的vc++ 6.0 编译不知道为啥,想发出来交流下虽然不是java,不过我也没别的地方发了~!~!~!~!##include
#include
#include
#include
#include
#define UP 'w'
#define DOWN 's'#
define LEFT 'a'#define RIGHT 'd'COORD head;//蛇头坐标,不显示COORD food;COORD mid={20,10},score={14,8};HANDLE hndl=GetStdHandle(STD_OUTPUT_HANDLE);COORD crawl;int size;int ensize=1;//size增加量int delay=140;//延时int sizeOfTheYard=20;bool magicWall=false;void move();void control();void yard();void randomFood();void operation();int furtherOperation(char *,int ,int );bool menu();bool judge();void grow();struct Snake{struct Snake *next;COORD coordinate;}*pEnd; void main(){while(true){if(menu())return;srand(time(NULL));crawl.X=2;crawl.Y=0;size=3;pEnd=(struct Snake*)malloc(sizeof(struct Snake));pEnd->next=pEnd;pEnd->coordinate=mid;for(int i=1;i
next;free(pEnd);pEnd=temp;}pEnd=NULL;SetConsoleCursorPosition(hndl,mid);printf("GAME OVER!!!");system("pause");}}void move(){while(true){SetConsoleCursorPosition(hndl,head);printf("*");if(food.X==head.X&&food.Y==head.Y){size+=ensize;for(int i=0;i
coordinate=head;randomFood();}else{SetConsoleCursorPosition(hndl,pEnd->coordinate);printf(" ");pEnd->coordinate=head;}Sleep(delay);control();pEnd=pEnd->next;head.X+=crawl.X;head.Y+=crawl.Y;if(judge())return;}}void control(){if(kbhit())switch(getch()){case UP:case UP-32:crawl.X=0;crawl.Y=crawl.Y==1?1:-1;break;case LEFT:case LEFT-32:crawl.X=crawl.X==2?2:-2;crawl.Y=0;break;case DOWN:case DOWN-32:crawl.X=0;crawl.Y=crawl.Y==-1?-1:1;break;case RIGHT:case RIGHT-32:crawl.X=crawl.X==-2?-2:2;crawl.Y=0;break;}}void yard(){system("cls");printf("\n%6sCrawling speed\t%d","",(440-delay)/50);printf("\n%6sMagic wall\t%s\n","",magicWall==true?"enabled":"disabled");printf("%6sX","");for(int i=0;i<=sizeOfTheYard;i++)printf(" X");for(i=0;i
coordinate.X && food.Y==p->coordinate.Y){randomFood();return;}p=p->next;}while(p!=pEnd);SetConsoleCursorPosition(hndl,score);printf("%d",size);SetConsoleCursorPosition(hndl,food);printf("\3");}bool judge(){if(magicWall){if(head.X==6)head.X=2*(sizeOfTheYard
+3
);else if(head.X==2*(sizeOfTheYard+4))head.X=8;else if(head.Y==3)head.Y=sizeOfTheYard+3;else if(head.Y==sizeOfTheYard+4)head.Y=4;}else if(head.X==6||head.X==2*(sizeOfTheYard+4)||head.Y==3||head.Y==sizeOfTheYard+4)return true;struct Snake *p=pEnd;for(int i=0;i
next,i++)if(head.X==p->coordinate.X && head.Y==p->coordinate.Y)return true;return false;}void operation(){while(true){system("cls");printf("\n\n\n");printf("\t\tS.Size of the yard\t%d\n",sizeOfTheYard);printf("\t\tC.Crawling speed\t%d\n",(440-delay)/50);printf("\t\tG.Growing speed\t\t%d\n",ensize);printf("\t\tM.Magic wall\t\t%s\n\t\tQ.Quit",magicWall==true?"enabled":"disabled");get:switch(getch()){case 's':case 'S':sizeOfTheYard=furtherOperation("size of the yard",15,30);break;case 'c':case 'C':delay=440-50*furtherOperation("crawling speed",1,8);break;case 'g':case 'G':ensize=furtherOperation("growing speed",1,5);break;case 'm':case 'M':magicWall=magicWall==true?false:true;break;case 'q':case 'Q':return;default:goto get;}}}int furtherOperation(char *p,int min,int max){int temp;do{system("cls");printf("\n\n\n\t\tPlease input the %s(%d~%d):",p,min,max);printf("\n\t\t");fflush(stdin);scanf(" %d",&temp);}while(temp
max);return temp;}bool menu(){while(true){system("cls");printf("\n\t\t SNAKE\n\n\t\tS.Start\n\t\tO.Operation\n\t\tQ.Quit");get:switch(getch()){case 'o':case 'O':operation();break;case 'q':case 'Q':return true;case 's':case 'S':return false;default:goto get;}}}void grow(){struct Snake *temp;temp=pEnd->next;pEnd->next=(struct Snake*)malloc(sizeof(struct Snake));pEnd->next->next=temp;pEnd->next->coordinate=pEnd->coordinate;}
2008年07月24日 13点07分
3