social_stream-presence 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/jquery.ui.chatbox.sstreampresence.js +1 -1
- data/app/assets/javascripts/presence.js.erb +16 -1
- data/app/assets/javascripts/presence_XmppClient.js.erb +10 -3
- data/app/assets/javascripts/presence_game.js.erb +284 -49
- data/app/assets/javascripts/presence_game_comunication.js.erb +313 -0
- data/app/assets/javascripts/presence_game_interface.js.erb +134 -0
- data/app/assets/javascripts/presence_game_ter.js.erb +237 -188
- data/app/assets/javascripts/presence_persistence.js +1 -1
- data/app/assets/javascripts/presence_uiManager.js.erb +4 -2
- data/app/assets/javascripts/presence_utilities.js +1 -1
- data/app/assets/javascripts/presence_videochat.js.erb +2 -3
- data/app/assets/javascripts/presence_windowManager.js +8 -1
- data/app/assets/stylesheets/TresEnRaya.css +57 -0
- data/app/assets/stylesheets/chat.css.scss +22 -1
- data/app/views/chat/_index.html.erb +15 -18
- data/config/locales/en.yml +14 -1
- data/config/locales/es.yml +14 -1
- data/lib/social_stream/presence/version.rb +1 -1
- data/lib/tasks/presence/installer.rake +2 -2
- data/vendor/assets/javascripts/jquery.gamequery-0.5.1.js +1164 -0
- metadata +95 -65
@@ -0,0 +1,134 @@
|
|
1
|
+
////////////////////
|
2
|
+
//Multiplayer Games Interface Manager
|
3
|
+
////////////////////
|
4
|
+
|
5
|
+
PRESENCE.GAME.INTERFACE = (function(P,$,undefined){
|
6
|
+
|
7
|
+
//////////////////////////
|
8
|
+
// TRIGGERS //
|
9
|
+
//////////////////////////
|
10
|
+
|
11
|
+
var pickGamesButton = function (uiElement){
|
12
|
+
var slug = $(uiElement.element).attr("id");
|
13
|
+
var videoBoxVisibility = toggleVideoBoxForSlug(slug);
|
14
|
+
|
15
|
+
if (videoBoxVisibility) {
|
16
|
+
hideVideoChatButton(slug);
|
17
|
+
var mygame = generateDefaultGame(slug);
|
18
|
+
PRESENCE.GAME.requestUserToPlay(slug,mygame);
|
19
|
+
} else {
|
20
|
+
showVideoChatButton(slug);
|
21
|
+
PRESENCE.GAME.finishGame(slug);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
////////////////////////////
|
27
|
+
// CALLBACKS //
|
28
|
+
////////////////////////////
|
29
|
+
|
30
|
+
updateInterfaceAfterGameRequestReceived = function(slug){
|
31
|
+
//gameStatus="pending";
|
32
|
+
|
33
|
+
//Show or create chatbox
|
34
|
+
createBuddyChatBox(slug);
|
35
|
+
var chatBox = getChatBoxForSlug(slug);
|
36
|
+
|
37
|
+
//Show invitation message
|
38
|
+
showGameInvitation(slug);
|
39
|
+
|
40
|
+
//Hide hideVideoChatButton
|
41
|
+
hideVideoChatButton(slug);
|
42
|
+
|
43
|
+
//Show gamebox
|
44
|
+
toggleVideoBoxForSlug(slug,true);
|
45
|
+
}
|
46
|
+
|
47
|
+
var updateInterfaceBeforeStartGame = function(slug){
|
48
|
+
var parentDiv = document.createElement('div');
|
49
|
+
var divID = 'game_' + slug + contactsInfo[slug].game.id;
|
50
|
+
parentDiv.setAttribute('id', divID);
|
51
|
+
$(parentDiv).css('width', "100%");
|
52
|
+
$(parentDiv).css('height', "100%");
|
53
|
+
setVideoBoxContent(slug,parentDiv);
|
54
|
+
|
55
|
+
PRESENCE.GAME.startGame(slug,divID)
|
56
|
+
}
|
57
|
+
|
58
|
+
var updateInterfaceAfterFinishGame = function(slug){
|
59
|
+
toggleVideoBoxForSlug(slug,false);
|
60
|
+
showVideoChatButton(slug);
|
61
|
+
}
|
62
|
+
|
63
|
+
var updateInterfaceOnInformationMessage = function(slug,msg){
|
64
|
+
setVideoBoxContent(slug,"<p class=\"game-info\"> " + msg +" </p>");
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
///////////////////////////////
|
70
|
+
// INTERFACE HELP METHODS //
|
71
|
+
///////////////////////////////
|
72
|
+
|
73
|
+
var showGameInvitation = function(slug){
|
74
|
+
var title = "<p class=\"game-info\">" + I18n.t("chat.game.call", {name: getNameFromSlug(slug)}) + " </p>";
|
75
|
+
var msg = title + "<p class=\"game-request\"> <a class=\"gameButton\" slug=\""+slug+"\" value=\"yes\">" + I18n.t("chat.game.accept") + "</a> -"
|
76
|
+
+ " <a class=\"gameButton\" slug=\""+slug+"\" value=\"no\">" + I18n.t("chat.game.deny") + "</a> </p>";
|
77
|
+
setVideoBoxContent(slug,msg);
|
78
|
+
setGameRequestButtonsFunction();
|
79
|
+
}
|
80
|
+
|
81
|
+
var setGameRequestButtonsFunction = function(){
|
82
|
+
$(".gameButton").click(function(event) {
|
83
|
+
event.preventDefault();
|
84
|
+
var result = $(this).attr("value");
|
85
|
+
var slug = $(this).attr("slug");
|
86
|
+
PRESENCE.GAME.responseUserToPlay(slug,result);
|
87
|
+
});
|
88
|
+
}
|
89
|
+
|
90
|
+
var hideVideoChatButton = function(slug){
|
91
|
+
$(getChatBoxButtonForSlug(slug,"video")).hide();
|
92
|
+
}
|
93
|
+
|
94
|
+
var showVideoChatButton = function(slug){
|
95
|
+
$(getChatBoxButtonForSlug(slug,"video")).show();
|
96
|
+
}
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
//////////////////////
|
101
|
+
// DEBUG METHODS //
|
102
|
+
//////////////////////
|
103
|
+
|
104
|
+
var generateDefaultGame = function(guest_slug){
|
105
|
+
var player1 = new PRESENCE.GAME.player(user_slug,user_name)
|
106
|
+
var player2 = new PRESENCE.GAME.player(guest_slug,getNameFromSlug(guest_slug))
|
107
|
+
var localPlayers = [player1,player2]
|
108
|
+
var localOptions = new Array();
|
109
|
+
localOptions['theme']="Modern";
|
110
|
+
var mygame = new PRESENCE.GAME.game("TER","Tres en Raya",localPlayers,localOptions)
|
111
|
+
return mygame;
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
return {
|
116
|
+
pickGamesButton: pickGamesButton,
|
117
|
+
updateInterfaceAfterGameRequestReceived: updateInterfaceAfterGameRequestReceived,
|
118
|
+
updateInterfaceBeforeStartGame: updateInterfaceBeforeStartGame,
|
119
|
+
updateInterfaceAfterFinishGame: updateInterfaceAfterFinishGame,
|
120
|
+
updateInterfaceOnInformationMessage: updateInterfaceOnInformationMessage,
|
121
|
+
generateDefaultGame: generateDefaultGame
|
122
|
+
};
|
123
|
+
|
124
|
+
}) (PRESENCE, jQuery);
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
////////////////////
|
129
|
+
//Interface Events
|
130
|
+
////////////////////
|
131
|
+
|
132
|
+
function play(){
|
133
|
+
$(".chat-gamesthick").css("display","block");
|
134
|
+
}
|
@@ -1,96 +1,218 @@
|
|
1
1
|
////////////////////
|
2
|
-
//Tres en Raya
|
2
|
+
// Tres en Raya //
|
3
3
|
////////////////////
|
4
4
|
|
5
5
|
PRESENCE.GAME.TER = (function(P,$,undefined){
|
6
6
|
|
7
|
-
//
|
8
|
-
var
|
9
|
-
|
10
|
-
//
|
11
|
-
|
7
|
+
//Gamecore
|
8
|
+
var CORE = P.GAME
|
9
|
+
|
10
|
+
//Games variables
|
11
|
+
var game; //Game and player are objects defined in the gamecore.
|
12
12
|
var player = null;
|
13
13
|
var currentPlayer = null;
|
14
|
-
|
14
|
+
var playing=true;
|
15
|
+
|
16
|
+
//We must define our ACTION object.
|
17
|
+
//The information exchanged between players is performed through the exchange of action type objects.
|
18
|
+
//We can define our own types of actions, with different fields
|
15
19
|
function action(player,square) {
|
16
20
|
this.player = player;
|
21
|
+
this.type = "general";
|
17
22
|
this.square = square;
|
18
23
|
}
|
19
|
-
|
20
|
-
|
24
|
+
|
21
25
|
//Html Divs
|
22
26
|
var divID = null;
|
23
27
|
var containerDivId = 'tresEnRayaContainerDivID';
|
24
28
|
var messageDivId = 'tresEnRayaMessageDivID';
|
25
29
|
|
26
|
-
//Boardgame
|
30
|
+
//Boardgame variables
|
27
31
|
var board = [];
|
28
32
|
var boardDimension = null;
|
29
33
|
var squareDimension = null;
|
30
34
|
var middleSquareDimension = null;
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
|
37
|
+
|
38
|
+
////////////////
|
39
|
+
// STARTER //
|
40
|
+
////////////////
|
41
|
+
//The core will invoke this method automatically to start the game.
|
42
|
+
//*myPlayer = myself
|
43
|
+
//*myGame = Game object (is the same for all players)
|
44
|
+
//*myDivID = Div to render the game
|
45
|
+
var init = function(myPlayer,myGame,myDivID){
|
46
|
+
player = myPlayer;
|
47
|
+
game = myGame;
|
48
|
+
divID = myDivID;
|
49
|
+
|
50
|
+
//Setting options
|
51
|
+
game.options = settingOptions(myGame.options);
|
52
|
+
|
53
|
+
//Init Graphics
|
41
54
|
drawBoard();
|
55
|
+
|
56
|
+
//Init Logic
|
42
57
|
settingBoard();
|
58
|
+
|
59
|
+
//Init Events
|
43
60
|
setBoardEvents();
|
44
|
-
|
45
|
-
|
61
|
+
|
62
|
+
//Init game variables
|
63
|
+
currentPlayer = game.players[0];
|
64
|
+
playing=true;
|
65
|
+
|
66
|
+
//Start Play!
|
67
|
+
if(player.id==currentPlayer.id){
|
46
68
|
showMessage("You start!")
|
47
69
|
} else {
|
48
|
-
showMessage(currentPlayer + " starts!")
|
70
|
+
showMessage(currentPlayer.name + " starts!")
|
49
71
|
}
|
50
72
|
};
|
51
73
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
74
|
+
|
75
|
+
//Set defaults for unspecified options
|
76
|
+
var settingOptions = function(myOptions){
|
77
|
+
|
78
|
+
if (!('theme' in myOptions)){
|
79
|
+
myOptions['theme'] = "Modern"
|
80
|
+
}
|
81
|
+
|
82
|
+
if (!('rounds' in myOptions)){
|
83
|
+
myOptions['rounds'] = "1"
|
56
84
|
}
|
57
85
|
|
58
|
-
//
|
59
|
-
|
60
|
-
|
86
|
+
//Apply default options for non specified opts.
|
87
|
+
return myOptions;
|
88
|
+
};
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
////////////////////////////////
|
93
|
+
// CORE CONFIG CALLBACKS //
|
94
|
+
////////////////////////////////
|
95
|
+
|
96
|
+
//Optional methods that can be invoked by the core
|
97
|
+
|
98
|
+
//The Core provides basic validation
|
99
|
+
//We can include our own validation conditions here!
|
100
|
+
//The core will invoke this method automatically in the validation process
|
101
|
+
var validateParams = function(myPlayer,myGame,myDivID){
|
102
|
+
if(myGame.players.lenght < 2){
|
103
|
+
return new CORE.createValidationResult(false,"This game needs two players at least");
|
61
104
|
}
|
105
|
+
return new CORE.createValidationResult(true,"Ok");
|
106
|
+
}
|
107
|
+
|
108
|
+
|
109
|
+
//MinimumRequirements to execute this game
|
110
|
+
var minimumRequirements = function(){
|
111
|
+
var requirements = new Array();
|
112
|
+
return requirements;
|
113
|
+
}
|
62
114
|
|
63
|
-
|
64
|
-
|
65
|
-
|
115
|
+
|
116
|
+
|
117
|
+
/////////////////////////////////
|
118
|
+
// GAMECORE CALLS & CALLBACKS // * To send our actions to other players we will use the << sendAction >> method.
|
119
|
+
///////////////////////////////// * When some player send us a action, the core will invoke the << onActionReceived >> method.
|
120
|
+
|
121
|
+
var sendAction = function(action){
|
122
|
+
CORE.sendAction(game.id,game.players,action)
|
123
|
+
return;
|
124
|
+
}
|
125
|
+
|
126
|
+
var onActionReceived = function(action){
|
127
|
+
processAction(action);
|
128
|
+
return;
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
/////////////////////////
|
134
|
+
// ACTION MANAGEMENT // * These methods are not mandatory, but are highly recommended.
|
135
|
+
////////////////////////
|
136
|
+
|
137
|
+
|
138
|
+
//Processes an action of any player
|
139
|
+
var processAction = function(action){
|
140
|
+
|
141
|
+
if(playing==false){
|
142
|
+
return
|
143
|
+
}
|
144
|
+
|
145
|
+
//Check if the action is legal.
|
146
|
+
if(!checkAction(action)){
|
147
|
+
showMessage("Ilegal action")
|
148
|
+
return false
|
149
|
+
}
|
150
|
+
|
151
|
+
if(player.id==action.player.id){
|
152
|
+
//Notify my actions!
|
153
|
+
sendAction(action)
|
66
154
|
}
|
67
155
|
|
68
|
-
//
|
69
|
-
|
156
|
+
//Update logic
|
157
|
+
updateLogic(action)
|
158
|
+
|
159
|
+
//Update Graphics
|
160
|
+
updateInterface(action)
|
161
|
+
|
162
|
+
//Check for winner
|
163
|
+
//If there is a winner, checkWinner() will return the winner's name.
|
164
|
+
//If not, it will return "finish" if the game is over without a winner, or null if the game is not over.
|
165
|
+
var winner = checkWinner()
|
166
|
+
if(winner!=null){
|
167
|
+
processWinner(winner)
|
168
|
+
finishGame()
|
169
|
+
return
|
170
|
+
}
|
171
|
+
|
172
|
+
//We continue with the next turn if the game is not over.
|
173
|
+
nextTurn();
|
174
|
+
}
|
175
|
+
|
176
|
+
|
177
|
+
//Check if the action is legal.
|
178
|
+
var checkAction = function(action){
|
179
|
+
|
180
|
+
if(currentPlayer.id!=action.player.id){
|
181
|
+
//The player has made an action out of his turn.
|
70
182
|
return false;
|
71
183
|
}
|
72
184
|
|
73
|
-
|
74
|
-
|
185
|
+
if(board[action.square][2]!=0){
|
186
|
+
//Square is already occupied by another figure.
|
75
187
|
return false;
|
76
188
|
}
|
77
189
|
|
78
|
-
return true;
|
190
|
+
return true;
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
//If we have a turn-based game we probably need a nextTurn method.
|
195
|
+
//This is an example
|
196
|
+
var nextTurn = function(){
|
197
|
+
var playersQuantity = game.players.length;
|
198
|
+
var indexActualPlayer = game.players.indexOf(currentPlayer);
|
199
|
+
if(indexActualPlayer==(playersQuantity-1)){
|
200
|
+
currentPlayer=game.players[0];
|
201
|
+
} else {
|
202
|
+
currentPlayer=game.players[indexActualPlayer+1];
|
203
|
+
}
|
204
|
+
if(player.id==currentPlayer.id){
|
205
|
+
showMessage("Is your turn!")
|
206
|
+
} else {
|
207
|
+
showMessage(currentPlayer.name + " turn")
|
208
|
+
}
|
79
209
|
}
|
80
210
|
|
81
|
-
var settingOptions = function(myOptions){
|
82
211
|
|
83
|
-
if (!('theme' in myOptions)){
|
84
|
-
myOptions['theme'] = "Modern"
|
85
|
-
}
|
86
212
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
//Apply default options for non specified opts.
|
92
|
-
return myOptions;
|
93
|
-
};
|
213
|
+
///////////////////////
|
214
|
+
// TER GAME METHODS //
|
215
|
+
///////////////////////
|
94
216
|
|
95
217
|
var drawBoard = function(){
|
96
218
|
var containerDiv = document.createElement('div');
|
@@ -101,14 +223,15 @@ PRESENCE.GAME.TER = (function(P,$,undefined){
|
|
101
223
|
var messageDiv = document.createElement('div');
|
102
224
|
messageDiv.setAttribute('id', messageDivId);
|
103
225
|
$(messageDiv).addClass('tresEnRayaMessageDivClass')
|
104
|
-
$(messageDiv).addClass('tresEnRayaMessageTheme' + options['theme'])
|
226
|
+
$(messageDiv).addClass('tresEnRayaMessageTheme' + game.options['theme'])
|
105
227
|
$("#" + divID).append(messageDiv);
|
106
228
|
|
107
229
|
var p = document.createElement('p');
|
108
230
|
p.setAttribute('id', messageDivId + "p");
|
109
|
-
$(p).addClass('tresEnRayaMessagePTheme' + options['theme'])
|
231
|
+
$(p).addClass('tresEnRayaMessagePTheme' + game.options['theme'])
|
110
232
|
$("#" + messageDivId).append(p);
|
111
233
|
|
234
|
+
var messageDivHeight = 12;
|
112
235
|
|
113
236
|
//Adjust dimensions
|
114
237
|
var parentWidth = $("#" + divID).width();
|
@@ -116,16 +239,18 @@ PRESENCE.GAME.TER = (function(P,$,undefined){
|
|
116
239
|
var maxDimension = 300;
|
117
240
|
var minDimension = 100;
|
118
241
|
|
119
|
-
var dimension = Math.min(parentWidth,parentHeight,maxDimension)
|
120
|
-
boardDimension =
|
242
|
+
var dimension = Math.max(Math.min(parentWidth,parentHeight,maxDimension),minDimension)
|
243
|
+
boardDimension = dimension - messageDivHeight;
|
121
244
|
|
122
245
|
$("#" + containerDivId).height(boardDimension)
|
123
246
|
$("#" + containerDivId).width(boardDimension);
|
247
|
+
$("#" + messageDivId).width(boardDimension);
|
124
248
|
|
125
249
|
//Apply Theme
|
126
|
-
$("#" + containerDivId).addClass('tresEnRayaContainerTheme' + options['theme'])
|
250
|
+
$("#" + containerDivId).addClass('tresEnRayaContainerTheme' + game.options['theme'])
|
127
251
|
};
|
128
252
|
|
253
|
+
|
129
254
|
var settingBoard = function(){
|
130
255
|
squareDimension = boardDimension/3;
|
131
256
|
middleSquareDimension = squareDimension/2;
|
@@ -141,9 +266,9 @@ PRESENCE.GAME.TER = (function(P,$,undefined){
|
|
141
266
|
board[8] = [boardDimension-middleSquareDimension,boardDimension-middleSquareDimension,0]
|
142
267
|
};
|
143
268
|
|
269
|
+
|
144
270
|
var setBoardEvents = function(){
|
145
271
|
$("#" + containerDivId).click(function (event) {
|
146
|
-
|
147
272
|
var offsetX = event.pageX - $("#" + containerDivId).offset().left
|
148
273
|
var offsetY = event.pageY - $("#" + containerDivId).offset().top
|
149
274
|
|
@@ -151,15 +276,17 @@ PRESENCE.GAME.TER = (function(P,$,undefined){
|
|
151
276
|
return;
|
152
277
|
}
|
153
278
|
|
154
|
-
if(currentPlayer!=player){
|
155
|
-
|
279
|
+
if(currentPlayer.id!=player.id){
|
280
|
+
return;
|
156
281
|
}
|
157
282
|
square = getSquare(offsetX,offsetY)
|
283
|
+
|
158
284
|
var actionNew = new action(currentPlayer,square);
|
159
285
|
processAction(actionNew)
|
160
286
|
});
|
161
287
|
};
|
162
288
|
|
289
|
+
|
163
290
|
var getSquare = function(x,y){
|
164
291
|
for(var i=0; i<board.length; i++){
|
165
292
|
if((Math.abs(x-board[i][0])<middleSquareDimension)&&(Math.abs(y-board[i][1])<middleSquareDimension)){
|
@@ -169,51 +296,6 @@ PRESENCE.GAME.TER = (function(P,$,undefined){
|
|
169
296
|
return 0;
|
170
297
|
}
|
171
298
|
|
172
|
-
|
173
|
-
var processAction = function(action){
|
174
|
-
|
175
|
-
if(playing==false){
|
176
|
-
return;
|
177
|
-
}
|
178
|
-
|
179
|
-
//Check if the action is legal
|
180
|
-
if(!checkAction(action)){
|
181
|
-
showMessage("Ilegal action");
|
182
|
-
return false;
|
183
|
-
}
|
184
|
-
|
185
|
-
if(player==currentPlayer){
|
186
|
-
//Notify action
|
187
|
-
sendAction(action);
|
188
|
-
}
|
189
|
-
|
190
|
-
|
191
|
-
//Update logic
|
192
|
-
updateLogic(action);
|
193
|
-
|
194
|
-
//Update interface
|
195
|
-
updateInterface(action);
|
196
|
-
|
197
|
-
//Check for winner
|
198
|
-
var winner = checkWinner()
|
199
|
-
if(winner!=null){
|
200
|
-
if(winner!="finish"){
|
201
|
-
if(player==winner){
|
202
|
-
showMessage("You have won the game")
|
203
|
-
} else {
|
204
|
-
showMessage(winner + " has won the game")
|
205
|
-
}
|
206
|
-
} else {
|
207
|
-
showMessage("Finished game");
|
208
|
-
}
|
209
|
-
finishGame();
|
210
|
-
return
|
211
|
-
}
|
212
|
-
|
213
|
-
nextTurn();
|
214
|
-
}
|
215
|
-
|
216
|
-
|
217
299
|
var showMessage = function(msg){
|
218
300
|
$("#" + messageDivId + "p").html(msg)
|
219
301
|
}
|
@@ -222,52 +304,43 @@ PRESENCE.GAME.TER = (function(P,$,undefined){
|
|
222
304
|
playing = false;
|
223
305
|
}
|
224
306
|
|
225
|
-
var checkAction = function(action){
|
226
|
-
if(board[action.square][2]!=0){
|
227
|
-
return false;
|
228
|
-
}
|
229
|
-
|
230
|
-
return true;
|
231
|
-
}
|
232
|
-
|
233
307
|
var updateLogic = function(action){
|
234
|
-
|
308
|
+
if(action.player.id == game.players[0].id){
|
309
|
+
var r = 1;
|
310
|
+
} else {
|
311
|
+
var r = 2;
|
312
|
+
}
|
313
|
+
board[action.square][2]=r;
|
235
314
|
}
|
236
315
|
|
237
316
|
var updateInterface = function(action){
|
238
317
|
var img = document.createElement('img');
|
239
318
|
|
240
|
-
if(action.player==players[0]){
|
319
|
+
if(action.player.id==game.players[0].id){
|
241
320
|
var figure = "circle";
|
242
321
|
} else {
|
243
322
|
var figure = "aspa";
|
244
323
|
}
|
245
324
|
|
246
|
-
|
247
|
-
|
325
|
+
var path = "/assets/games/ter/modern_circle.png"
|
326
|
+
$(img).attr("src","/assets/games/ter/" + game.options['theme'].toLowerCase() + "_" + figure + ".png");
|
248
327
|
$("#" + containerDivId).append(img);
|
249
|
-
$(img).addClass('tresEnRayaImgTheme' + options['theme'])
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
328
|
+
$(img).addClass('tresEnRayaImgTheme' + game.options['theme'])
|
329
|
+
|
330
|
+
//Calculate displacement
|
331
|
+
var figureSizePercent = 0.8;
|
332
|
+
var xdisplacement = -squareDimension*figureSizePercent/2*0.9;
|
333
|
+
var ydisplacement = 10;
|
334
|
+
|
335
|
+
$(img).width(squareDimension*figureSizePercent)
|
336
|
+
$(img).height(squareDimension*figureSizePercent)
|
337
|
+
$(img).css("top",board[action.square][1]+ydisplacement)
|
338
|
+
$(img).css("left",board[action.square][0]+xdisplacement)
|
256
339
|
return;
|
257
340
|
}
|
258
341
|
|
259
|
-
var sendAction = function(action){
|
260
|
-
//Notify action to other players
|
261
|
-
//[...]
|
262
|
-
return;
|
263
|
-
}
|
264
342
|
|
265
|
-
|
266
|
-
processAction(action);
|
267
|
-
return;
|
268
|
-
}
|
269
|
-
|
270
|
-
//Return winner's name if exists and null if dont exits.
|
343
|
+
//Return winner's name if exists and null if don't exits.
|
271
344
|
//Return "finish" when the game is blocked.
|
272
345
|
var checkWinner = function(){
|
273
346
|
|
@@ -288,97 +361,73 @@ PRESENCE.GAME.TER = (function(P,$,undefined){
|
|
288
361
|
|
289
362
|
//Check horizontal
|
290
363
|
if((board[0][2]==board[1][2])&&(board[1][2]==board[2][2])&&(board[2][2]!=0)){
|
291
|
-
return players[board[0][2]-1];
|
364
|
+
return game.players[board[0][2]-1];
|
292
365
|
}
|
293
366
|
if((board[3][2]==board[4][2])&&(board[4][2]==board[5][2])&&(board[5][2]!=0)){
|
294
|
-
return players[board[3][2]-1];
|
367
|
+
return game.players[board[3][2]-1];
|
295
368
|
}
|
296
369
|
if((board[6][2]==board[7][2])&&(board[7][2]==board[8][2])&&(board[8][2]!=0)){
|
297
|
-
return players[board[6][2]-1];
|
370
|
+
return game.players[board[6][2]-1];
|
298
371
|
}
|
299
372
|
|
300
373
|
//Check vertical
|
301
374
|
if((board[0][2]==board[3][2])&&(board[3][2]==board[6][2])&&(board[6][2]!=0)){
|
302
|
-
return players[board[0][2]-1];
|
375
|
+
return game.players[board[0][2]-1];
|
303
376
|
}
|
304
377
|
if((board[1][2]==board[4][2])&&(board[4][2]==board[7][2])&&(board[7][2]!=0)){
|
305
|
-
return players[board[1][2]-1];
|
378
|
+
return game.players[board[1][2]-1];
|
306
379
|
}
|
307
380
|
if((board[2][2]==board[5][2])&&(board[5][2]==board[8][2])&&(board[8][2]!=0)){
|
308
|
-
return players[board[2][2]-1];
|
381
|
+
return game.players[board[2][2]-1];
|
309
382
|
}
|
310
383
|
|
311
384
|
//Check diagonals
|
312
385
|
if((board[0][2]==board[4][2])&&(board[4][2]==board[8][2])&&(board[8][2]!=0)){
|
313
|
-
return players[board[0][2]-1];
|
386
|
+
return game.players[board[0][2]-1];
|
314
387
|
}
|
315
388
|
if((board[6][2]==board[4][2])&&(board[4][2]==board[2][2])&&(board[2][2]!=0)){
|
316
|
-
return players[board[6][2]-1];
|
389
|
+
return game.players[board[6][2]-1];
|
317
390
|
}
|
318
391
|
|
319
392
|
return null;
|
320
393
|
}
|
321
394
|
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
395
|
+
|
396
|
+
var processWinner = function(winner){
|
397
|
+
if(winner!="finish"){
|
398
|
+
if(player.id==winner.id){
|
399
|
+
showMessage("You have won the game")
|
400
|
+
} else {
|
401
|
+
showMessage(winner.name + " has won the game")
|
402
|
+
}
|
327
403
|
} else {
|
328
|
-
|
329
|
-
}
|
330
|
-
if(player==currentPlayer){
|
331
|
-
showMessage("Is your turn!")
|
332
|
-
} else {
|
333
|
-
showMessage(currentPlayer + " turn")
|
404
|
+
showMessage("Finished game");
|
334
405
|
}
|
335
406
|
}
|
336
407
|
|
337
|
-
var getRandomPlayer = function(){
|
338
|
-
var playersQuantity = players.length;
|
339
|
-
var randomIndex = Math.round(Math.random()*(players.length-1))
|
340
|
-
return players[randomIndex]
|
341
|
-
}
|
342
|
-
|
343
408
|
//Getters
|
344
|
-
var
|
345
|
-
return
|
409
|
+
var getGame = function(){
|
410
|
+
return game;
|
346
411
|
}
|
347
|
-
|
348
|
-
|
349
|
-
return
|
412
|
+
|
413
|
+
var getBoard = function(){
|
414
|
+
return board;
|
350
415
|
}
|
351
416
|
|
352
|
-
var
|
353
|
-
|
354
|
-
|
417
|
+
var getMyplayer = function(){
|
418
|
+
return player;
|
419
|
+
}
|
420
|
+
|
421
|
+
var getCurrentPlayer = function(){
|
422
|
+
return currentPlayer;
|
423
|
+
}
|
355
424
|
|
356
425
|
|
357
426
|
return {
|
358
427
|
init: init,
|
359
|
-
|
360
|
-
|
428
|
+
validateParams: validateParams,
|
429
|
+
minimumRequirements: minimumRequirements,
|
430
|
+
onActionReceived: onActionReceived
|
361
431
|
};
|
362
432
|
|
363
|
-
}) (PRESENCE, jQuery);
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
////////////////////
|
373
|
-
//Interface Events
|
374
|
-
////////////////////
|
375
|
-
function play(){
|
376
|
-
$(".chat-gamesthick").css("display","block");
|
377
|
-
}
|
378
|
-
|
379
|
-
function pickGamesButton(uiElement){
|
380
|
-
var slug = $(uiElement.element).attr("id");
|
381
|
-
//clickGamesButton(slug);
|
382
|
-
log("clickGamesButton(slug)" + slug)
|
383
|
-
}
|
384
|
-
|
433
|
+
}) (PRESENCE, jQuery);
|