General
The Woosls code is written in Python, and follows the Python style guide. That is, 4 space indentation, no spaces around ( and ), and so on.
When using Python for small scripts, you never need care much about code organization, it simply will be readable. For a project like this, there are some self-imposed guidelines:
* Put all variables at proper place, that is, local, class level, or module level. Python has no global variables, so the problems of C++ with that can’t arise.
* Next, initialize all variables in the __init__ function of the class. This somehow violates the ability to have fully dynamic objects, but for Woosls, it is good as documentation. For example, when the game is saved and reloaded, it’s enough to check that every variable in the __init__ methods is saved/reloaded. Of course the pickle module could be used in that specific case, bu still - it’s nice to have an overview of all variables, even if usually you just add properties to an object where they arise.
* Never make a file with more than 1000 lines. 500 lines already is really bad. And creating a file of 1 line for a very simple class is ok. The reason is, this serves again as documentation. If each unit class has its file, then everything is clear. Of course you could just put 3 or 4 units inherited from another in one file.. but there’s no advantage.
* Related to the previous, never put many unrelated source files into the same directory. E.g. all units go into their own directory.
That’s about it, I may add more later. But it’s all Python code, so there really shouldn’t be much possibility to mess up completely, like in most other languages who ”’even ignore whitespace”’ |)
main.py
This does several things (maybe should split it?):
* Startup code
* Run the main event loop
* Dispatch events and ticks to server, client, GUI
* Hold global accessible items, e.g. the screen or the current client, so they can be accessed by other modules without having to pass around references everywhere
map.py
The map module simply contains the representation of the hexagon map.
game.py
The game module contains the complete game state. This means map and players.
server.py
The server module has the game server. It handles all client requests and sends out the game ticks.
client.py
This is where user input is collected and transformed into requests to the server. Replies by the server are received and passed on to the game module.
player.py
This module describes a player. A player has units, a roads net, various settings and other things.
unit.py
Implementation of a single unit.