Browse code

Ajout de la liste des tuiles restantes

schardon authored on 02/05/2020 14:50:50
Showing 1 changed files
... ...
@@ -182,6 +182,8 @@ echo '"pioche":"'.$scPartie->pioche[0].'", ';
182 182
 echo '"nbpioche":'.(count($scPartie->pioche) - 1).', ';
183 183
 echo '"tresor":'.JsonTab( $scPartie->nextTresor() ).', ';
184 184
 
185
+echo '"tuilesrestantes":{'.$scPartie->tuilesRestantesJson().'}, ';
186
+
185 187
 //  * Joueurs
186 188
 echo '"joueur":{';
187 189
 echo JsonJoueur( $scMoi );
Browse code

Passage en MySQL

schardon authored on 01/05/2020 17:19:57
Showing 1 changed files
... ...
@@ -11,8 +11,8 @@ if( !$scMoi->exist() )
11 11
  * LANCER UNE NOUVELLE PARTIE
12 12
  */
13 13
 if( isset($_GET['new']) ) {
14
-  $db->req("UPDATE parties SET statut=0 WHERE id=".$scPartie->id.";");
15
-  $db->req("UPDATE joueurs SET statut=0 WHERE partie_id=".$scPartie->id.";");
14
+  $db->req("UPDATE ".$__CONF['dbtablepre']."parties SET statut=0 WHERE id=".$scPartie->id.";");
15
+  $db->req("UPDATE ".$__CONF['dbtablepre']."joueurs SET statut=0 WHERE partie_id=".$scPartie->id.";");
16 16
   exit();
17 17
 }
18 18
 
... ...
@@ -24,8 +24,8 @@ if( isset($_GET['meeple']) ) {
24 24
     exit();
25 25
 
26 26
   $meepleId = ($scPartie->statut + 1) / 2;
27
-  $db->req("UPDATE joueurs SET position_meeple".$meepleId."=".(100 + intval($_GET['meeple']))." WHERE partie_id=".$scPartie->id." AND statut>0;");
28
-  $db->req("UPDATE parties SET statut=(statut+1) WHERE id=".$scPartie->id.";");
27
+  $db->req("UPDATE ".$__CONF['dbtablepre']."joueurs SET position_meeple".$meepleId."=".(100 + intval($_GET['meeple']))." WHERE partie_id=".$scPartie->id." AND statut>0;");
28
+  $db->req("UPDATE ".$__CONF['dbtablepre']."parties SET statut=(statut+1) WHERE id=".$scPartie->id.";");
29 29
   exit();
30 30
 }
31 31
 
... ...
@@ -37,8 +37,8 @@ if( isset($_GET['temple']) ) {
37 37
     exit();
38 38
 
39 39
   $templeId = $scPartie->statut / 2;
40
-  $db->req("UPDATE joueurs SET position_temple".$templeId."=".intval($_GET['temple'])." WHERE partie_id=".$scPartie->id." AND statut>0;");
41
-  $db->req("UPDATE parties SET statut=(statut+1) WHERE id=".$scPartie->id.";");
40
+  $db->req("UPDATE ".$__CONF['dbtablepre']."joueurs SET position_temple".$templeId."=".intval($_GET['temple'])." WHERE partie_id=".$scPartie->id." AND statut>0;");
41
+  $db->req("UPDATE ".$__CONF['dbtablepre']."parties SET statut=(statut+1) WHERE id=".$scPartie->id.";");
42 42
   exit();
43 43
 }
44 44
 
... ...
@@ -46,7 +46,7 @@ if( isset($_GET['temple']) ) {
46 46
  * JOUE
47 47
  */
48 48
 function compileDernierCoup($j, $tuile) {
49
-  global $db, $scPartie;
49
+  global $db, $scPartie, $__CONF;
50 50
 
51 51
   $dcAction = $j->dernier_coup[0];
52 52
   $dcVal = substr($j->dernier_coup, 1);
... ...
@@ -82,7 +82,7 @@ function compileDernierCoup($j, $tuile) {
82 82
     }
83 83
   }
84 84
 
85
-  $db->req("UPDATE joueurs SET plateau='".$j->plateauTxt()."', tresor1='".$j->tresor[0]."', tresor2='".$j->tresor[1]."', tresor3='".$j->tresor[2]."', tresor4='".$j->tresor[3]."', pepite_diamant=".$j->diamant.", pepite_or=".$j->or.", dernier_coup='', position_meeple1=".$j->meeple[0].", position_temple1=".$j->temple[0].", position_meeple2=".$j->meeple[1].", position_temple2=".$j->temple[1].", position_meeple3=".$j->meeple[2].", position_temple3=".$j->temple[2].", position_meeple4=".$j->meeple[3].", position_temple4=".$j->temple[3]."   WHERE id=".$j->id.";");
85
+  $db->req("UPDATE ".$__CONF['dbtablepre']."joueurs SET plateau='".$j->plateauTxt()."', tresor1='".$j->tresor[0]."', tresor2='".$j->tresor[1]."', tresor3='".$j->tresor[2]."', tresor4='".$j->tresor[3]."', pepite_diamant=".$j->diamant.", pepite_or=".$j->or.", dernier_coup='', position_meeple1=".$j->meeple[0].", position_temple1=".$j->temple[0].", position_meeple2=".$j->meeple[1].", position_temple2=".$j->temple[1].", position_meeple3=".$j->meeple[2].", position_temple3=".$j->temple[2].", position_meeple4=".$j->meeple[3].", position_temple4=".$j->temple[3]."   WHERE id=".$j->id.";");
86 86
 }
87 87
 
88 88
 function verifFinPartie($j) {
... ...
@@ -100,7 +100,7 @@ function verifFinPartie($j) {
100 100
 
101 101
 
102 102
 if( isset($_GET['dc']) ) {
103
-  $db->req("UPDATE joueurs SET dernier_coup='".$_GET['dc']."' WHERE id=".$scMoi->id.";");
103
+  $db->req("UPDATE ".$__CONF['dbtablepre']."joueurs SET dernier_coup='".$_GET['dc']."' WHERE id=".$scMoi->id.";");
104 104
   $scMoi->dernier_coup = $_GET['dc'];
105 105
 
106 106
 
... ...
@@ -116,7 +116,6 @@ if( isset($_GET['dc']) ) {
116 116
   if($nbDejaJoue == count($scJoueurs)) {
117 117
     // Extrait la 1ere tuile de la pioche
118 118
     $tuile = array_shift( $scPartie->pioche );
119
-
120 119
     compileDernierCoup($scMoi, $tuile);
121 120
     foreach($scJoueurs as $j)
122 121
       compileDernierCoup($j, $tuile);
... ...
@@ -136,9 +135,7 @@ if( isset($_GET['dc']) ) {
136 135
     if($fin)
137 136
       $scPartie->statut++;
138 137
 
139
-
140
-    $db->req("UPDATE parties SET statut='".$scPartie->statut."', pioche='".$scPartie->piocheTxt()."', tresor1='".$scPartie->tresor[0]."', tresor2='".$scPartie->tresor[1]."', tresor3='".$scPartie->tresor[2]."', tresor4='".$scPartie->tresor[3]."' WHERE id=".$scPartie->id.";");
141
-
138
+    $db->req("UPDATE ".$__CONF['dbtablepre']."parties SET statut='".$scPartie->statut."', pioche='".$scPartie->piocheTxt()."', tresor1='".$scPartie->tresor[0]."', tresor2='".$scPartie->tresor[1]."', tresor3='".$scPartie->tresor[2]."', tresor4='".$scPartie->tresor[3]."' WHERE id=".$scPartie->id.";");
142 139
   }
143 140
 
144 141
   exit();
Browse code

Externalisation du systeme de menu

schardon authored on 27/04/2020 23:19:23
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,198 @@
1
+<?php
2
+
3
+include('conf.php');
4
+include('commun/commun.php');
5
+
6
+
7
+if( !$scMoi->exist() )
8
+  exit();
9
+
10
+/*
11
+ * LANCER UNE NOUVELLE PARTIE
12
+ */
13
+if( isset($_GET['new']) ) {
14
+  $db->req("UPDATE parties SET statut=0 WHERE id=".$scPartie->id.";");
15
+  $db->req("UPDATE joueurs SET statut=0 WHERE partie_id=".$scPartie->id.";");
16
+  exit();
17
+}
18
+
19
+/*
20
+ * POSITIONNER UN MEEPLE
21
+ */
22
+if( isset($_GET['meeple']) ) {
23
+  if($scPartie->statut % 2 != 1 && $scPartie->statut >= 9)
24
+    exit();
25
+
26
+  $meepleId = ($scPartie->statut + 1) / 2;
27
+  $db->req("UPDATE joueurs SET position_meeple".$meepleId."=".(100 + intval($_GET['meeple']))." WHERE partie_id=".$scPartie->id." AND statut>0;");
28
+  $db->req("UPDATE parties SET statut=(statut+1) WHERE id=".$scPartie->id.";");
29
+  exit();
30
+}
31
+
32
+/*
33
+ * POSITIONNER UN TEMPLE
34
+ */
35
+if( isset($_GET['temple']) ) {
36
+  if($scPartie->statut % 2 != 0 && $scPartie->statut >= 9)
37
+    exit();
38
+
39
+  $templeId = $scPartie->statut / 2;
40
+  $db->req("UPDATE joueurs SET position_temple".$templeId."=".intval($_GET['temple'])." WHERE partie_id=".$scPartie->id." AND statut>0;");
41
+  $db->req("UPDATE parties SET statut=(statut+1) WHERE id=".$scPartie->id.";");
42
+  exit();
43
+}
44
+
45
+/*
46
+ * JOUE
47
+ */
48
+function compileDernierCoup($j, $tuile) {
49
+  global $db, $scPartie;
50
+
51
+  $dcAction = $j->dernier_coup[0];
52
+  $dcVal = substr($j->dernier_coup, 1);
53
+
54
+  // Pose de la tuile sur le plateau
55
+  if($dcAction == 'c') {
56
+    $j->plateau[ $dcVal - 1 ] = $tuile;
57
+  }
58
+  // Deplacement d'un meeple
59
+  elseif($dcAction == 'm') {
60
+    $dcMeeple = $dcVal[0];
61
+    $dcActionType = $dcVal[1];
62
+    $dcInfo = substr($dcVal, 2);
63
+
64
+    // Deplacement du meeple sur une case du plateau
65
+    if($dcActionType == 'c') {
66
+      $caseHasPepite = substr($j->plateau[ $dcInfo - 1 ], -1);
67
+      if($caseHasPepite == 'o' || $caseHasPepite == 'd') {
68
+        $j->plateau[ $dcInfo - 1 ] = substr( $j->plateau[ $dcInfo - 1 ], 0, -1 );
69
+        if($caseHasPepite == 'o') $j->or++;
70
+        if($caseHasPepite == 'd') $j->diamant++;
71
+      }
72
+      $j->meeple[ $dcMeeple - 1 ] = $dcInfo;
73
+    }
74
+    // Deplacement du meeple sur un temple
75
+    elseif($dcActionType == 't') {
76
+      $templeId = 0;
77
+      for($i = 0 ; $i < count($j->temple) ; $i++)
78
+        if($j->temple[$i] == $dcInfo)
79
+          $templeId = $i;
80
+      $j->tresor[$templeId] = $scPartie->gagneTresor($templeId);
81
+      $j->meeple[ $dcMeeple - 1 ] = $dcInfo + 200;
82
+    }
83
+  }
84
+
85
+  $db->req("UPDATE joueurs SET plateau='".$j->plateauTxt()."', tresor1='".$j->tresor[0]."', tresor2='".$j->tresor[1]."', tresor3='".$j->tresor[2]."', tresor4='".$j->tresor[3]."', pepite_diamant=".$j->diamant.", pepite_or=".$j->or.", dernier_coup='', position_meeple1=".$j->meeple[0].", position_temple1=".$j->temple[0].", position_meeple2=".$j->meeple[1].", position_temple2=".$j->temple[1].", position_meeple3=".$j->meeple[2].", position_temple3=".$j->temple[2].", position_meeple4=".$j->meeple[3].", position_temple4=".$j->temple[3]."   WHERE id=".$j->id.";");
86
+}
87
+
88
+function verifFinPartie($j) {
89
+  $fin = 0;
90
+
91
+  for($i = 0 ; $i < count($j->meeple) ; $i++)
92
+    if($j->meeple[$i] >= 200)
93
+      $fin++;
94
+
95
+  if( $fin == count($j->meeple) )
96
+    return true;
97
+
98
+  return false;
99
+}
100
+
101
+
102
+if( isset($_GET['dc']) ) {
103
+  $db->req("UPDATE joueurs SET dernier_coup='".$_GET['dc']."' WHERE id=".$scMoi->id.";");
104
+  $scMoi->dernier_coup = $_GET['dc'];
105
+
106
+
107
+  /*
108
+   * SI TOUT LE MONDE A DEJA JOUE
109
+   */
110
+  $nbDejaJoue = 0;
111
+  foreach($scJoueurs as $j) {
112
+    if($j->dernier_coup != "")
113
+      $nbDejaJoue++;
114
+  }
115
+
116
+  if($nbDejaJoue == count($scJoueurs)) {
117
+    // Extrait la 1ere tuile de la pioche
118
+    $tuile = array_shift( $scPartie->pioche );
119
+
120
+    compileDernierCoup($scMoi, $tuile);
121
+    foreach($scJoueurs as $j)
122
+      compileDernierCoup($j, $tuile);
123
+
124
+    // Verification des conditions de fin de partie
125
+    $fin = false;
126
+
127
+    if( count($scPartie->pioche) == 0 )
128
+      $fin = true;
129
+
130
+    if( verifFinPartie($scMoi) )
131
+      $fin = true;
132
+    foreach($scJoueurs as $j)
133
+      if( verifFinPartie($j) )
134
+        $fin = true;
135
+
136
+    if($fin)
137
+      $scPartie->statut++;
138
+
139
+
140
+    $db->req("UPDATE parties SET statut='".$scPartie->statut."', pioche='".$scPartie->piocheTxt()."', tresor1='".$scPartie->tresor[0]."', tresor2='".$scPartie->tresor[1]."', tresor3='".$scPartie->tresor[2]."', tresor4='".$scPartie->tresor[3]."' WHERE id=".$scPartie->id.";");
141
+
142
+  }
143
+
144
+  exit();
145
+}
146
+
147
+
148
+
149
+
150
+/*
151
+ * ENVOI LES INFOS
152
+ */
153
+
154
+// Affiche un tableau
155
+function JsonTab($data) {
156
+  $echoreturn = '[';
157
+  for($i = 0 ; $i < count($data) ; $i++) {
158
+    if($i > 0) $echoreturn .= ", ";
159
+    $echoreturn .= '"'.$data[$i].'"';
160
+  }
161
+  $echoreturn .= ']';
162
+  return $echoreturn;
163
+}
164
+
165
+// Affiche les infos d'un joueur
166
+function JsonJoueur($j) {
167
+  $echoreturn = '"'.$j->id.'":{';
168
+//  $echoreturn .= '"id":'.$j->id.', ';
169
+  $echoreturn .= '"tresor":'.JsonTab($j->tresor).', ';
170
+  $echoreturn .= '"diamant":'.$j->diamant.', ';
171
+  $echoreturn .= '"or":'.$j->or.', ';
172
+  $echoreturn .= '"dernier_coup":"'.$j->dernier_coup.'", ';
173
+  $echoreturn .= '"meeple":'.JsonTab($j->meeple).', ';
174
+  $echoreturn .= '"temple":'.JsonTab($j->temple).', ';
175
+  $echoreturn .= '"plateau":'.JsonTab($j->plateau);
176
+  $echoreturn .= '}';
177
+  return $echoreturn;
178
+}
179
+
180
+
181
+// Debut du JSON
182
+//  * Partie
183
+echo '{"statut":'.$scPartie->statut.', ';
184
+echo '"pioche":"'.$scPartie->pioche[0].'", ';
185
+echo '"nbpioche":'.(count($scPartie->pioche) - 1).', ';
186
+echo '"tresor":'.JsonTab( $scPartie->nextTresor() ).', ';
187
+
188
+//  * Joueurs
189
+echo '"joueur":{';
190
+echo JsonJoueur( $scMoi );
191
+foreach($scJoueurs as $j)
192
+  echo ', '.JsonJoueur($j);
193
+echo '}';
194
+
195
+echo '}';
196
+// Fin du JSON
197
+
198
+?>