txfxiaofeng
txfxiaofeng
关注数: 0
粉丝数: 3
发帖数: 127
关注贴吧数: 2
链表排序 #include #include #define N 20#define NULL 0struct{ char a[]; struct * next;}struct * f(struct * head){ struct *p0,*p1,*p2,*min; for(p1=head;p1->next!=NULL;p0=p1,p1=p1->next) { min=p1; for(p2=p1->next;p2->next!=NULL;p2=p2->next) if(strcmp(p1,p2)>0) min=p2; if(p1=head) { head=p2; p1->next=p2->next; p2->next=p1; } else { p1->next=p2->next; p2->next=p1; p0->next=p2; } } return(head);}
贪吃蛇的问题! /*编译器:TC 2.0*/#include #include #include #include #define N 200 #define LEFT 0x4b00 #define RIGHT 0x4d00 #define DOWN 0x5000 #define UP 0x4800 #define ESC 0x011b int i,key; int score=0;/*得分*/ int gamespeed=5000;/*游戏速度*/ struct Food { int x;/*食物的横坐标*/ int y;/*食物的纵坐标*/ int yes;/*判断是否要出现食物的变量*/ }food; /*食物的结构体*/ struct Snake { int x[N]; int y[N]; int node;/*蛇的节数*/ int direction;/*蛇移动方向*/ int life;/* 蛇的生命,1活着,0死亡*/ }snake; void Init(void);/*图形驱动*/ void Close(void);/*图形结束*/ void DrawK(void);/*开始画面*/ void GamePlay(void);/*玩游戏具体过程*/ void GameOver(void);/*结束游戏*/ void PrintScore(void);/*输出成绩*/ /*主函数*/ void main(void) { Init();/*图形驱动*/ DrawK();/*开始画面*/ GamePlay();/*具体游戏过程*/ Close();/*图形结束*/ } /*图形驱动*/ void Init(void) { int gdriver=DETECT,gmode; /*自动检测显示器*//*registerbgidriver(EGAVGA_DRIVER); 建立独立图形运行程序*/initgraph(&gdriver,&gmode,"c:\\tc"); /*图形初始化*/cleardevice(); /*清除屏幕图形*/} /*开始画面,左上角坐标为(50,40),右下角坐标为(610,460)的围墙*/ void DrawK(void) { setbkcolor(10); /*设置背景色(淡绿)*/setcolor(11); /*前景色(淡青)*/setlinestyle(0,0,3); /*设置线型(实线,三点宽)*/ rectangle(50,40,610,460); /*上边*/ rectangle(59,49,600,450);/*下边*/ floodfill(55, 45, 11);} /*玩游戏具体过程*/ void GamePlay(void) { struct Food * f=&food;struct Snake * s=&snake;randomize(); /*随机数发生器*/ f->yes=0; /*0表示需要出现新食物,1表示已经存在食物*/ s->life=1; /*活着*/ s->direction=1; /*方向往右*/ s->x[0]=100;s->y[0]=100; /*蛇头*/ s->x[1]=110;s->y[1]=100; s->x[2]=120;s->y[2]=100;s->node=3; /*节数*/ PrintScore(); /*输出得分*/ while(1) /*可以重复玩游戏,压ESC键结束*/ { while(!kbhit()) /*在没有按键的情况下,蛇自己移动身体*/ { if(f->yes==0)/*需要出现新食物*/ { f->x=rand()%400+60; f->y=rand()%350+60; while(f->x%10!=0)/*食物随机出现后必须让食物能够在整格内,这样才可以让蛇吃到*/ f->x++; while(f->y%10!=0)f->y++; f->yes=1;/*画面上有食物了*/ } if(f->yes==1)/*画面上有食物了就要显示*/ { setcolor(9); /*兰色食物*/rectangle(f->x,f->y,f->x+10,f->y-10); /*画矩形框表示食物*/floodfill(f->x+5, f->y-5, 9);} for(i=s->node-1;i>0;i--)/*蛇的每个环节往前移动,也就是贪吃蛇的关键算法*/ { s->x[i]=s->x[i-1]; s->y[i]=s->y[i-1]; } /*1,2,3,4表示右,左,上,下四个方向,通过这个判断来移动蛇头*/ switch(snake.direction) { case 1: s->x[0]+=10;break; case 2: s->x[0]-=10;break; case 3: s->y[0]-=10;break; case 4: s->y[0]+=10;break; } for(i=3;i .node;i++)/*从蛇的第四节开始判断是否撞到自己了,因为蛇头为两节, 第三节不可能拐过来*/
七七四十九 编程实现 1 2 3 4 5 6 724 25 26 27 28 29 823 40 41 42 43 30 922 39 48 49 44 31 1021 38 47 46 45 32 1120 37 36 35 34 33 1219 18 17 16 15 14 13不要直接用输出函数~~
难道就没有高手愿意帮我吗? http://post.baidu.com/f?kz=205711261
算式还原! 乘式还原 有乘法运算如下 ○○○ × ○○ —————— ○○○○ ○○○○ —————— ○○○○○ 18个○位置上全部是素数(1,3,5或7),请还原这算式
哪位高手告诉我贪吃蛇的简单算法啊! 要算法不要代码谢谢
1
下一页