Skip to content

Instantly share code, notes, and snippets.

@LukasGasior1
Created June 8, 2015 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LukasGasior1/a1ba2a8902404346d0bb to your computer and use it in GitHub Desktop.
Save LukasGasior1/a1ba2a8902404346d0bb to your computer and use it in GitHub Desktop.
module.controller('GameController', function($scope, $rootScope, commandService) {
$scope.selectedPlayer = $rootScope.game.players[0];
$scope.winners = [];
$scope.gameFinished = false;
$scope.playAgain = function() {
$rootScope.gameId = null;
$rootScope.game = null;
$rootScope.page = "create";
};
$scope.hidePopoverTimeout = null;
$scope.roll = function() {
commandService.roll($scope.gameId, $scope.selectedPlayer, function(data) {
if (data.message) {
if ($scope.hidePopoverTimeout != null) {
clearTimeout($scope.hidePopoverTimeout);
}
$('#roll').popover({
content: data.message,
placement: 'left',
trigger: 'manual'
}).popover('show');
$scope.hidePopoverTimeout = setTimeout(function() {
$('#roll').popover('hide');
}, 1500);
} else {
alert('Unexpected error occurred, try again later.');
}
});
};
$scope.isWinner = function(player) {
return $.inArray(player, $scope.winners) != -1;
};
$rootScope.$on('events.TurnChanged', function(event, data) {
$scope.selectedPlayer = data.turn.currentPlayer;
$scope.$apply();
});
$rootScope.$on('events.GameFinished', function(event, data) {
$scope.gameFinished = true;
$scope.winners = data.winners;
$scope.$apply();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment