-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
106 lines (91 loc) · 2.47 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
(function(){
var app = angular.module('dartGame', [
'ui.router'
]);
app.controller('lobbyCtrl', lobbyCtrl);
app.controller('gameCtrl', gameCtrl);
app.factory('gameSvc', gameSvc);
app.config(configStates);
configStates.$inject = ['$stateProvider', '$urlRouterProvider'];
function configStates($stateProvider, $urlRouterProvider) {
$urlRouterProvider.when('', '/lobby');
$urlRouterProvider.when('/', '/lobby');
$stateProvider
.state('lobby', {
url: '/lobby',
templateUrl: './pages/lobby.html',
controller: 'lobbyCtrl',
data: {
pageTitle: 'Lobby'
}
})
.state('game', {
url: '/game',
templateUrl: './pages/game.html',
controller: 'gameCtrl',
data: {
pageTitle: 'Game'
}
})
;
}
lobbyCtrl.$inject = ['$scope', '$state', 'gameSvc'];
function lobbyCtrl($scope, $state, gameSvc){
$scope.state = 'lobby';
$scope.players = [];
$scope.addPlayer = function(name){
var checkName = $scope.players.some(function(pl){
return pl.name === name;
});
if (checkName) {
alert('JA EXISTE ALGUEM COM ESSE NOME: ', name);
} else {
$scope.players.push({name:name, rounds:{}, totalScore:0});
$scope.playerName = '';
}
}
$scope.startGame = function(players){
gameSvc.players = players;
$state.go('game');
}
}
gameCtrl.$inject = ['$scope', 'gameSvc'];
function gameCtrl($scope, gameSvc){
$scope.players = gameSvc.players;
$scope.numRounds = 5;
$scope.rounds = function(){
var rounds = [];
for (var i = 0; i < $scope.numRounds; i++) {
rounds.push(i);
$scope.players = $scope.players.map(function(pl){
pl.rounds[i] = {total:0, edit:false};
return pl;
});
}
return rounds;
}();
$scope.makeTotal = function(pl){
var total = 0;
for (var i = 0; i < $scope.numRounds; i++) {
total += +pl.rounds[i].total;
}
pl.totalScore = total;
};
// $scope.editRound = function(player, round){
// player.rounds[round].edit = true;
// window.addEventListener('click', makeFalse);
//
// function makeFalse(){
// console.count();
// player.rounds[round].edit = false;
// window.removeEventListener('click', makeFalse);
// }
// };
}
gameSvc.$inject = [];
function gameSvc(){
var svc = {};
svc.players = [];
return svc;
}
})();