Hi guys I'm developing a mini game as a project, and I would gladly appreciate if someone could tell me if I'm heading in the right direction.
The aim is to develop a bee-keeping game. First of all I need to have a text file called Inventory which contains the following data:
Total Amount of Bees: 15
Total Amount of Infected Bees: 5
Total Amount of Money: 1500
Total Amount of Honey Jars: 5
Total Amount of Beeswax: 0
Once that is finished I need to write a menu which holds the following choices:
New Game (Set to Default Amounts)
Buy New Bees
Bees Death Process
End Program
Below is the code I have written so far
Code:
#include <stdio.h>
struct Inventory {
int NoOfBees, NoOfInfBees, Money, Honey, Beeswax;
};
int enterChoice(void);
void textFile(FILE *readPtr);
void BuyBees(FILE *fPtr);
void DeadBees(FILE *fPtr);
int main(void)
{
FILE *cfPtr;
int choice;
if ((cfPtr = fopen("Inventory1.txt", "rb+"))==NULL){
printf("File could not be opened.\n");
}
else {
while((choice=enterChoice())!=4){
switch(choice){
case 1:
textFile(cfPtr);
break;
case 2:
BuyBees(cfPtr);
break;
case 3:
DeadBees(cfPtr);
break;
default:
printf("Invalid choice.\n");
break;
}
}
fclose(cfPtr);
}
return 0;
}
/*New Game (Default Amounts, Choice 1)*/
void textFile(FILE*readPtr)
{
FILE *writePtr;
struct clientData client = {0,"","",0.0};
if ((writePtr = fopen("Inventory1.txt","w"))==NULL){
printf("File could not be opened.\n");
}
else {
rewind(readPtr);
fprintf(writePtr,"Total Number of Bees: 15\n", "Total Number of Infected Bees: 5\n", "Total Amount of Money: 1500\n", "Total Amount of Honey Jars: 5\n", "Total Amount of Beeswax: 0\n");
while (!feof(readPtr)) {
fread(&client, sizeof(struct clientData),1,readPtr);
}
}
fclose(writePtr);
}
}
/*Menu*/
int enterChoice( void )
{
int menuChoice;
printf( "\nEnter your choice\n"
"1: New Game (Set to Default Amounts)\n"
"2: Buy Bees.\n"
"3: Bees Death Process.\n"
"4: End Program.\n");
scanf("%d", &menuChoice);
return menuChoice;
}
Any help/tips/critique would be greatly appreciated.