This repository was archived by the owner on Mar 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCar.c
135 lines (112 loc) · 2.2 KB
/
Car.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Car.h"
Cars_list addCar(Cars_list list, Car* element)
{
element_list* new_element = malloc(sizeof(element_list));
new_element->car = element;
new_element->next = NULL;
if(list == NULL)
{
return new_element;
}
else
{
element_list* tmp = list;
while(tmp->next != NULL)
{
tmp = tmp->next;
}
tmp->next = new_element;
return list;
}
}
Cars_list addFirst(Cars_list list, Car* element)
{
element_list* new_element = malloc(sizeof(element_list));
new_element->car = element;
new_element->next = list;
return new_element;
}
Car* createCar(int id, int posx, int posy, float speed, float acc, char state, char color)
{
Car* new_car = malloc(sizeof(Car));
new_car->id = id;
new_car->posx = posx;
new_car->posy = posy;
new_car->speed = speed;
new_car->acc = acc;
new_car->state = state;
new_car->color = color;
new_car->collision = 0;
new_car->behind_speed = 0;
new_car->toposx = posx;
return new_car;
}
Cars_list delCar(Cars_list list, Car* element)
{
if(list == NULL) {
return NULL;
}
if(list->car == element) {
Cars_list tmp = list->next;
free(list);
return tmp;
}
Cars_list tmp1 = list;
Cars_list tmp2 = list->next;
while(tmp2 != NULL)
{
if(tmp2->car == element) {
tmp1->next = tmp2->next;
free(tmp2);
return list;
}
tmp2 = tmp2->next;
tmp1 = tmp1->next;
}
return list;
}
Score_list addScore(Score_list list, int score, char* nom)
{
element_score_list* new_element = malloc(sizeof(element_score_list));
new_element->score = score;
strcpy(new_element->nom,nom);
new_element->next = NULL;
if(list == NULL)
{
return new_element;
}
if(score >= list->score) {
new_element->next = list;
return new_element;
}
element_score_list* tmp = list->next;
element_score_list* tmp2 = list;
while(tmp != NULL)
{
if(score >= tmp->score)
break;
tmp2 = tmp;
tmp = tmp->next;
}
tmp2->next = new_element;
new_element->next = tmp;
return list;
}
Score_list delScore(Score_list list)
{
if(list == NULL) {
return NULL;
}
Score_list tmp1 = list;
Score_list tmp2 = list;
while(tmp1 != NULL)
{
tmp1 = tmp1->next;
free(tmp2);
tmp2 = tmp1;
}
return NULL;
}