From aaebad30cd22fed75e52108967f7e6e19d2283c3 Mon Sep 17 00:00:00 2001 From: Evgeny Krasnov Date: Sun, 25 Sep 2022 15:09:18 +0300 Subject: [PATCH] I changed 2 functions in component/map.py to improve their cycle complexity --- source/component/map.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/source/component/map.py b/source/component/map.py index 57461a0..d7b01ff 100644 --- a/source/component/map.py +++ b/source/component/map.py @@ -180,16 +180,14 @@ def drawBackground(self, surface): for y in range(self.height): for x in range(self.width): - if self.bg_map[y][x] == c.BG_EMPTY: - color = c.LIGHTYELLOW - elif self.bg_map[y][x] == c.BG_ACTIVE: - color = c.SKY_BLUE - elif self.bg_map[y][x] == c.BG_RANGE: - color = c.NAVYBLUE - elif self.bg_map[y][x] == c.BG_SELECT: - color = c.GREEN - elif self.bg_map[y][x] == c.BG_ATTACK: - color = c.GOLD + colors = { + c.BG_EMPTY: c.LIGHTYELLOW, + c.BG_ACTIVE: c.SKY_BLUE, + c.BG_RANGE: c.NAVYBLUE, + c.BG_SELECT: c.GREEN, + c.BG_ATTACK: c.GOLD + } + color = colors[self.bg_map[y][x]] pg.draw.rect(surface, color, (x * c.REC_SIZE, y * c.REC_SIZE, c.REC_SIZE, c.REC_SIZE)) @@ -228,16 +226,14 @@ def drawBackgroundHex(self, surface): for y in range(self.height): for x in range(self.width): - if self.bg_map[y][x] == c.BG_EMPTY: - color = c.LIGHTYELLOW - elif self.bg_map[y][x] == c.BG_ACTIVE: - color = c.SKY_BLUE - elif self.bg_map[y][x] == c.BG_RANGE: - color = c.NAVYBLUE - elif self.bg_map[y][x] == c.BG_SELECT: - color = c.GREEN - elif self.bg_map[y][x] == c.BG_ATTACK: - color = c.GOLD + colors = { + c.BG_EMPTY: c.LIGHTYELLOW, + c.BG_ACTIVE: c.SKY_BLUE, + c.BG_RANGE: c.NAVYBLUE, + c.BG_SELECT: c.GREEN, + c.BG_ATTACK: c.GOLD + } + color = colors[self.bg_map[y][x]] base_x, base_y = tool.getHexMapPos(x, y) points = [(base_x, base_y + Y_LEN//2 + Y_LEN), (base_x, base_y + Y_LEN//2),