Browse code

Systeme d'affichage fait

schardon authored on 25/04/2020 20:29:35
Showing 4 changed files
... ...
@@ -23,6 +23,9 @@ if( isset($_GET['new']) ) {
23 23
  * POSITIONNER UN MEEPLE
24 24
  */
25 25
 if( isset($_GET['meeple']) ) {
26
+  if($scPartie->statut % 2 != 1 && $scPartie->statut >= 9)
27
+    exit();
28
+
26 29
   $meepleId = ($scPartie->statut + 1) / 2;
27 30
   $db->req("UPDATE joueurs SET position_meeple".$meepleId."=".(100 + intval($_GET['meeple']))." WHERE partie_id=".$scPartie->id." AND statut>0;");
28 31
   $db->req("UPDATE parties SET statut=(statut+1) WHERE id=".$scPartie->id.";");
... ...
@@ -33,6 +36,9 @@ if( isset($_GET['meeple']) ) {
33 36
  * POSITIONNER UN TEMPLE
34 37
  */
35 38
 if( isset($_GET['temple']) ) {
39
+  if($scPartie->statut % 2 != 0 && $scPartie->statut >= 9)
40
+    exit();
41
+
36 42
   $templeId = $scPartie->statut / 2;
37 43
   $db->req("UPDATE joueurs SET position_temple".$templeId."=".intval($_GET['temple'])." WHERE partie_id=".$scPartie->id." AND statut>0;");
38 44
   $db->req("UPDATE parties SET statut=(statut+1) WHERE id=".$scPartie->id.";");
... ...
@@ -160,8 +166,8 @@ function JsonTab($data) {
160 166
 
161 167
 // Affiche les infos d'un joueur
162 168
 function JsonJoueur($j) {
163
-  $echoreturn = '{';
164
-  $echoreturn .= '"id":'.$j->id.', ';
169
+  $echoreturn = '"'.$j->id.'":{';
170
+//  $echoreturn .= '"id":'.$j->id.', ';
165 171
   $echoreturn .= '"tresor":'.JsonTab($j->tresor).', ';
166 172
   $echoreturn .= '"diamant":'.$j->diamant.', ';
167 173
   $echoreturn .= '"or":'.$j->or.', ';
... ...
@@ -182,11 +188,11 @@ echo '"nbpioche":'.(count($scPartie->pioche) - 1).', ';
182 188
 echo '"tresor":'.JsonTab( $scPartie->nextTresor() ).', ';
183 189
 
184 190
 //  * Joueurs
185
-echo '"joueur":[';
191
+echo '"joueur":{';
186 192
 echo JsonJoueur( $scMoi );
187 193
 foreach($scJoueurs as $j)
188 194
   echo ', '.JsonJoueur($j);
189
-echo ']';
195
+echo '}';
190 196
 
191 197
 echo '}';
192 198
 // Fin du JSON
... ...
@@ -159,14 +159,22 @@ table.plateau tr td img {
159 159
 }
160 160
 
161 161
 .zone-moi-infos-temple1 {
162
+  position: absolute;
163
+  top: 0;
164
+  left: 0;
165
+  color: #55a;
162 166
 }
163 167
 .zone-moi-infos-temple2 {
168
+  color: #882;
164 169
 }
165 170
 .zone-moi-infos-temple3 {
171
+  color: #a22;
166 172
 }
167 173
 .zone-moi-infos-temple4 {
174
+  color: #a5a;
168 175
 }
169 176
 
177
+
170 178
 /*
171 179
  * MON PLATEAU
172 180
  */
... ...
@@ -180,6 +188,7 @@ table.plateau tr td img {
180 188
 .zone-moi-plateau table.plateau {
181 189
 }
182 190
 
191
+.zone-moi-infos .nbr-infos,
183 192
 .zone-moi-plateau .nbr-infos,
184 193
 .zone-moi-plateau .calcul-total {
185 194
   font-size: 200%;
... ...
@@ -135,7 +135,7 @@ var scInput_JeuNom = '<?php echo $jeuNom; ?>';
135 135
       </tr>
136 136
       <?php for($i = 1 ; $i <= 4 ; $i++) { ?>
137 137
       <tr>
138
-        <td><img src="src/temple<?php echo $i; ?>.png" /><div class="zone-moi-infos-temple<?php echo $i; ?>" id="zoneInfosTemple<?php echo $i; ?>"></div></td>
138
+        <td><img src="src/temple<?php echo $i; ?>.png" /><div class="zone-moi-infos-temple<?php echo $i; ?> nbr-infos" id="zoneInfosTemple<?php echo $i; ?>"></div></td>
139 139
       </tr>
140 140
       <?php } ?>
141 141
     </table>
... ...
@@ -2,6 +2,7 @@
2 2
 $(document).ready(function() {
3 3
 
4 4
   var scJoueurId = scInput_JoueurId;
5
+  var lastData;
5 6
 
6 7
 
7 8
   function refreshScreen(data) {
... ...
@@ -10,6 +11,141 @@ $(document).ready(function() {
10 11
     }
11 12
 
12 13
 
14
+    for(var j in data['joueur']) {
15
+
16
+
17
+      /*
18
+       * AFFICHAGE DES TEMPLES
19
+       */
20
+      for(var t = 0 ; t < data['joueur'][j]['temple'].length ; t++) {
21
+        if( ( !lastData || data['joueur'][j]['temple'][t] != lastData['joueur'][j]['temple'][t] ) && data['joueur'][j]['temple'][t] > 0 ) {
22
+          // Supprime l'ancien Temple
23
+          $('#AffTemple_User' + j + '_Temple' + (t + 1)).remove();
24
+          // Affiche le Temple a la nouvelle position
25
+          mInfo = data['joueur'][j]['temple'][t];
26
+          $('#PlateauCase_User' + j + '_Temple' + mInfo).append('<img src="src/temple' + (t + 1) + '.png" id="AffTemple_User' + j + '_Temple' + (t + 1) + '" />');
27
+        }
28
+      }
29
+
30
+
31
+      /*
32
+       * AFFICHAGE DES TUILES
33
+       */
34
+      for(var t = 0 ; t < data['joueur'][j]['plateau'].length ; t++) {
35
+        if( ( !lastData || data['joueur'][j]['plateau'][t] != lastData['joueur'][j]['plateau'][t] ) && data['joueur'][j]['plateau'][t] != "" ) {
36
+          var caseInfo = data['joueur'][j]['plateau'][t];
37
+          var pepite = caseInfo[caseInfo.length - 1];
38
+          if(pepite == 'o' ||pepite == 'd')
39
+            caseInfo = caseInfo.substring(0, caseInfo.length - 1);
40
+          else
41
+            pepite = '';
42
+          $('#PlateauCase_User' + j + '_Case' + (t + 1)).html('<img src="src/tuile_' + caseInfo + '.png" />');
43
+          if(pepite != "")
44
+            $('#PlateauCase_User' + j + '_Case' + (t + 1)).append('<img src="src/tuile_' + pepite + '.png" />');
45
+        }
46
+      }
47
+
48
+
49
+      /*
50
+       * AFFICHAGE DES MEEPLES
51
+       */
52
+      for(var m = 0 ; m < data['joueur'][j]['meeple'].length ; m++) {
53
+        if( ( !lastData || data['joueur'][j]['meeple'][m] != lastData['joueur'][j]['meeple'][m] ) && data['joueur'][j]['meeple'][m] > 0 ) {
54
+          // Supprime l'ancien Meeple
55
+          $('#AffMeeple_User' + j + '_Meeple' + (m + 1)).remove();
56
+          // Affiche le Meeple a la nouvelle position
57
+          mInfo = data['joueur'][j]['meeple'][m];
58
+          if(mInfo >= 200)
59
+            $('#PlateauCase_User' + j + '_Temple' + (mInfo - 200)).append('<img src="src/meeple' + (m + 1) + '.png" id="AffMeeple_User' + j + '_Meeple' + (m + 1) + '" />');
60
+          else if(mInfo >= 100)
61
+            $('#PlateauCase_User' + j + '_Meeple' + (mInfo - 100)).append('<img src="src/meeple' + (m + 1) + '.png" id="AffMeeple_User' + j + '_Meeple' + (m + 1) + '" />');
62
+          else
63
+            $('#PlateauCase_User' + j + '_Case' + mInfo).append('<img src="src/meeple' + (m + 1) + '.png" id="AffMeeple_User' + j + '_Meeple' + (m + 1) + '" />');
64
+        }
65
+      }
66
+
67
+
68
+      /*
69
+       * AFFICHAGE DES INFOS
70
+       */
71
+      var total = 0;
72
+
73
+      for(var i = 0 ; i < data['joueur'][j]['tresor'].length ; i++) {
74
+        $('#Plateau_User' + j + '_Temple' + (i + 1) + 'Nbr').html( data['joueur'][j]['tresor'][i] );
75
+        total += parseInt( data['joueur'][j]['tresor'][i] );
76
+      }
77
+
78
+      $('#Plateau_User' + j + '_OrNbr').html( data['joueur'][j]['or'] );
79
+      total += parseInt( data['joueur'][j]['or'] * 2 );
80
+
81
+      $('#Plateau_User' + j + '_DiamantNbr').html( data['joueur'][j]['diamant'] );
82
+      total += parseInt( data['joueur'][j]['diamant'] );
83
+
84
+      $('#Plateau_User' + j + '_TotalNbr').html( total );
85
+
86
+      if(j != scJoueurId) {
87
+        if( !lastData || data['joueur'][j]['dernier_coup'] != lastData['joueur'][j]['dernier_coup'] ) {
88
+          if(data['joueur'][j]['dernier_coup'].length > 0)
89
+            $('#Plateau_User' + j + '_Joue').html('<img src="src/ok.png" />');
90
+          else
91
+            $('#Plateau_User' + j + '_Joue').empty;
92
+        }
93
+      }
94
+
95
+
96
+    } // FIN BOUCLE : REFRESH DES ECRANS DE CHAQUE JOUEUR
97
+
98
+
99
+    // ETAPES INITIALES DE POSITIONNEMENT DES MEEPLES & TEMPLES
100
+    if(data['statut'] > 0 && data['statut'] < 9 && (!lastData || data['statut'] != lastData['statut']) ) {
101
+      if(data['statut'] % 2 == 0) {
102
+        $('#zoneInfosTuile_tuile').html('<img src="src/temple' + (data['statut'] / 2) + '.png" />');
103
+        for(var i = 1 ; i <= 11 ; i++) {
104
+          $('#PlateauCase_User' + scJoueurId + '_Temple' + i).addClass('clickable');
105
+          $('#PlateauCase_User' + scJoueurId + '_Meeple' + i).removeClass('clickable');
106
+        }
107
+      }
108
+      else {
109
+        $('#zoneInfosTuile_tuile').html('<img src="src/meeple' + (Math.floor(data['statut'] / 2) + 1) + '.png" />');
110
+        for(var i = 1 ; i <= 11 ; i++) {
111
+          $('#PlateauCase_User' + scJoueurId + '_Meeple' + i).addClass('clickable');
112
+          $('#PlateauCase_User' + scJoueurId + '_Temple' + i).removeClass('clickable');
113
+        }
114
+      }
115
+    }
116
+    // PENDANT LA PARTIE
117
+    else if(data['statut'] == 9) {
118
+      
119
+    }
120
+    // FIN DE PARTIE : statut > 10
121
+    else {
122
+
123
+    }
124
+
125
+
126
+
127
+
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" />');
138
+    }
139
+
140
+    $('#zoneInfosReste').html( 'Reste : ' + data['nbpioche'] );
141
+    for(var t = 0 ; t < 4 ; t++)
142
+      $('#zoneInfosTemple' + (t + 1)).html( data['tresor'][t] );
143
+
144
+
145
+
146
+
147
+
148
+    lastData = data;
13 149
   }
14 150
 
15 151
   function refresh() {
... ...
@@ -33,5 +169,63 @@ $(document).ready(function() {
33 169
 
34 170
 
35 171
 
172
+
173
+  /*
174
+   * CLICKS
175
+   */
176
+
177
+  $('.zone-moi-plateau table tr td').on('click', function(e) {
178
+    var ReadID = $(this).attr('id');
179
+    if(!ReadID) return;
180
+    ReadID = ReadID.substring('PlateauCase_User'.length);
181
+    var UserID = ReadID.substring(0, ReadID.indexOf('_'));
182
+    var InfoType = ReadID.substring(ReadID.indexOf('_') + 1);
183
+    var InfoID = 0;
184
+    if(InfoType.substring(0, 'Case'.length) == 'Case') { InfoID = InfoType.substring('Case'.length); InfoType = 'c'; }
185
+    else if(InfoType.substring(0, 'Temple'.length) == 'Temple') { InfoID = InfoType.substring('Temple'.length); InfoType = 't'; }
186
+    else if(InfoType.substring(0, 'Meeple'.length) == 'Meeple') { InfoID = InfoType.substring('Meeple'.length); InfoType = 'm'; }
187
+
188
+    /*
189
+     * DEBUT DE PARTIE : CHOIX DES POSITIONS DES TEMPLES ET MEEPLES
190
+     */
191
+    if(lastData['statut'] > 0 && lastData['statut'] < 9) {
192
+      if(lastData['statut'] % 2 == 0) {
193
+        if(InfoType == 't') {
194
+          $.get('backend/jeu.php?j=' + scJoueurId + '&temple=' + InfoID)
195
+            .done(function(data, text, jqxhr) {
196
+
197
+            })
198
+            .fail(function(jqxhr){
199
+      //        alert(jqxhr.responseText);
200
+            })
201
+            .always(function(){
202
+
203
+            });
204
+        }
205
+      }
206
+      else {
207
+        if(InfoType == 'm') {
208
+          $.get('backend/jeu.php?j=' + scJoueurId + '&meeple=' + InfoID)
209
+            .done(function(data, text, jqxhr) {
210
+
211
+            })
212
+            .fail(function(jqxhr){
213
+      //        alert(jqxhr.responseText);
214
+            })
215
+            .always(function(){
216
+
217
+            });
218
+        }
219
+      }
220
+    }
221
+    /*
222
+     * PENDANT LA PARTIE : JOUER UN COUP
223
+     */
224
+    else if(lastData['statut'] == 9) {
225
+    }
226
+
227
+
228
+  });
229
+
36 230
 });
37 231
 })(jQuery);