Skip to content

Commit a741511

Browse files
committed
GH-29: Fixing pylint issues in top level files.
1 parent fc0d738 commit a741511

File tree

5 files changed

+76
-71
lines changed

5 files changed

+76
-71
lines changed

constants.py

+36-34
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1-
import sys
2-
import subprocess
3-
import paths
1+
"""
2+
A file to export constants used throughout the application.
3+
4+
This module exports:
5+
VERSION - The game version of the current code.
6+
DISPLAY_NAME - The window title.
7+
DISPLAY_SIZE - The fixed size of the display.
8+
9+
MAP_SIZE - The x by y size of the game maps, in tiles.
10+
TILE_WIDTH - The width of game tiles in px.
11+
TILE_HEIGHT - The height of game tiles in px.
12+
13+
MAP_WIDTH - The total map width, worked out from the MAP_SIZE and TILE_WIDTH.
14+
MAP_HEIGHT - The total map height, worked out from the MAP_SIZE and TILE_WIDTH.
15+
MAP_PADDING - An arbitrary value for padding around the map.
16+
17+
GAME_RECT - The rect value ([x, y, width, height]) of the map, including padding.
18+
ORIGIN - The exact top point of the isometric map.
19+
20+
COLOURS - A dictionary of colours used throughout the application.
21+
FONTS - A dictionary of font information used in teh application.
422
5-
# Dev Version Text (Tries for git version, if cant get it, revert to version saved here)
6-
try:
7-
if sys.version_info[0] < 3.5:
8-
version = subprocess.check_output(["git", "describe", "--tags"]).strip()
9-
else:
10-
version = subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE).stdout.decode("utf-8")
11-
assert version != ""
12-
except Exception: # seems to be so dependent on system and versions, easier to do a catch all
13-
version = "v1.1.1" # git not installed, or older lib version, so revert to hardcoded version
23+
UNIT_SPECS - The data for each unit in the game including health, attach, defense etc.
24+
LEVELS - A matrix that manages how city level increases work.
25+
"""
1426

27+
import paths
28+
29+
# Application version. Should always match repository tag.
30+
VERSION = "v1.1.1"
1531

1632
# configuration for pygame.display
1733
DISPLAY_NAME = "Conqueror of Empires"
@@ -27,11 +43,11 @@
2743
MAP_HEIGHT = TILE_HEIGHT*MAP_SIZE[1]
2844
MAP_PADDING = 20 # space between map and edge of game surface.
2945

30-
width = MAP_WIDTH + MAP_PADDING*2
31-
height = MAP_HEIGHT + TILE_HEIGHT + MAP_PADDING*2
32-
x = -MAP_WIDTH/2
33-
y = -MAP_PADDING
34-
GAME_RECT = [x, y, width, height] # x, y change with scroll anyway
46+
WIDTH = MAP_WIDTH + MAP_PADDING * 2
47+
HEIGHT = MAP_HEIGHT + TILE_HEIGHT + MAP_PADDING * 2
48+
X = -MAP_WIDTH / 2
49+
Y = -MAP_PADDING
50+
GAME_RECT = [X, Y, WIDTH, HEIGHT] # x, y change with scroll anyway
3551

3652
ORIGIN = [GAME_RECT[2]/2 - TILE_HEIGHT + MAP_PADDING, MAP_PADDING] # top map point
3753

@@ -59,18 +75,6 @@
5975
"small": 12},
6076
"colour": COLOURS["white"]}
6177

62-
# Game Data
63-
TILE_DATA = {
64-
"s": [0, 0, 0],
65-
"w": [0, 0, 0],
66-
"g": [0, 0, 0],
67-
"f": [100, 20, 5],
68-
"m": [10, 100, 20],
69-
"o": [10, 100, 50],
70-
"c": [100, 50, 25], # default of settlement store (level 1)
71-
}
72-
73-
7478
UNIT_SPECS = {
7579
"scout": {
7680
"max_health": 10,
@@ -124,9 +128,8 @@
124128
},
125129
}
126130

127-
# each item is level, each item in level is sub-level.
128-
# item: len() = number of sub-levels to next level, value is ap cost to reach sub level/ len() = 0 means max level
129-
# city level starts at 1, to reference level must do city_level - 1.
131+
# Levels Matrix
132+
# each list item represents a level, each item within a level list represents a sub-level.
130133
LEVELS = [
131134
[2, 2, 2], # 1 to 2
132135
[2, 2, 2, 2], # 2 to 3
@@ -135,6 +138,5 @@
135138
[], # 5 is max
136139
]
137140

138-
139141
# Cleanup unneeded to not pollute namespace.
140-
del x, y, width, height, MAP_PADDING
142+
del X, Y, WIDTH, HEIGHT, MAP_PADDING

main.py

+21-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
#!/usr/bin/env python3
22

3+
"""
4+
The main entry point for the application.
5+
"""
6+
37
import logging
4-
logging.basicConfig(filename='main.log', filemode='w', format='%(name)s - %(levelname)s - %(message)s')
8+
from project import control
59

6-
try:
10+
# Setting up logging
11+
logging.basicConfig(
12+
filename='main.log',
13+
filemode='w',
14+
format='%(name)s - %(levelname)s - %(message)s'
15+
)
716

8-
import project.control as control
917

10-
def main():
11-
controller = control.ApplicationController()
12-
controller.run()
18+
def main():
19+
""" The main function to instantiate and run the application controller. """
1320

21+
controller = control.ApplicationController()
22+
controller.run()
1423

15-
if __name__ == "__main__":
16-
main()
1724

18-
except Exception as e:
19-
logging.exception("caught at main")
20-
raise e # personal choice, still want to see error in IDE
25+
if __name__ == "__main__":
26+
try:
27+
main()
28+
except Exception as error:
29+
logging.exception("caught at main")
30+
raise error # personal choice, still want to see error in IDE

paths.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
"""
2+
A constants file to export file paths used in the application.
3+
This includes data and asset paths.
4+
5+
This module exports:
6+
dataPath - The base folder that stores game data such as maps, game saves etc.
7+
assetPath - The base folder that stores game assets.
8+
gamePath - The folder that stores saved games.
9+
mapPath - The folder that stores map files.
10+
fontPath - The folder that stores font files used in the application.
11+
imagePath - The base path that stores image assets used in the application.
12+
tilePath - The folder that stores map tile images.
13+
unitPath - The folder that stores unit images.
14+
uiPath - The folder that stores general images related to the application UI.
15+
uiMenuPath - The folder that stores UI images specifically for the menus.
16+
uiGamePath - The folder that stores UI images specifically for use in the game.
17+
"""
18+
119
import os
220

321
dataPath = os.getcwd() + os.sep + "data" + os.sep

project/game/model.py

-25
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ class Tile:
289289
def __init__(self, save_data):
290290
self.type = save_data["type"]
291291
self.position = save_data["position"]
292-
# self.wood, self.stone, self.metal = constants.TILE_DATA[tile_type]
293292

294293
def get_save_data(self):
295294
return {
@@ -303,30 +302,6 @@ def get_type(self):
303302
def get_position(self):
304303
return self.position
305304

306-
# def take_wood(self, amount=1): # defaults, left for future in case decide change.
307-
# if self.wood > 0:
308-
# self.wood = self.wood - amount
309-
# if self.wood < 0:
310-
# self.wood = 0 # ensures resource is fully used, but cant go negative.
311-
# return True
312-
# return False
313-
#
314-
# def take_stone(self, amount=1):
315-
# if self.stone > 0:
316-
# self.stone = self.stone - amount
317-
# if self.stone < 0:
318-
# self.stone = 0
319-
# return True
320-
# return False
321-
#
322-
# def take_metal(self, amount=1):
323-
# if self.metal > 0:
324-
# self.metal = self.metal - amount
325-
# if self.metal < 0:
326-
# self.metal = 0
327-
# return True
328-
# return False
329-
330305

331306
class City:
332307
def __init__(self, model_link, save_data):

project/menus/menu.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def __init__(self, GUI):
195195
self.rect[0] + 5, self.rect[1] + 130)
196196

197197
self.version = pygame_gui.Text(
198-
constants.version,
198+
constants.VERSION,
199199
constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"],
200200
self.rect[0] + 5, self.rect[1] + self.rect[3] - 20)
201201

0 commit comments

Comments
 (0)