c语言农场,C语言课程设计《开心农场》源码公开

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

void Print(char c,int num)

{

for (int i = 0;i

printf("%c",c);

}

int GetId(char* name,FILE *fp)

{

long id = 0;

User user;

while (!feof(fp))

{

ReadUserInfo(id,fp,&user);

if ((!strcmp(user.account.name,name)))

return id;

id++;

}

return id;

}

void RefreshUserInfo(User* user)

{

FILE* fp = fopen("data","rb+");

int Id = GetId(user->account.name,fp);

fseek(fp,Id*sizeof(User),0);

long time = GetNowTime();

for (int i = 0;i<9;i++)

{

if (user->land[i].isReclamated)

if (user->land[i].isPlanted && user->land[i].crop.stage!=kuwei)

{

int difftime = GetNowTime() - user->land[i].crop.plantedTime;

int stage = difftime/(user->land[i].crop.changeTime*60);

if (stage>=chengshu) user->land[i].crop.stage = chengshu;

if (stage==kaihua) user->land[i].crop.stage = kaihua;

if (stage==faya) user->land[i].crop.stage = faya;

if (stage==zhongzi) user->land[i].crop.stage = zhongzi;

if (rand()%23==0)

if (user->land[i].crop.stage

for (int j = 0 ; j<3;j++)

user->land[i].crop.state[j] = rand()%2;

}

}

WriteUserInfo(user,fp);

fclose(fp);

}

long GetNowTime()

{

time_t t;

time(&t);

return (long)t/60;

}

bool PlantCrop(Land* land,int crop)

{

if (land->isReclamated==false)

{

return false;

}

land->isPlanted = true;

land->crop.changeTime = stCrop[crop].changeTime;

land->crop.Exp = stCrop[crop].Exp;

land->crop.isPicked = false;

land->crop.isUsedFertilizer = false;

strcpy(land->crop.name,stCrop[crop].name);

land->crop.numberOfFruit = stCrop[crop].numberOfFruit;

land->crop.plantedTime = GetNowTime();

land->crop.stage = zhongzi;

land->crop.state[0] = 0;

land->crop.state[1] = 0;

land->crop.state[2] = 0;

land->crop.id = stCrop[crop].id;

return true;

}

void PrintTitle()

{

Print(' ',28);

printf("开  心  农  场\n");

Print('*',80);

}

void PrintStartMenu()

{

system("cls");

Print('\n',7);

PrintTitle();

Print(' ',28);printf("  H A P P Y     F A R M\n");

Print('\n',4);

Print(' ',32);printf("|1.  登陆游戏|\n");

Print(' ',32);printf("|2.  注册账号|\n");

Print(' ',32);printf("|3.  开发团队|\n");

Print(' ',32);printf("|0.  退出游戏|\n");

Print('\n',5);

printf("请输入菜单命令:");

}

void PrintBack()

{

printf("\n");

Print(' ',68);

printf("输入#号返回\n");

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值