11import map
2- import wall
3- import surface
4- import surfaceType
2+ from wall import Wall
3+ from surface import Surface
4+ from surfaceType import SurfaceType
5+ import csv
6+ from vector2d import Vector2D
57
68
79class CSVParser :
8- def __init__ (self , filename , map : map ):
9- self .source_file = filename
10- self .map_to_draw = map
10+ def __init__ (self , map_source , leaderboard ):
11+ self .source_file = map_source
12+ self .leaderboard = leaderboard
1113
12- def open_file (self ):
13- pass
1414
15- def parse_file (self ):
16- pass
15+ def draw_map (self , map : map ):
16+ file = open (self .source_file )
17+ csv_reader = csv .reader (file )
18+ header = next (csv_reader )
19+
20+ rows = []
21+
22+ for row in csv_reader :
23+ row .append (row )
24+
25+ #planned CSV structure ->
26+ #0 type(string -> what is it, wall / surface),
27+ #1 position x,
28+ #2 position y,
29+ #3 width,
30+ #4 height,
31+ #5 surfaceType or with_tires to specify
32+ for row in rows :
33+ position = Vector2D (row [1 ], row [2 ])
34+ width = row [3 ]
35+ height = row [4 ]
36+
37+ if row [0 ] == "WALL" :
38+ if row [5 ] == "with_tires" :
39+ map .walls .append (Wall (position , width , height , True ))
40+ else :
41+ map .walls .append (Wall (position , width , height , False ))
42+
43+ elif row [0 ] == "SURFACE" :
44+ if row [5 ] == "ASPHALT" :
45+ map .sufraces .append (Surface (position , width , height , SurfaceType .ASPHALT ))
46+
47+ elif row [5 ] == "SNOW" :
48+ map .sufraces .append (Surface (position , width , height , SurfaceType .SNOW ))
49+
50+ elif row [5 ] == "ICE" :
51+ map .sufraces .append (Surface (position , width , height , SurfaceType .ICE ))
52+
53+ elif row [5 ] == "GRAVEL" :
54+ map .sufraces .append (Surface (position , width , height , SurfaceType .GRAVEL ))
55+
56+ elif row [5 ] == "SAND" :
57+ map .sufraces .append (Surface (position , width , height , SurfaceType .SAND ))
58+
59+ elif row [5 ] == "GRASS" :
60+ map .sufraces .append (Surface (position , width , height , SurfaceType .GRASS ))
61+
62+ elif row [5 ] == "FINISHLINE" :
63+ map .sufraces .append (Surface (position , width , height , SurfaceType .FINISHLINE ))
64+
65+ file .close ()
66+
67+ def write_to_leaderboard (self ):
68+ file = open (self .leaderboard )
69+ csv_writer = csv .writer (file )
70+ file .close ()
0 commit comments