#include <graphics.h>
#include <iostream>
#include <stdlib.h>
#include <mmsystem.h>
#include <conio.h>
#include <stdio.h>
int Day=1;
int Money=10000;
struct field
{
char PlantType[20]; //植物类型
int planted=0; //是否已经种植植物
int water=0; //是否浇水
int grass=0; //是否长草
int PlantSick=0; //是否生病
int weed=1;
int muck=0; //是否施肥
int NeedDay=0; //成熟需要时间
float PlantMature=0.0; //发育程度
int PlantDay=0; //生长日数
};
int goodsrobert=0;
int goodsstraw=0;
int goodstomato=0;
int goodsmelon=0;
int seedsrobert=0;
int seedsstraw=0;
int seedstomato=0;
int seedsmelon=0;
int seedshen=0;
int seedssheep=0;
int seedscow=0;
int seedspig=0;
int seedsegg=0;
int seedsmilk=0;
int seedsfur=0;
int goodshen=0;
int goodssheep=0;
int goodscow=0;
int goodspig=0;
int amountofmuck=0;
int amountofmilk=0;
int amountoffood=0;
int amountofshit=0;
struct field plants[20];
struct pasture
{
char AnimalType[20]; //植物类型
int feed=0; //是否喂食
int AnimalSick=0; //是否长草
float AnimalMature=0.0; //发育程度
int AnimalDay=0; //生长日数
int NeedDay=0;
int AnimalDirty=0; //是否捕获
int x;
int y; //横纵坐标
// struct animal *next; //链表
};
struct Shit
{
int x;
int y;
};
struct Shit shit[20];
struct pasture animal[30];
struct field *Rfile1(struct field *head1)
{
FILE *fr,*fw;
char ch;
int i=0;
fr=fopen("field.txt","r");
if(fr==NULL)
{
fw=fopen("field.txt","w");
fr=fopen("field.txt","r");
}
while((ch=fgetc(fr))!=EOF)
{
fseek(fr,-1,SEEK_CUR);
cleardevice();
if(i==0)
{
fscanf(fr,"%d%d",&Day,&Money);
}
else if(i==1)
{
fscanf(fr,"%d%d%d%d%d%d%d%d%d\n",&seedsrobert,&seedsstraw,&seedstomato,&seedsmelon,&goodsrobert,&goodsstraw,&goodstomato,&goodsmelon,&amountofmuck);
}
else
{
fscanf(fr,"%s%d%d%d%d%d%d%d%d\n",plants[i-1].PlantType,&plants[i-1].planted,&plants[i-1].water,&plants[i-1].grass,&plants[i-1].PlantSick,&plants[i-1].weed,&plants[i-1].muck,&plants[i-1].NeedDay,&plants[i-1].PlantDay);
plants[i-1].PlantMature=plants[i-1].PlantDay*1.0/plants[i-1].NeedDay;
}
i++;
}
return head1;
}
struct animal *Rfile2(struct animal *head2)
{
FILE *fr,*fw;
char ch;
int i=0;
fr=fopen("animal.txt","r");
if(fr==NULL)
{
fw=fopen("animal.txt","w");
fr=fopen("animal.txt","r");
}
while((ch=fgetc(fr))!=EOF)
{
fseek(fr,-1,SEEK_CUR);
cleardevice();
if(i==0)
{
fscanf(fr,"%d%d%d%d%d%d%d%d%d%d\n",&seedshen,&seedssheep,&seedscow,&seedspig,&goodshen,&goodssheep,&goodscow,&goodspig,&amountofmilk,&amountoffood);
}
else
{
fscanf(fr,"%s%d%d%d%d%d\n",animal[i].AnimalType,&animal[i].feed,&animal[i].AnimalSick,&animal[i].AnimalDay,&animal[i].NeedDay,&animal[i].AnimalDirty,&animal[i].AnimalMature);
animal[i].AnimalMature=animal[i].AnimalDay*1.0/animal[i].NeedDay;
}
i++;
}
return head2;
}
struct field *SaveGame1(struct field *head1)
{
FILE *fps;
fps=fopen("field.txt","w");
int i;
int n1=seedsrobert+seedsstraw+seedstomato+seedsmelon;
if(fps==NULL)
{
cleardevice();
xyprintf(400,400,"游戏信息储存失败!任意键继续.....");
}
else
{
cleardevice();
xyprintf(400,400,"游戏信息储存成功!任意键继续.....");
}
getch();
fprintf(fps,"%d %d\n",Day,Money);
fprintf(fps,"%d %d %d %d %d %d %d %d %d\n",seedsrobert,seedsstraw,seedstomato,seedsmelon,goodsrobert,goodsstraw,goodstomato,goodsmelon,amountofmuck);
for(i=1;i<=n1;i++)
{
cleardevice();
plants[i].PlantMature=plants[i].PlantDay*1.0/plants[i].NeedDay;
if(plants[i].planted)
{
fprintf(fps,"%s %d %d %d %d %d %d %d %d\n",plants[i].PlantType,plants[i].planted,plants[i].water,plants[i].grass,plants[i].PlantSick,plants[i].weed,plants[i].muck,plants[i].NeedDay,plants[i].PlantDay);
}
}
return head1;
}
struct animal *SaveGame2(struct animal *head2)
{
FILE *fps;
fps=fopen("animal.txt","w");
int i;
int n2=seedshen+seedssheep+seedscow+seedspig;
if(fps==NULL)
{
cleardevice();
xyprintf(400,400,"游戏信息储存失败!");
}
else
{
cleardevice();
xyprintf(400,400,"游戏信息储存失成功!");
}
fprintf(fps,"%d %d %d %d %d %d %d %d %d %d\n",seedshen,seedssheep,seedscow,seedspig,goodshen,goodssheep,goodscow,goodspig,amountofmilk,amountoffood);
for(i=1;i<=n2;i++)
{
cleardevice();
animal[i].AnimalMature=animal[i].AnimalDay*1.0/animal[i].NeedDay;
fprintf(fps,"%s %d %d %d %d %d\n",animal[i].AnimalType,animal[i].feed,animal[i].AnimalSick,animal[i].AnimalDay,animal[i].NeedDay,animal[i].AnimalDirty);
}
return head2;
}
struct field *InitField(struct field *head1,int i)
{
strcpy(plants[i].PlantType,"nothing");
plants[i].planted=0;
plants[i].water=0;
plants[i].grass=0;
plants[i].PlantSick=0;
plants[i].muck=0;
plants[i].PlantMature=0.0;
plants[i].PlantDay=0;
}
struct field *plant(struct field *head1,int x,int y,int y1,int click)
{
int i=1;
if(((x-600)*(x-600)+(y-310)*(y-310)<=2500))
{
i=1;
}
else if(((x-450)*(x-450)+(y-380)*(y-380)<=2500))
{
i=2;
}
else if(((x-300)*(x-300)+(y-460)*(y-460)<=2500))
{
i=3;
}
else if(((x-760)*(x-760)+(y-390)*(y-390)<=2500))
{
i=4;
}
else if(((x-610)*(x-610)+(y-450)*(y-450)<=2500))
{
i=5;
}
else if(((x-450)*(x-450)+(y-530)*(y-530)<=2500))
{
i=6;
}
else if(((x-920)*(x-920)+(y-460)*(y-460)<=2500))
{
i=7;
}
else if(((x-760)*(x-760)+(y-530)*(y-530)<=2500))
{
i=8;
}
else if(((x-600)*(x-600)+(y-610)*(y-610)<=2500))
{
i=9;
}
else if(((x-1070)*(x-1070)+(y-530)*(y-530)<=2500))
{
i=10;
}
else if(((x-910)*(x-910)+(y-610)*(y-610)<=2500))
{
i=11;
}
else if(((x-750)*(x-750)+(y-680)*(y-680)<=2500))
{
i=12;
}
else if(((x-1210)*(x-1210)+(y-610)*(y-610)<=2500))
{
i=13;
}
else if(((x-1060)*(x-1060)+(y-680)*(y-680)<=2500))
{
i=14;
}
else if(((x-900)*(x-900)+(y-760)*(y-760)<=2500))
{
i=15;
}
else if(((x-1360)*(x-1360)+(y-680)*(y-680)<=2500))
{
i=16;
}
else if(((x-1220)*(x-1220)+(y-760)*(y-760)<=2500))
{
i=17;
}
else if(((x-1070)*(x-1070)+(y-830)*(y-830)<=2500))
{
i=18;
}
else return head1;
setcolor(EGERGB(0x0, 0xFF, 0x0));
setfont(32, 0, "宋体");
setbkmode(TRANSPARENT);
if(plants[i].planted==1)
{
outtextxy(x, y, "该区域已种植");
return head1;
}
else
{
if(click==1)
{
if(y1>=200&&y1<=300)
{
if(seedsrobert>0)
{
strcpy(plants[i].PlantType,"robert");
plants[i].NeedDay=1;
seedsrobert--;
plants[i].planted=1;
plants[i].PlantDay=0;
}
else