Skip to content

Commit 98c81f7

Browse files
committed
drawing map method added in parser
1 parent 8428b5e commit 98c81f7

File tree

3 files changed

+67
-12
lines changed

3 files changed

+67
-12
lines changed

CSVParser.py

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,70 @@
11
import 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

79
class 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()

map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from car import Car
55

66
class Map:
7-
def __init__(self, id, width, height, car, walls): #surfaces
7+
def __init__(self, id, width, height, car, walls, surfaces): #surfaces
88
self.id = id
99
self.width = width
1010
self.height = height
1111
self.car = car
1212
self.walls = walls
13-
#self.surfaces = surfaces
13+
self.surfaces = surfaces
1414

1515
def check_collision(self):
1616
for wall in self.walls:

surfaceType.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ class SurfaceType(Enum):
1010
GRAVEL = (0.4, (204, 102, 0))
1111
GRASS = (0.5, (0, 204, 0))
1212
SAND = (0.25, (255, 255, 0))
13+
FINISHLINE = (0.9, "finish_line.png") #special case where there will be an image

0 commit comments

Comments
 (0)