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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
(function () {
var app = angular.module('main-app', ['AutoFont', 'VAligner', 'network-app']);
app.factory('ViewService', function () {
var obj = function () {
var _currentViewName = 'accounts';
this.__defineGetter__('currentViewName', function () {
return _currentViewName;
});
this.__defineSetter__('currentViewName', function (name) {
_currentViewName = name;
triggerAll();
});
var listeners = [];
this.addListener = function (listener) {
listeners.push(listener);
};
var triggerAll = function () {
for (var i = 0; i < listeners.length; i++) {
if (typeof(listeners[i]) === 'function') {
listeners[i]();
}
}
}
};
return new obj();
});
app.value('AppData', {
userInfo: {}
});
app.controller('MainController', ['$scope', 'ViewService', 'AppData', function ($scope, ViewService, AppData) {
$scope.getCurrentViewName = function () {
return ViewService.currentViewName;
};
$scope.getLogin = function () {
return AppData.login;
}
}]);
app.controller('GameController', ['$scope', 'NetworkService', 'ViewService', function ($scope, NetworkService, ViewService) {
this.gameData = {};
var self = this;
NetworkService.addTagListener('GameData', function (data) {
for (var key in data.data) {
if (!data.data.hasOwnProperty(key)) {
continue;
}
self.gameData[key] = data.data[key];
}
if (data.game_status == 'started') {
ViewService.currentViewName = 'round';
}
$scope.$apply();
});
this.remainingWaiting = 10;
this.costs = [100, 200, 300, 400, 500, 600, 700, 800].reverse();
this.currentCostId = 3;
this.bank = {
value: 1000,
enabled: false
};
this.players = [];
this.currentPlayer = this.players[1];
this.currentQuestion = {
quest: 'This is question',
answers: ['answer1', 'answer2', 'answer3'],
selected: 0,
correct: 1
};
this.myTurn = false;
this.me = this.players[0];
this.timer = {
round: 100
};
this.final = {
finalists: [this.players[0], this.players[1]],
checks: [[0, 0], [0, 1], [1, 0], [1, 1]]
}
}]);
app.controller('AccountsController', ['$scope', '$timeout', 'AppData', 'ViewService', 'NetworkService',
function ($scope, $timeout, AppData, ViewService, NetworkService) {
this.accounts = ['1', '2', '3', '4', '5', '6'];
this.setAccount = function(login) {
ViewService.currentViewName = 'menu';
NetworkService.addTagListener('UserInfo', function (data) {
console.log('userInfo');
console.log(data.data);
AppData.userInfo = data.data;
});
NetworkService.handshake('sivsais');//login);
};
}]);
app.controller('MenuController', ['$scope', 'ViewService', 'AppData', 'NetworkService',
function ($scope, ViewService, AppData, NetworkService) {
$scope.setCurrentViewName = function (name) {
ViewService.currentViewName = name;
};
this.soundEnabled = true;
this.onButtonClicked = function (id) {
if (id == 0) {
ViewService.currentViewName = 'waiting';
NetworkService.send(AppData.userInfo.ID, 'C_Misc', 'C_PLAY', {});
}
}
}]);
app.directive('view', ['ViewService', function (ViewService) {
return {
restrict: 'E',
link: function (scope, elem, attrs) {
scope.currentUrl = 'views/' + ViewService.currentViewName + '/' + ViewService.currentViewName + '.html';
ViewService.addListener(function () {
scope.currentUrl = 'views/' + ViewService.currentViewName + '/' + ViewService.currentViewName + '.html';
});
},
template: '<div ng-include="currentUrl"></div>'//,
}
}]);
})();