def __init__(self): """Initialise a new Server object.""" with open(os.path.join("..", "config", "config.json")) as config_file: config = json.load(config_file) db_connection = database_API.Connection(config["postgres"]["user"], config["postgres"]["password"], config["postgres"]["database"]) self._session = db_connection.get_session() logger = Logger(self._session, "Server Connection Handler", config["logging"]["log_level"]) self._log = logger.get_logger() self._connection_handler = ConnectionHandler(self.handle_message, self._log) grid = Grid(20) grid.create_grid() grid.static_map() game_id = database_API.Game.insert(self._session, 1, True) self._gamestate = GameState(game_id, 1, grid, self._log, self._session) try: self._connection_handler.start(config["server"]["port"]) except KeyboardInterrupt: self._connection_handler.stop() sys.exit()
self._hud.draw_quick_surface(layouts) self._screen.blit(self._hud_quick_surface, (0, 0)) pygame.display.flip() if self._menu_displayed: self._select_menu.display_menu() else: self._main_menu.display_menu() def render_hud(self): """Render heads up display.""" while not self._shutdown: self._hud.draw() time.sleep(1) if __name__ == "__main__": with open(os.path.join("..", "config", "config.json")) as config_file: config = json.load(config_file) map_ref = Grid(26) map_ref.create_grid() map_ref.static_map() logger = Logger("client.log", "client", config["logging"]["log_level"]) logger = logger.get_logger() civ = Civilisation(1, map_ref, logger) game_state = GameState(1, 1, map_ref, logger) game_state.add_civ(civ) game_state.my_id = 1 server_api = server_API.ServerAPI() game = Game(game_state, logger, server_api) game.start()