Code:
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#define CARS_ARRAY_SIZE 4
struct cars
{
char name[20];
char make[20];
int car_number;
char color[20];
int distance;
int RCinfo[4];
};
//prototypes
int car_pic(struct cars *carpointer, int size);
int Modify(struct cars *modpointer, int size, int CarSelect);
int readCarsTXT (struct cars *readpointer, int size);
int manual (struct cars *manualpointer, int size);
int automatic (struct cars *automaticpointer, int size);
int movement (struct cars *movementpointer, int size);
int main (void)
{
//declaring variables in array
int i=0;
int lower=0;
int upper=10;
int count=1;
int automaticmovement;
int manualmovement;
int AutoOrManual;
int automatic;
int CarType;
int number;
int CarColor;
char DriverName;
int manualrace;
int v1;
int v2;
int modifyorstart;
int automatic2;
int ExitFlag=0;
//opening file for arrayos
FILE *fPointerCars;---------
srand(time(NULL));//
//Print name and explain this is a racing game
printf("RoseEllen Hoke\n This is a race car game a text base game to race 4 cars across the screen and determine the first second and third place. \n A text file (car.txt) with the name of the driver, type of the race car, car number, and the color of the car is given to you.");
do
{
struct cars AutoManual[CARS_ARRAY_SIZE];
printf("enter 1 if you want race against another user or \n enter 2 if you want to race against 4 cars automatically or \n enter 3 to exit");
scanf("%d",&AutoOrManual);
switch(AutoOrManual)
{
case 1:
// i do not know how to get it to move to the next thing
printf("You have selected Manual");
int manualrace= manual();
//CAll Function that runs that type of race
break;
case 2:
printf("You have selected Automatic");
int automaticrace= automatic();
break;
case 3:
printf("EXIT");
ExitFlag=1;
default:
printf("please enter a valid number");
break;
}
}while(ExitFlag==0);
return 0;
}
int automatic ()
{
struct cars AutoCars[4];
struct cars ModifyCars[6];
struct cars StartCars[0];
int CarSelection=0;
int CarModify=0;
int CarStart=0
readCarsTXT()
readCarsTXT(AutoCars, CARS_ARRAY_SIZE);
CarSelection=car_pic(AutoCars,CARS_ARRAY_SIZE);
readCarsTXT(ModifyCars, CARS_ARRAY_SIZE);
readCarsTXT(StartCars, CARS_ARRAY_SIZE);
CarStart=
printf("press 1 if you would like to modify your car or press 2 if you would like to start the game");
switch (modifyorstart)
{
case 1:
CarModify=Modify(ModifyCars,CARS_ARRAY_SIZE);
break;
case 2:
//SOMETHING TO START THE GAME
break;
default:
printf("please enter a valid number");
break;
}
// Ask here whether they want to mod car or start
//YOu can run the race in this function or create a new one
}
//Create random number generator for the number of moves
//Create random number generator for the which vehile to move.
//Create a fuctnio the writes to the txt file
int manual()
{
struct cars ManualRace[2];
int playerone=0;
int playertwo=0;
readCarsTXT()
readCarsTXT(ManualRace, CARS_ARRAY_SIZE);
playerone=car_pic(ManualRace,CARS_ARRAY_SIZE);
playertwo=car_pic((ManualRace,CARS_ARRAY_SIZE);
}
int Modify(struct cars *modpointer, int size, int CarSelect)
{
int i = CarSelect;
int CarType1;
int DriverName;
int numberA;
int CarColor1;
printf("Please select your modification\n enter 1 for name\n enter 2 for a make\n enter 3 for a number\n enter 4 for a color");
scanf("%d", &CarType1);
switch(CarType1)
{
case 1:
printf("\n please enter driver name");
scanf("%s", &DriverName);
strcpy((modpointer+i)->name, DriverName);
break;
case 2:
printf("please enter the type of car you want");
scanf("s", &CarType1);
strcpy ((modpointer+i)->make, CarType1);
break;
case 3:
printf("\nplease enter the number you want");
scanf("%d", &numberA);
strcpy((modpointer+i)->car_number, numberA);
break;
case 4:
printf("please enter the color you want your car");
scanf("%s", &CarColor1);
strcpy((modpointer+i)->color, CarColor1);
break;
default:
printf("Wrong INput");
}
}
//Chanfe this main to a function that just reads the cars. txt file
//Pass this function a structure
int readCarsTXT(struct cars *readpointer, int size)
{
// declaring variables
int i=0;
FILE *carFilePointer;
carFilePointer = fopen("car.txt", "r");
// check existence of the file
if (carFilePointer == NULL)
{
printf("file does not exist");
}
else
{
// read the file and assign data to array of structures
for (i=0; i < CARS_ARRAY_SIZE; i++)
{
fscanf(carFilePointer,"%s %s %d %s",readpointer-> name, readpointer-> make, &readpointer->car_number, readpointer-> color);
// pointer arithmetic. point to the next array element
readpointer++;
}
// call car_pic function
}
close(carFilePointer);
}
// function definition
int car_pic(struct cars *carpointer, int size)
{
int i=0, chosen_car=0;
// display cars
for (i=0; i < size; i++)
{
printf("%d- %-12s %-12s %-3d %-12s\n", i+1, carpointer-> name, carpointer-> make, carpointer->car_number, carpointer-> color);
// pointer arithmetic. point to the next array element
carpointer++;
}
printf("\nEnter the line number for your car ");
scanf("%d", &chosen_car);
// assign array index to chosen_car and return
chosen_car --;
return chosen_car;
}