最近在写的C语言大作业,我设计的是大鱼吃小鱼,借鉴了论坛上的一些代码。
以下是其中的一部分。这里的fish*produce()不太明白是什么用法,请大神赐教QAQ
typedef struct node {
int x;
int y;
int sudu;
int fenshu;
int mode;
struct node* next;
}fish;
fish* produce()
{
srand((unsigned)time(NULL));//防止随机数每次重复,使用系统时间来初始化
int x = 1;
fish* p, * r = NULL, * h;
h = NULL;
while (x <= 5)
{
p = (fish*)malloc(sizeof(fish));
p->x = -50;
p->y = rand() % (360 - 0) + 0;
p->sudu = rand() % (40 - 10) + 10;
p->fenshu = rand() % (50 - 5) + 5;
p->mode = rand() % 4;
p->next = NULL;
if (h == NULL)
{
h = p;
r = p;
}
else
{
r->next = p;
r = p;
}
x++;
}
return h;
}