Skip to content

Commit 2f1e997

Browse files
committed
enum_and_parser code prettified
1 parent ad7dd7c commit 2f1e997

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

data/Records.csv

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,10 @@ ferrari458,map1,8000,Lec
335335
ferrari458,map1,10051,Lec
336336
ferrari458,map1,7630,Lec
337337
ferrari458,map1,7872,Lec
338-
ferrari458,map1,13118,Lec
338+
ferrari458,map1,13118,Lec
339+
supra_new,map1,10830,Gucio
340+
supra_new,map1,10128,Gucio
341+
supra_new,map1,10362,Gucio
342+
supra_new,map1,21638,Gucio
343+
supra_new,map1,11979,Gucio
344+
supra_new,map1,15231,Gucio

enums_and_parser/CSVParser.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from back_elements.wall import Wall
32
from back_elements.surface import Surface
43
from enums_and_parser.surfaceType import SurfaceType
@@ -22,14 +21,14 @@ def draw_map(self, map):
2221
for row in csv_reader:
2322
rows.append(row)
2423

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-
#6 rotation -> if it has image, how much is it rotated
24+
# planned CSV structure ->
25+
# 0 type(string -> what is it, wall / surface),
26+
# 1 position x,
27+
# 2 position y,
28+
# 3 width,
29+
# 4 height,
30+
# 5 surfaceType or with_tires to specify
31+
# 6 rotation -> if it has image, how much is it rotated
3332
for row in rows:
3433
position = Vector2D(int(row[1]), int(row[2]))
3534
width = int(row[3])
@@ -45,7 +44,8 @@ def draw_map(self, map):
4544
elif row[0] == "SURFACE":
4645
if row[5] == "ASPHALT":
4746
map.all_surfaces.add(Surface(position, width, height, SurfaceType.ASPHALT, rotation))
48-
map.places_for_boosters.append([position.x + 40, position.y + 40, position.x + width - 40, position.y + height - 40])
47+
map.places_for_boosters.append(
48+
[position.x + 40, position.y + 40, position.x + width - 40, position.y + height - 40])
4949

5050
elif row[5] == "SNOW":
5151
map.all_surfaces.add(Surface(position, width, height, SurfaceType.SNOW, rotation))
@@ -74,12 +74,12 @@ def draw_map(self, map):
7474

7575
file.close()
7676

77-
def write_to_leaderboard(self,result, name, map, car):
78-
#assuming the following schema of the CSV file:
79-
#0 - player name
80-
#1 - player result(time)
81-
#2 - map
82-
#3 - car model
77+
def write_to_leaderboard(self, result, name, map, car):
78+
# assuming the following schema of the CSV file:
79+
# 0 - player name
80+
# 1 - player result(time)
81+
# 2 - map
82+
# 3 - car model
8383

8484
file = open(self.leaderboard)
8585
csv_writer = csv.writer(file)
@@ -96,18 +96,16 @@ def read_leaderboard(self):
9696
rows = []
9797

9898
for row in csv_reader:
99-
row.append(row)
100-
101-
#now we can do what we want with the rows - it's up to us what
99+
rows.append(row)
102100

103101
file.close()
104102
pass
105103

106-
def read_car_statistics(self, car_id:int):
107-
#planned cars file structure:
108-
#[0] - id
109-
#[1] - NAME
110-
#[2] - engine
104+
def read_car_statistics(self, car_id: int):
105+
# planned cars file structure:
106+
# [0] - id
107+
# [1] - NAME
108+
# [2] - engine
111109

112110
file = open(self.cars)
113111
csv_reader = csv.reader(file)
@@ -118,5 +116,4 @@ def read_car_statistics(self, car_id:int):
118116
for row in csv_reader:
119117
rows.append(row)
120118

121-
#we return this data to engine or whatever and it will create a car
122119
return int(rows[car_id][0]), rows[car_id][1], int(rows[car_id][2])

enums_and_parser/boosterType.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33

44
class BoosterType(Enum):
5-
#both positive and negative
5+
# both positive and negative
66
SPEED = (1, "sp_resized")
77
TURNING = (2, "tr_resized")
88

9-
#only positive
9+
# only positive
1010
NO_COLLISIONS = (3, "nw_resized")
1111
DECREASE_TIMER = (4, "dt_resized")
1212

13-
#only negative
13+
# only negative
1414
NO_TURNING = (5, "nt_resized")
1515
FREEZE = (6, "fr_resized")

enums_and_parser/surfaceType.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33

44
class SurfaceType(Enum):
5-
#in car.move there is friction hardcoded so it will be easy to add these values
6-
#but we can also consider adding air friction - wind (given we have enough time)
7-
#it would be similar but it would depend on direction of movement
85
ASPHALT = (0.9, (0, 0, 0)) # (fraction, colour) respectively
96
SNOW = (0.35, (245, 245, 245))
107
ICE = (0.1, (153, 204, 255))
118
GRAVEL = (0.4, (204, 102, 0))
129
GRASS = (0.5, (0, 204, 0))
1310
SAND = (0.25, (255, 255, 0))
14-
FINISHLINE = (0.9, "./data/finish_line.png") #special case where there will be an image
11+
FINISHLINE = (0.9, "./data/finish_line.png")
1512
SIDE = (0.9, "./data/side.png")
1613
CHECKPOINT = (0.9, (255, 0, 0))

0 commit comments

Comments
 (0)