This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.controller('GameController', function($scope, $rootScope, commandService) { | |
$scope.selectedPlayer = $rootScope.game.players[0]; | |
$scope.winners = []; | |
$scope.gameFinished = false; | |
$scope.playAgain = function() { | |
$rootScope.gameId = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rootScope.$on('events.TurnCountdownUpdated', function(event, data) { | |
$rootScope.game.turn.secondsLeft = data.secondsLeft; | |
$rootScope.$apply(); | |
}); | |
$rootScope.$on('events.TurnChanged', function(event, data) { | |
$rootScope.game.turn = data.turn; | |
$rootScope.$apply(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rootScope.$on('events.GameStarted', function(event, data) { | |
$rootScope.game = { | |
players: data.players, | |
turn: data.initialTurn, | |
scores: [] | |
}; | |
$rootScope.page = "game"; | |
$rootScope.$apply(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.controller('StartGameController', function($scope, $rootScope, commandService) { | |
$scope.playersCount = 6; | |
$scope.loading = false; | |
$scope.hidePopoverTimeout = null; | |
$scope.startGame = function() { | |
$scope.loading = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.controller('CreateGameController', function($scope, $rootScope, commandService, eventService) { | |
$scope.loading = false; | |
$scope.createNewGame = function() { | |
$scope.loading = true; | |
commandService.createGame(function(data) { | |
$scope.loading = false; | |
$rootScope.gameId = data.id; | |
$rootScope.page = "choose_players"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-switch on="page"> | |
<div ng-switch-when="create" ng-controller="CreateGameController"> | |
<!-- content --> | |
</div> | |
<div ng-switch-when="choose_players" ng-controller="StartGameController"> | |
<!-- content --> | |
</div> | |
<div ng-switch-when="game" ng-controller="GameController"> | |
<!-- content --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rootScope.page = "create"; // one of: "create", "choose_players", "game" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.service('commandService', function($http) { | |
return { | |
createGame: function(success, error) { | |
$http.post('/game') | |
.success(success) | |
.error(error); | |
}, | |
startGame: function(gameId, playersCount, error) { | |
$http.post('/game/' + gameId + '/start?playersCount=' + playersCount) | |
.error(error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override def receive = { | |
case ev: GameEvent => | |
out ! ev | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override val requestStrategy = new RequestStrategy { | |
override def requestDemand(remainingRequested: Int) = | |
Math.max(remainingRequested, 1) | |
} | |
override def receive = { | |
case OnNext(message: Message) => | |
val gameEvent = | |
GameEvent( | |
gameId = message.headers("gameId"), |