... | ... |
@@ -111,9 +111,10 @@ if( isset($_GET['dc']) ) { |
111 | 111 |
* SI TOUT LE MONDE A DEJA JOUE |
112 | 112 |
*/ |
113 | 113 |
$nbDejaJoue = 0; |
114 |
- foreach($scJoueurs as $j) |
|
115 |
- if($scJoueurs->dernier_coup != "") |
|
114 |
+ foreach($scJoueurs as $j) { |
|
115 |
+ if($j->dernier_coup != "") |
|
116 | 116 |
$nbDejaJoue++; |
117 |
+ } |
|
117 | 118 |
|
118 | 119 |
if($nbDejaJoue == count($scJoueurs)) { |
119 | 120 |
// Extrait la 1ere tuile de la pioche |
... | ... |
@@ -6,7 +6,11 @@ class Database { |
6 | 6 |
|
7 | 7 |
public function __construct($dbfile) { |
8 | 8 |
$this->_dbfile = $dbfile; |
9 |
- $this->_dbcnx = new SQLite3($this->_dbfile); |
|
9 |
+ $this->_dbcnx = false; |
|
10 |
+ while(!$this->_dbcnx) { |
|
11 |
+ $this->_dbcnx = new SQLite3($this->_dbfile); |
|
12 |
+ $this->_dbcnx->busyTimeout(5000); |
|
13 |
+ } |
|
10 | 14 |
} |
11 | 15 |
|
12 | 16 |
public function req($req) { |
... | ... |
@@ -67,7 +67,7 @@ class JoueurInfos { |
67 | 67 |
if(!$this->_exist) return false; |
68 | 68 |
|
69 | 69 |
$plateauTxt = ''; |
70 |
- for($i = 0 ; $i < count($req['plateau']) ; $i++) { |
|
70 |
+ for($i = 0 ; $i < count($this->plateau) ; $i++) { |
|
71 | 71 |
if($i > 0) $plateauTxt .= ','; |
72 | 72 |
$plateauTxt .= $this->plateau[$i]; |
73 | 73 |
} |
... | ... |
@@ -85,7 +85,7 @@ class PartieInfos { |
85 | 85 |
if(!$this->_exist) return false; |
86 | 86 |
|
87 | 87 |
$piocheTxt = ''; |
88 |
- for($i = 0 ; $i < count($req['pioche']) ; $i++) { |
|
88 |
+ for($i = 0 ; $i < count($this->pioche) ; $i++) { |
|
89 | 89 |
if($i > 0) $piocheTxt .= ','; |
90 | 90 |
$piocheTxt .= $this->pioche[$i]; |
91 | 91 |
} |
... | ... |
@@ -148,8 +148,8 @@ var scInput_JeuNom = '<?php echo $jeuNom; ?>'; |
148 | 148 |
|
149 | 149 |
|
150 | 150 |
|
151 |
-<div class="bas-btn"> |
|
152 |
- <div class="bas-btn-terminer jeu-btn" id="basBoutons">Terminer la partie</div> |
|
151 |
+<div class="bas-btn" id="basBoutons"> |
|
152 |
+ <div class="bas-btn-terminer jeu-btn" id="basBoutonTerminer">Terminer la partie</div> |
|
153 | 153 |
</div> |
154 | 154 |
|
155 | 155 |
|
... | ... |
@@ -4,6 +4,7 @@ $(document).ready(function() { |
4 | 4 |
var scJoueurId = scInput_JoueurId; |
5 | 5 |
var lastData; |
6 | 6 |
|
7 |
+ var dejaJoue = false; |
|
7 | 8 |
|
8 | 9 |
function refreshScreen(data) { |
9 | 10 |
if(data['statut'] == 0) { |
... | ... |
@@ -115,31 +116,54 @@ $(document).ready(function() { |
115 | 116 |
} |
116 | 117 |
// PENDANT LA PARTIE |
117 | 118 |
else if(data['statut'] == 9) { |
118 |
- |
|
119 |
- } |
|
120 |
- // FIN DE PARTIE : statut > 10 |
|
121 |
- else { |
|
119 |
+ for(var i = 1 ; i <= 11 ; i++) { |
|
120 |
+ $('#PlateauCase_User' + scJoueurId + '_Temple' + i).removeClass('clickable'); |
|
121 |
+ $('#PlateauCase_User' + scJoueurId + '_Meeple' + i).removeClass('clickable'); |
|
122 |
+ } |
|
123 |
+ for(var i = 1 ; i <= 30 ; i++) |
|
124 |
+ $('#PlateauCase_User' + scJoueurId + '_Case' + i).addClass('clickable'); |
|
125 |
+ for(var i = 1 ; i <= 4 ; i++) { |
|
126 |
+ $('#AffMeeple_User' + scJoueurId + '_Meeple' + i).addClass('clickable'); |
|
127 |
+ $('#AffTemple_User' + scJoueurId + '_Temple' + i).addClass('clickable'); |
|
128 |
+ } |
|
122 | 129 |
|
123 |
- } |
|
124 | 130 |
|
125 | 131 |
|
132 |
+ // AFFICHAGE DES INFOS |
|
133 |
+ if(!dejaJoue && data['joueur'][scJoueurId]['dernier_coup'].length > 0) { |
|
134 |
+ $('#zoneInfosTuile_tuile').html('<img src="src/ok.png" />'); |
|
135 |
+ dejaJoue = true; |
|
136 |
+ } |
|
137 |
+ |
|
138 |
+ if( ( !lastData || lastData['statut'] < 9 || dejaJoue ) && data['joueur'][scJoueurId]['dernier_coup'].length == 0 ) { |
|
139 |
+ dejaJoue = false; |
|
140 |
+ var pioche = data['pioche']; |
|
141 |
+ var pepite = pioche[pioche.length - 1]; |
|
142 |
+ if(pepite == 'o' ||pepite == 'd') |
|
143 |
+ pioche = pioche.substring(0, pioche.length - 1); |
|
144 |
+ else |
|
145 |
+ pepite = ''; |
|
146 |
+ $('#zoneInfosTuile_tuile').html('<img src="src/tuile_' + pioche + '.png" />'); |
|
147 |
+ if(pepite != "") |
|
148 |
+ $('#zoneInfosTuile_tuile').append('<img src="src/tuile_' + pepite + '.png" />'); |
|
149 |
+ } |
|
150 |
+ |
|
151 |
+ $('#zoneInfosReste').html( 'Reste : ' + data['nbpioche'] ); |
|
152 |
+ for(var t = 0 ; t < 4 ; t++) |
|
153 |
+ $('#zoneInfosTemple' + (t + 1)).html( data['tresor'][t] ); |
|
154 |
+ |
|
126 | 155 |
|
127 | 156 |
|
128 |
- if( !lastData || data['pioche'] != lastData['pioche'] ) { |
|
129 |
- var pioche = data['pioche']; |
|
130 |
- var pepite = pioche[pioche.length - 1]; |
|
131 |
- if(pepite == 'o' ||pepite == 'd') |
|
132 |
- pioche = pioche.substring(0, pioche.length - 1); |
|
133 |
- else |
|
134 |
- pepite = ''; |
|
135 |
- $('#zoneInfosTuile_tuile').html('<img src="src/tuile_' + pioche + '.png" />'); |
|
136 |
- if(pepite != "") |
|
137 |
- $('#zoneInfosTuile_tuile').append('<img src="src/tuile_' + pepite + '.png" />'); |
|
157 |
+ |
|
158 |
+ } |
|
159 |
+ // FIN DE PARTIE : statut > 10 |
|
160 |
+ else if(data['statut'] >= 10) { |
|
161 |
+ |
|
162 |
+ $('#finPartie').fadeIn(); |
|
163 |
+ |
|
138 | 164 |
} |
139 | 165 |
|
140 |
- $('#zoneInfosReste').html( 'Reste : ' + data['nbpioche'] ); |
|
141 |
- for(var t = 0 ; t < 4 ; t++) |
|
142 |
- $('#zoneInfosTemple' + (t + 1)).html( data['tresor'][t] ); |
|
166 |
+ |
|
143 | 167 |
|
144 | 168 |
|
145 | 169 |
|
... | ... |
@@ -151,9 +175,17 @@ $(document).ready(function() { |
151 | 175 |
function refresh() { |
152 | 176 |
$.get('backend/jeu.php?j=' + scJoueurId) |
153 | 177 |
.done(function(data, text, jqxhr) { |
154 |
- refreshScreen( JSON.parse(jqxhr.responseText) ); |
|
178 |
+ try { |
|
179 |
+ var JsonResponse = JSON.parse(jqxhr.responseText); |
|
180 |
+ refreshScreen( JsonResponse ); |
|
181 |
+ } |
|
182 |
+ catch(error) { |
|
183 |
+// alert(jqxhr.responseText); |
|
184 |
+ console.log("TRY JSON PARSE : --- " + jqxhr.responseText + " --- " + error); |
|
185 |
+ } |
|
155 | 186 |
}) |
156 | 187 |
.fail(function(jqxhr){ |
188 |
+ console.log("BACKEND REFRESH : " + jqxhr.responseText); |
|
157 | 189 |
// alert(jqxhr.responseText); |
158 | 190 |
}) |
159 | 191 |
.always(function(){ |
... | ... |
@@ -174,7 +206,12 @@ $(document).ready(function() { |
174 | 206 |
* CLICKS |
175 | 207 |
*/ |
176 | 208 |
|
209 |
+ var meepleSelected = 0; |
|
210 |
+ |
|
177 | 211 |
$('.zone-moi-plateau table tr td').on('click', function(e) { |
212 |
+ if(dejaJoue) return; |
|
213 |
+ if(lastData['statut'] > 9) return; |
|
214 |
+ |
|
178 | 215 |
var ReadID = $(this).attr('id'); |
179 | 216 |
if(!ReadID) return; |
180 | 217 |
ReadID = ReadID.substring('PlateauCase_User'.length); |
... | ... |
@@ -197,6 +234,7 @@ $(document).ready(function() { |
197 | 234 |
}) |
198 | 235 |
.fail(function(jqxhr){ |
199 | 236 |
// alert(jqxhr.responseText); |
237 |
+ console.log("BACKEND TEMPLE : " + jqxhr.responseText); |
|
200 | 238 |
}) |
201 | 239 |
.always(function(){ |
202 | 240 |
|
... | ... |
@@ -210,6 +248,7 @@ $(document).ready(function() { |
210 | 248 |
|
211 | 249 |
}) |
212 | 250 |
.fail(function(jqxhr){ |
251 |
+ console.log("BACKEND MEEPLE : " + jqxhr.responseText); |
|
213 | 252 |
// alert(jqxhr.responseText); |
214 | 253 |
}) |
215 | 254 |
.always(function(){ |
... | ... |
@@ -222,10 +261,174 @@ $(document).ready(function() { |
222 | 261 |
* PENDANT LA PARTIE : JOUER UN COUP |
223 | 262 |
*/ |
224 | 263 |
else if(lastData['statut'] == 9) { |
264 |
+ |
|
265 |
+ meepleSelectId = caseHasMeeple(InfoType, InfoID); |
|
266 |
+ |
|
267 |
+ // => CASE VIDE : DEPOSER LA TUILER |
|
268 |
+ if(InfoType == 'c' && lastData['joueur'][scJoueurId]['plateau'][InfoID - 1].length == 0 && !meepleSelectId) { |
|
269 |
+ if(meepleSelected > 0) $('#SelectionMeeple' + meepleSelected).remove(); |
|
270 |
+ meepleSelected = 0; |
|
271 |
+ $.get('backend/jeu.php?j=' + scJoueurId + '&dc=c' + InfoID) |
|
272 |
+ .done(function(data, text, jqxhr) { |
|
273 |
+ $('#zoneInfosTuile_tuile').html('<img src="src/ok.png" />'); |
|
274 |
+ $('#PlateauCase_User' + scJoueurId + '_Case' + InfoID).append('<img src="src/tuile_' + lastData['pioche'] + '.png" style="opacity: 0.5" />'); |
|
275 |
+ dejaJoue = true; |
|
276 |
+ }) |
|
277 |
+ .fail(function(jqxhr){ |
|
278 |
+ console.log("BACKEND DC=C : " + jqxhr.responseText); |
|
279 |
+ // alert(jqxhr.responseText); |
|
280 |
+ }) |
|
281 |
+ .always(function(){ |
|
282 |
+ |
|
283 |
+ }); |
|
284 |
+ } |
|
285 |
+ |
|
286 |
+ // => CASE AVEC MEEPLE : LE SELECTIONNER |
|
287 |
+ else if(meepleSelectId) { |
|
288 |
+ if(meepleSelected > 0) $('#SelectionMeeple' + meepleSelected).remove(); |
|
289 |
+ $('#AffMeeple_User' + scJoueurId + '_Meeple' + meepleSelectId).parent().append('<img src="src/selection.png" id="SelectionMeeple' + meepleSelectId + '" />'); |
|
290 |
+ meepleSelected = meepleSelectId; |
|
291 |
+ } |
|
292 |
+ |
|
293 |
+ // => MEEPLE SELECTED vers CASE VIDE OU TEMPLE : BOUGER LE MEEPLE |
|
294 |
+ else if(meepleSelected) { |
|
295 |
+ if(InfoType == 'c' && lastData['joueur'][scJoueurId]['plateau'][InfoID - 1].length > 0) { |
|
296 |
+ |
|
297 |
+ if(meepleSelected > 0) $('#SelectionMeeple' + meepleSelected).remove(); |
|
298 |
+ tempMeepleSelected = meepleSelected; |
|
299 |
+ meepleSelected = 0; |
|
300 |
+ $.get('backend/jeu.php?j=' + scJoueurId + '&dc=m' + tempMeepleSelected + 'c' + InfoID) |
|
301 |
+ .done(function(data, text, jqxhr) { |
|
302 |
+ $('#zoneInfosTuile_tuile').html('<img src="src/ok.png" />'); |
|
303 |
+ $('#PlateauCase_User' + scJoueurId + '_Case' + InfoID).append('<img src="src/meeple' + tempMeepleSelected + '_vide.png" />'); |
|
304 |
+ dejaJoue = true; |
|
305 |
+ }) |
|
306 |
+ .fail(function(jqxhr){ |
|
307 |
+ console.log("BACKEND DC=C : " + jqxhr.responseText); |
|
308 |
+ // alert(jqxhr.responseText); |
|
309 |
+ }) |
|
310 |
+ .always(function(){ |
|
311 |
+ |
|
312 |
+ }); |
|
313 |
+ |
|
314 |
+ } |
|
315 |
+ else if(InfoType == 't') { |
|
316 |
+ templeSelectId = caseHasTemple(InfoID); |
|
317 |
+ if(templeSelectId == meepleSelected) { |
|
318 |
+ |
|
319 |
+ if(meepleSelected > 0) $('#SelectionMeeple' + meepleSelected).remove(); |
|
320 |
+ tempMeepleSelected = meepleSelected; |
|
321 |
+ meepleSelected = 0; |
|
322 |
+ $.get('backend/jeu.php?j=' + scJoueurId + '&dc=m' + tempMeepleSelected + 't' + InfoID) |
|
323 |
+ .done(function(data, text, jqxhr) { |
|
324 |
+ $('#zoneInfosTuile_tuile').html('<img src="src/ok.png" />'); |
|
325 |
+ $('#PlateauCase_User' + scJoueurId + '_Temple' + InfoID).append('<img src="src/meeple' + tempMeepleSelected + '_vide.png" />'); |
|
326 |
+ dejaJoue = true; |
|
327 |
+ }) |
|
328 |
+ .fail(function(jqxhr){ |
|
329 |
+ console.log("BACKEND DC=C : " + jqxhr.responseText); |
|
330 |
+ // alert(jqxhr.responseText); |
|
331 |
+ }) |
|
332 |
+ .always(function(){ |
|
333 |
+ |
|
334 |
+ }); |
|
335 |
+ |
|
336 |
+ |
|
337 |
+ } |
|
338 |
+ } |
|
339 |
+ } |
|
340 |
+ |
|
341 |
+ } |
|
342 |
+ }); |
|
343 |
+ |
|
344 |
+ function caseHasMeeple(type, id) { |
|
345 |
+ if(type == 't') return false; |
|
346 |
+ |
|
347 |
+ var position = parseInt(id); |
|
348 |
+ if(type == 'm') position += 100; |
|
349 |
+ |
|
350 |
+ for(var i = 0 ; i < lastData['joueur'][scJoueurId]['meeple'].length ; i++) |
|
351 |
+ if( lastData['joueur'][scJoueurId]['meeple'][i] == position ) return (i + 1); |
|
352 |
+ |
|
353 |
+ return false; |
|
354 |
+ } |
|
355 |
+ |
|
356 |
+ function caseHasTemple(id) { |
|
357 |
+ for(var i = 0 ; i < lastData['joueur'][scJoueurId]['temple'].length ; i++) |
|
358 |
+ if( lastData['joueur'][scJoueurId]['temple'][i] == id ) return (i + 1); |
|
359 |
+ |
|
360 |
+ return false; |
|
361 |
+ } |
|
362 |
+ |
|
363 |
+ |
|
364 |
+ |
|
365 |
+ |
|
366 |
+ var actionJeter = false; |
|
367 |
+ |
|
368 |
+ // Click sur la pioche : Action jeter |
|
369 |
+ $('#zoneInfosTuile').on('click', function(e) { |
|
370 |
+ if(dejaJoue) return; |
|
371 |
+ |
|
372 |
+ if(actionJeter) { |
|
373 |
+ actionJeter = false; |
|
374 |
+ $('#zoneInfosTuile_jeter').hide(); |
|
375 |
+ if(meepleSelected > 0) $('#SelectionMeeple' + meepleSelected).remove(); |
|
376 |
+ meepleSelected = 0; |
|
377 |
+ $.get('backend/jeu.php?j=' + scJoueurId + '&dc=p') |
|
378 |
+ .done(function(data, text, jqxhr) { |
|
379 |
+ $('#zoneInfosTuile_tuile').html('<img src="src/ok.png" />'); |
|
380 |
+ dejaJoue = true; |
|
381 |
+ }) |
|
382 |
+ .fail(function(jqxhr){ |
|
383 |
+ console.log("BACKEND DC=P : " + jqxhr.responseText); |
|
384 |
+ // alert(jqxhr.responseText); |
|
385 |
+ }) |
|
386 |
+ .always(function(){ |
|
387 |
+ |
|
388 |
+ }); |
|
225 | 389 |
} |
390 |
+ else { |
|
391 |
+ $('#zoneInfosTuile_jeter').fadeIn(); |
|
392 |
+ actionJeter = true; |
|
393 |
+ } |
|
394 |
+ }); |
|
395 |
+ |
|
396 |
+ $('#zoneInfosTuile').on('mouseleave', function(e) { |
|
397 |
+ $('#zoneInfosTuile_jeter').fadeOut(); |
|
398 |
+ actionJeter = false; |
|
399 |
+ }); |
|
226 | 400 |
|
227 | 401 |
|
402 |
+ |
|
403 |
+ |
|
404 |
+ |
|
405 |
+ /* |
|
406 |
+ * BOUTON FIN DE PARTIE / NOUVELLE PARTIE |
|
407 |
+ */ |
|
408 |
+ function nouvellePartie() { |
|
409 |
+ $.get('backend/jeu.php?j=' + scJoueurId + '&new=1') |
|
410 |
+ .done(function(data, text, jqxhr) { |
|
411 |
+ |
|
412 |
+ }) |
|
413 |
+ .fail(function(jqxhr){ |
|
414 |
+ console.log("BACKEND NEW : " + jqxhr.responseText); |
|
415 |
+// alert(jqxhr.responseText); |
|
416 |
+ }) |
|
417 |
+ .always(function(){ |
|
418 |
+ |
|
419 |
+ }); |
|
420 |
+ |
|
421 |
+ } |
|
422 |
+ |
|
423 |
+ $('#finPartieBtn').on('click', function(e) { |
|
424 |
+ nouvellePartie(); |
|
425 |
+ }); |
|
426 |
+ |
|
427 |
+ $('#basBoutonTerminer').on('click', function(e) { |
|
428 |
+ nouvellePartie(); |
|
228 | 429 |
}); |
229 | 430 |
|
431 |
+ |
|
432 |
+ |
|
230 | 433 |
}); |
231 | 434 |
})(jQuery); |