public OnlinePlayerService() { turnService = Container.get<TurnService>(); gameObserver = Container.get<GameObserver>(); socket = Container.get<WebSocketService>(); gameObserver.addListener("OnPlay", (message) => { Play play = ((Message<Play>) message).message; turnService.play(play); }); gameObserver.addListener(Events.CARD_TO_TABLE, (message) => { Play play = (Play) message; if(play.player.playerType == PlayerType.LOCAL){ socket.sendMessage<Play>(new Message<Play>( "Play", play, play.GetType().FullName )); } }); gameObserver.addListener("giveCards", (message) => { Room room = ((Message<Room>) message).message; turnService.currentRoom.players.ForEach((player) => { var onPlayer = room.players.Find((play) => { return play.id == player.id; }); player.cards = onPlayer.cards; }); }); gameObserver.addListener("cardsToPlayers", (message) => { Room room = (Room) message; if (turnService.isMaster) { socket.sendMessage<Room>(new Message<Room>("giveCards", room, room.GetType().FullName)); } }); }