I added networking to my game, but I’m wondering where the best place is to send network messages.
My first idea was to add the network code to each action in the game wich results in this:
EndTurnAction
I think that is rather messy, as half of the class is networking code. So my second Idea was to move all network code in some kind of facade like
replace:
case NETWORK_SNAIL_GAME:
endTurnInSnailGameMode();
break;
with:
case NETWORK_SNAIL_GAME:
NetworkFacade.getInstance().endTurnInSnailGameMode(session);
break;
Now all the network code is grouped in 1 class NetworkFacade. Along with the catch blocks and GUI dialogs…
and then my last idea was to create a wrapper around the EndTurnAction class called the NetworkEndTurnAction class that ends the turn and sends a network message. But then I have to change the way I create new EndTurn Actions. if network then create network wrapper else create normal action?
An action is created in the ActionFactory like this:
public class ActionFactory {
public static CWAction buildEndTurnAction() {
ActionBag endTurnAction = new ActionBag("End Turn");
endTurnAction.add(new ClearInGameStateAction());
endTurnAction.add(new EndTurnAction());
endTurnAction.setActionText("end_turn");
return endTurnAction;
}
}
This is just 1 action ofcourse there are many more actions. Wich of the above 3 ideas would be the cleanest most beautifull/amazing/super way? Any hints on how this is normally done?