-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenveronement.cpp
executable file
·62 lines (54 loc) · 1.26 KB
/
enveronement.cpp
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
#include "enveronement.h"
void enverenement::addObstacle(obstacle *obst)
{
ensembleObstacle->append (obst);
}
enverenement::enverenement()
{
ensembleObstacle = new QList<obstacle>();
visible=true;
}
void enverenement::rest()
{
delete ensembleObstacle;
ensembleObstacle = new QList<obstacle>();
}
void enverenement::drawIt(QPainter *paint)
{
if (visible)
{
obstacle *ob;
for ( ob=ensembleObstacle->first(); ob != 0; ob=ensembleObstacle->next() )
{
paint->fillRect (ob->min.x(),ob->min.y(),
ob->max.x() - ob->min.x(),
ob->max.y() - ob->min.y(),
QBrush( Qt::darkCyan));
}
}
}
void enverenement::load(char *file)
{
rest();
FILE * fp= fopen(file,"r");
char ligne [100];
int minx,miny,maxx,maxy;
while (fgets(ligne,80,fp))
{
if (sscanf(ligne,"%d %d %d %d\n",&minx,&miny,&maxx,&maxy)!=-1){
obstacle *ob=new obstacle(QPoint(minx,miny),QPoint(maxx,maxy));
addObstacle(ob);
}
}
fclose(fp);
}
void enverenement::save(char *file)
{
obstacle *ob;
FILE * fp= fopen(file,"w");
if (fp){
for ( ob=ensembleObstacle->first(); ob != 0; ob=ensembleObstacle->next() )
fprintf(fp,"%d %d %d %d\n",ob->min.x(),ob->min.y(),ob->max.x(),ob->max.y());
}
fclose(fp);
}