In my gameclient I have the following classes(compontents): Game, GameScreen, GameWorld, Player.
They are structured like this: Game has two GameScreens: MenuScreen and MainScreen. MenuScreen has an instance of GameWorld. GameWorld has an instance of Player.
Now I wanted to add a multiplayer mode to my game. For this I have a class "NetworkConnection". For the problem keep in mind that this class needs to access individual objects in the game world, as well as vice-versa. Meaning that individual objects (as a simple example the player) need to send messages to the class. It could look like this for example:
networkConnection.SendPlayerPositionUpdate(x, y, playerID);
- The problem
Where do I put my NetworkConnection?
I thought about adding it to "Game" because it is a part of the game (duh). But when I want the player to tell its position to the server I have to do this:
(Inside the player class)
world.screen.game.networkConnection.SendPositionUpdate(...);
The otherway around (when messages are being received from the server)
(Inside the network class)
game.currentScreen.world.player.SetHealthPoints(receivedHealth);
Where should I place NetworkConnection? Should I make NetworkConnection a global singelton ?