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
def createGame() = Action.async { request => | |
WS.url(s"$apiUrl/game") | |
.post("") | |
.map { | |
case res if res.status == CREATED => Created(res.body) | |
case _ => InternalServerError | |
} | |
.recover { case _ => InternalServerError } | |
} |
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
def gameEvents(gameId: String) = WebSocket.acceptWithActor[String, GameEvent] { request => out => | |
WebsocketEventPublisher.props(gameId, out) | |
} |
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
POST /game controllers.MainController.createGame | |
POST /game/:gameId/start controllers.MainController.startGame(gameId: String, playersCount: Int) | |
POST /game/:gameId/roll/:playerId controllers.MainController.roll(gameId: String, playerId: String) | |
GET /:gameId/events controllers.MainController.gameEvents(gameId: String) | |
// other routes: static resources, main page |
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
class WebsocketEventPublisher(gameId: String, out: ActorRef) | |
extends Actor | |
with ActorLogging | |
with ImplicitFlowMaterializer { | |
import context.dispatcher | |
override def preStart() = { | |
import Global.connection | |
import Config.Events._ |
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); |
OlderNewer