public GamePlayController() { turnService = Container.get<TurnService>(); gameObserver = Container.get<GameObserver>(); gameObserver.addListener("GUI.CardClick", (cardObject) => { Card card = cardObject as Card; if(turnService.currentPlayer != localPlayer || turnService.currentProperty == Property.NONE){ // UnityEngine.Debug.Log("Clicked in " + card.id + " but not your turn"); return; } turnService.play(card, localPlayer); showCards(); if (turnService.currentPlayer == localPlayer) { showMenu(); } }, this); gameObserver.addListener(Events.TURN_WINNER, (playerMessage) => { if(playerMessage.Equals(localPlayer)){ showMenu(); } }); gameObserver.addListener(Events.NEXT_PLAYERS_TURN, (playerMessage) => { if(playerMessage.Equals(localPlayer)){ showMenu(); } }); gameObserver.addListener(Events.SELECT_PROPERTY, (property) => { showMenu(); }); //showMenu(); bindPropertyListeners(); }
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)); } }); }