-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.h
100 lines (92 loc) · 1.95 KB
/
list.h
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
// dynamic list template
template <class Type>
list<Type>::list(int nmax)
{
this->first = this->last = NULL;
this->length = 0;
this->max = nmax;
}
template <class Type>
list<Type>::~list()
{
while(this->length > 0)
{
Type *next = (Type *)this->first->next;
delete this->first;
this->first = next;
this->length--;
}
}
template <class Type>
void list<Type>::add(Type *obj)
{
//if(this->length == this->max) return;
if(this->length == 0)
{
this->first = this->last = obj;
}
else
{
this->last->next = obj;
obj->prev = this->last;
this->last = obj;
}
this->length++;
}
template <class Type>
void list<Type>::del(Type *obj)
{
if(obj == this->first)
{
this->first = (Type *)this->first->next;
}
else if(obj == this->last)
{
this->last = (Type *)this->last->prev;
}
else
{
obj->prev->next = (Type *)obj->next;
obj->next->prev = (Type *)obj->prev;
}
this->length--;
}
template <class Type>
Type * list<Type>::get(int id)
{
if(id > this->length-1) return NULL;
Type *curr = this->first;
for(int idx=0; idx<id; idx++)
{
curr = curr->next;
}
return curr;
}
template <class Type>
void list<Type>::empty()
{
Type *tmp, *curr = this->first;
for(int idx=0; idx<this->length; idx++)
{
tmp = (Type *)curr->next;
CloseHandle(curr->thread);
delete curr->trail;
delete curr->body;
if(curr->explosion) delete curr->explosion;
delete curr;
curr = tmp;
}
this->length = 0;
}
template <class Type>
void list<Type>::render()
{
Type *curr = this->first;
for(int idx=0; idx<this->length; idx++)
{
curr->trail->Render();
if(curr->alive) curr->body->RenderEx(curr->x, curr->y, curr->angle, 1);
if(curr->explosion) curr->explosion->Render();
curr = (Type *)curr->next;
}
}