get_car() works
This commit is contained in:
parent
d1187fc079
commit
d1bf7c854e
1 changed files with 21 additions and 2 deletions
23
car.c
23
car.c
|
|
@ -18,8 +18,23 @@ struct CarData {
|
|||
};
|
||||
|
||||
Car get_car(CarType carType) {
|
||||
Car car = {carType, RED, 0.0, 0.0, 0};
|
||||
return car;
|
||||
static struct CarData car_park[] = {
|
||||
{AIXAM, RED, 16.0, 0.0, -1},
|
||||
{FIAT_MULTIPLA, GREEN, 65.0, 0.0, -1},
|
||||
{FIAT_MULTIPLA, BLUE, 65.0, 0.0, -1},
|
||||
{FIAT_MULTIPLA, ORANGE, 65.0, 0.0, -1},
|
||||
{JEEP, SILVER, 80.0, 0.0, -1},
|
||||
{JEEP, BLACK, 80.0, 0.0, -1}
|
||||
};
|
||||
int length = sizeof(car_park) / sizeof(car_park[0]);
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (car_park[i].type == carType && car_park[i].speed == -1) {
|
||||
Car carToReturn = &car_park[i];
|
||||
car_park[i].speed = 0;
|
||||
return carToReturn;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
CarType get_type(Car car) {
|
||||
|
|
@ -48,4 +63,8 @@ void set_acceleration_rate(Car car, double acceleration_rate) {
|
|||
|
||||
void accelerate(Car car) {
|
||||
car->speed += 4;
|
||||
}
|
||||
|
||||
void init() {
|
||||
return;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue