求帮忙,在线等,急!!!(显示不出来)
ege吧
全部回复
仅看楼主
level 1
三月于冬 楼主
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<malloc.h>
#include <time.h>
int food[2];
struct snake
{
int x;
int y;
int life;
struct snake *next;
};
struct snake *createlist(struct snake* head)
{
struct snake* q,*p;
q=(struct snake*)malloc(sizeof(struct snake));
q=head;
q->x=16;q->y=16;q->life=1;
p=(struct snake*)malloc(sizeof(struct snake));
q->next=p;
p->x=16;p->y=15;p->life=1;
p->next=NULL;
return head;
}
void drawdot(int x,int y)
{
setfillcolor(BLUE);
x=(x-1)*20;
y=(y-1)*20;
bar(x,y,x+20,y+20);
}
void drawsnake(struct snake* head)
{
struct snake* p;
p=head;
while(p!=NULL)
{
drawdot(p->x,p->y);
p=p->next;
}
}
int main()
{
initgraph(960,640);
struct snake* head;
createlist(head);
drawsnake(head);
getch();
closegraph();
return 0;
}
2017年07月05日 02点07分 1
level 5
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<malloc.h>
#include <time.h>
int food[2];//食物
struct snake //蛇
{
int x;//一节蛇坐标
int y;
int life;//这个有什么用?
struct snake *next;//指向下一节
};
struct snake *createlist(/*struct snake* head */)//创建二节蛇
{
struct snake* q,*p;
//第一节,头
q=(struct snake*)malloc(sizeof(struct snake));
//q=head;
q->x=16;q->y=16;q->life=1;
//第二节
p=(struct snake*)malloc(sizeof(struct snake));
q->next=p;
p->x=16;p->y=15;p->life=1;
p->next=NULL;//蛇尾
return q;//返回蛇头
}
void drawdot(int x,int y)//绘制蛇的一节
{
setfillcolor(BLUE);
x=(x-1)*20;
y=(y-1)*20;
bar(x,y,x+20,y+20);
}
void drawsnake(struct snake* head)//绘制蛇
{
struct snake* p;
p=head;
while(p!=NULL)
{
drawdot(p->x,p->y);
p=p->next;
}
}
int main()
{
initgraph(960,640);
struct snake* head;//定义贪食蛇
head=createlist();//初始化两节蛇
drawsnake(head);//显示
//游戏循环
getch();
closegraph();
return 0;
}
2017年09月15日 12点09分 2
1