... | ... |
@@ -92,6 +92,29 @@ class PartieInfos { |
92 | 92 |
return $piocheTxt; |
93 | 93 |
} |
94 | 94 |
|
95 |
+ public function tuilesRestantesJson() { |
|
96 |
+ if(!$this->_exist) return false; |
|
97 |
+ |
|
98 |
+ $tuilesTab = []; |
|
99 |
+ |
|
100 |
+ for($i = 0 ; $i < count($this->pioche) ; $i++) { |
|
101 |
+ if( !$tuilesTab[ $this->pioche[$i] ] ) |
|
102 |
+ $tuilesTab[ $this->pioche[$i] ] = 1; |
|
103 |
+ else |
|
104 |
+ $tuilesTab[ $this->pioche[$i] ]++; |
|
105 |
+ } |
|
106 |
+ |
|
107 |
+ $tuilesJson = ''; |
|
108 |
+ $first = true; |
|
109 |
+ foreach($tuilesTab as $t => $nb) { |
|
110 |
+ if($first) $first = false; |
|
111 |
+ else $tuilesJson .= ', '; |
|
112 |
+ $tuilesJson .= '"'.$t.'":'.$nb; |
|
113 |
+ } |
|
114 |
+ |
|
115 |
+ return $tuilesJson; |
|
116 |
+ } |
|
117 |
+ |
|
95 | 118 |
public function nouvelle() { |
96 | 119 |
global $db, $__CONF; |
97 | 120 |
|
... | ... |
@@ -25,10 +25,10 @@ class PartieInfos { |
25 | 25 |
} |
26 | 26 |
|
27 | 27 |
public function creer($nom) { |
28 |
- global $db; |
|
28 |
+ global $db, $__CONF; |
|
29 | 29 |
|
30 |
- $db->req("INSERT INTO parties VALUES (NULL, '".$nom."', '', 0, '', '', '', '', 0);"); |
|
31 |
- return $db->reqFirst("SELECT id FROM parties ORDER BY id DESC LIMIT 1;")['id']; |
|
30 |
+ $db->req("INSERT INTO ".$__CONF['dbtablepre']."parties(nom) VALUES ('".$nom."');"); |
|
31 |
+ return $db->reqFirst("SELECT id FROM ".$__CONF['dbtablepre']."parties ORDER BY id DESC LIMIT 1;")['id']; |
|
32 | 32 |
} |
33 | 33 |
|
34 | 34 |
public function nextTresor() { |
... | ... |
@@ -53,9 +53,9 @@ class PartieInfos { |
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
public function refresh() { |
56 |
- global $db; |
|
56 |
+ global $db, $__CONF; |
|
57 | 57 |
|
58 |
- $req = $db->reqFirst('SELECT * FROM parties WHERE id='.$this->id.';'); |
|
58 |
+ $req = $db->reqFirst("SELECT * FROM ".$__CONF['dbtablepre']."parties WHERE id=".$this->id.";"); |
|
59 | 59 |
|
60 | 60 |
if(!$req) { |
61 | 61 |
$this->_exist = false; |
... | ... |
@@ -73,7 +73,7 @@ class PartieInfos { |
73 | 73 |
$this->pioche = explode(',', $req['pioche']); |
74 | 74 |
|
75 | 75 |
$this->joueurs = []; |
76 |
- $req = $db->req("SELECT id FROM joueurs WHERE partie_id=".$this->id." AND statut>0;"); |
|
76 |
+ $req = $db->req("SELECT id FROM ".$__CONF['dbtablepre']."joueurs WHERE partie_id=".$this->id." AND statut>0;"); |
|
77 | 77 |
while( $req1 = $db->next($req) ) |
78 | 78 |
$this->joueurs[] = $req1['id']; |
79 | 79 |
$this->nbjoueurs = count($this->joueurs); |
... | ... |
@@ -93,7 +93,7 @@ class PartieInfos { |
93 | 93 |
} |
94 | 94 |
|
95 | 95 |
public function nouvelle() { |
96 |
- global $db; |
|
96 |
+ global $db, $__CONF; |
|
97 | 97 |
|
98 | 98 |
if(!$this->_exist) return false; |
99 | 99 |
|
... | ... |
@@ -126,10 +126,10 @@ class PartieInfos { |
126 | 126 |
if($this->nbjoueurs >= 12) $tresors = '555444333222'; |
127 | 127 |
|
128 | 128 |
|
129 |
- $req = $db->req("UPDATE joueurs SET plateau=',,,,,,,,,,,,,,,,,,,,,,,,,,,,,', tresor1='0', tresor2='0', tresor3='0', tresor4='0', pepite_diamant='0', pepite_or='0', dernier_coup='', position_meeple1=0, position_temple1=0, position_meeple2=0, position_temple2=0, position_meeple3=0, position_temple3=0, position_meeple4=0, position_temple4=0 WHERE partie_id=".$this->id." AND statut>0;"); |
|
129 |
+ $req = $db->req("UPDATE ".$__CONF['dbtablepre']."joueurs SET plateau=',,,,,,,,,,,,,,,,,,,,,,,,,,,,,', tresor1='0', tresor2='0', tresor3='0', tresor4='0', pepite_diamant='0', pepite_or='0', dernier_coup='', position_meeple1=0, position_temple1=0, position_meeple2=0, position_temple2=0, position_meeple3=0, position_temple3=0, position_meeple4=0, position_temple4=0 WHERE partie_id=".$this->id." AND statut>0;"); |
|
130 | 130 |
if(!$req) return false; |
131 | 131 |
|
132 |
- $req = $db->req("UPDATE parties SET pioche='".$piocheTxt."', statut=1, tresor1=".$tresors.", tresor2=".$tresors.", tresor3=".$tresors.", tresor4=".$tresors.", wait=0 WHERE id=".$this->id.";"); |
|
132 |
+ $req = $db->req("UPDATE ".$__CONF['dbtablepre']."parties SET pioche='".$piocheTxt."', statut=1, tresor1=".$tresors.", tresor2=".$tresors.", tresor3=".$tresors.", tresor4=".$tresors.", wait=0 WHERE id=".$this->id.";"); |
|
133 | 133 |
if(!$req) return false; |
134 | 134 |
|
135 | 135 |
return true; |
... | ... |
@@ -41,7 +41,7 @@ class PartieInfos { |
41 | 41 |
public function gagneTresor($n) { |
42 | 42 |
$tresor = $this->tresor[$n][0]; |
43 | 43 |
$this->tresor[$n] = substr($this->tresor[$n], 1); |
44 |
- if($this->tresorDejaPris[$n] > 0) |
|
44 |
+ if($this->_tresorDejaPris[$n] > 0) |
|
45 | 45 |
$tresor = $this->_tresorDejaPris[$n]; |
46 | 46 |
else |
47 | 47 |
$this->_tresorDejaPris[$n] = $tresor; |
... | ... |
@@ -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 |
} |
... | ... |
@@ -11,6 +11,8 @@ class PartieInfos { |
11 | 11 |
public $nbjoueurs; |
12 | 12 |
public $joueurs; |
13 | 13 |
|
14 |
+ private $_tresorDejaPris = [0, 0, 0, 0]; |
|
15 |
+ |
|
14 | 16 |
private $_exist; |
15 | 17 |
|
16 | 18 |
public function __construct() { |
... | ... |
@@ -22,6 +24,30 @@ class PartieInfos { |
22 | 24 |
$this->refresh(); |
23 | 25 |
} |
24 | 26 |
|
27 |
+ public function creer($nom) { |
|
28 |
+ global $db; |
|
29 |
+ |
|
30 |
+ $db->req("INSERT INTO parties VALUES (NULL, '".$nom."', '', 0, '', '', '', '', 0);"); |
|
31 |
+ return $db->reqFirst("SELECT id FROM parties ORDER BY id DESC LIMIT 1;")['id']; |
|
32 |
+ } |
|
33 |
+ |
|
34 |
+ public function nextTresor() { |
|
35 |
+ $nextTresor = []; |
|
36 |
+ for($i = 0 ; $i < count($this->tresor) ; $i++) |
|
37 |
+ $nextTresor[$i] = $this->tresor[$i][0]; |
|
38 |
+ return $nextTresor; |
|
39 |
+ } |
|
40 |
+ |
|
41 |
+ public function gagneTresor($n) { |
|
42 |
+ $tresor = $this->tresor[$n][0]; |
|
43 |
+ $this->tresor[$n] = substr($this->tresor[$n], 1); |
|
44 |
+ if($this->tresorDejaPris[$n] > 0) |
|
45 |
+ $tresor = $this->_tresorDejaPris[$n]; |
|
46 |
+ else |
|
47 |
+ $this->_tresorDejaPris[$n] = $tresor; |
|
48 |
+ return $tresor; |
|
49 |
+ } |
|
50 |
+ |
|
25 | 51 |
public function exist() { |
26 | 52 |
return $this->_exist; |
27 | 53 |
} |
... | ... |
@@ -41,10 +67,10 @@ class PartieInfos { |
41 | 67 |
$this->wait = $req['wait']; |
42 | 68 |
|
43 | 69 |
for($i = 0 ; $i < 4 ; $i++) { |
44 |
- $this->tresor[$i] = $req['tresor'.$i]; |
|
70 |
+ $this->tresor[$i] = $req['tresor'.($i + 1)]; |
|
45 | 71 |
} |
46 | 72 |
|
47 |
- $this->pioche = $req['pioche']; |
|
73 |
+ $this->pioche = explode(',', $req['pioche']); |
|
48 | 74 |
|
49 | 75 |
$this->joueurs = []; |
50 | 76 |
$req = $db->req("SELECT id FROM joueurs WHERE partie_id=".$this->id." AND statut>0;"); |
... | ... |
@@ -77,7 +103,15 @@ class PartieInfos { |
77 | 103 |
'4d', '4', '5', '5', '6', '6', '7', '7', // T |
78 | 104 |
'8d', '8d', '9d', '9', '10d', '10', '11d', '11' ]; // L |
79 | 105 |
|
80 |
- shuffle($pioche); |
|
106 |
+ shuffle($this->pioche); |
|
107 |
+ |
|
108 |
+ $piocheTxt = ''; |
|
109 |
+ $first = true; |
|
110 |
+ foreach($this->pioche as $p) { |
|
111 |
+ if($first) $first = false; |
|
112 |
+ else $piocheTxt .= ','; |
|
113 |
+ $piocheTxt .= $p; |
|
114 |
+ } |
|
81 | 115 |
|
82 | 116 |
if($this->nbjoueurs == 2) $tresors = '53'; |
83 | 117 |
if($this->nbjoueurs == 3) $tresors = '532'; |
... | ... |
@@ -92,12 +126,10 @@ class PartieInfos { |
92 | 126 |
if($this->nbjoueurs >= 12) $tresors = '555444333222'; |
93 | 127 |
|
94 | 128 |
|
95 |
- for($i = 0 ; $i < $ccNbJoueurs ; $i++) { |
|
96 |
- $req = $db->req("UPDATE joueurs SET plateau=',,,,,,,,,,,,,,,,,,,,,,,,,,,,,', tresor1='0', tresor2='0', tresor3='0', tresor4='0', pepite_diamant='0', pepite_or='0', dernier_coup='', position_meeple1=0, position_temple1=0, position_meeple2=0, position_temple2=0, position_meeple3=0, position_temple3=0, position_meeple4=0, position_temple4=0 WHERE partie_id=".$this->id." AND statut>0;"); |
|
97 |
- if(!$req) return false; |
|
98 |
- } |
|
129 |
+ $req = $db->req("UPDATE joueurs SET plateau=',,,,,,,,,,,,,,,,,,,,,,,,,,,,,', tresor1='0', tresor2='0', tresor3='0', tresor4='0', pepite_diamant='0', pepite_or='0', dernier_coup='', position_meeple1=0, position_temple1=0, position_meeple2=0, position_temple2=0, position_meeple3=0, position_temple3=0, position_meeple4=0, position_temple4=0 WHERE partie_id=".$this->id." AND statut>0;"); |
|
130 |
+ if(!$req) return false; |
|
99 | 131 |
|
100 |
- $req = $db->req("UPDATE parties SET pioche='".$this->pioche."', statut=1, tresor1=".$tresors.", tresor2=".$tresors.", tresor3=".$tresors.", tresor4=".$tresors.", wait=0 WHERE id=".$this->id.";"); |
|
132 |
+ $req = $db->req("UPDATE parties SET pioche='".$piocheTxt."', statut=1, tresor1=".$tresors.", tresor2=".$tresors.", tresor3=".$tresors.", tresor4=".$tresors.", wait=0 WHERE id=".$this->id.";"); |
|
101 | 133 |
if(!$req) return false; |
102 | 134 |
|
103 | 135 |
return true; |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,110 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+class PartieInfos { |
|
4 |
+ public $id; |
|
5 |
+ public $nom; |
|
6 |
+ public $pioche; |
|
7 |
+ public $statut; |
|
8 |
+ public $tresor; |
|
9 |
+ public $wait; |
|
10 |
+ |
|
11 |
+ public $nbjoueurs; |
|
12 |
+ public $joueurs; |
|
13 |
+ |
|
14 |
+ private $_exist; |
|
15 |
+ |
|
16 |
+ public function __construct() { |
|
17 |
+ $this->_exist = false; |
|
18 |
+ } |
|
19 |
+ |
|
20 |
+ public function init($id) { |
|
21 |
+ $this->id = $id; |
|
22 |
+ $this->refresh(); |
|
23 |
+ } |
|
24 |
+ |
|
25 |
+ public function exist() { |
|
26 |
+ return $this->_exist; |
|
27 |
+ } |
|
28 |
+ |
|
29 |
+ public function refresh() { |
|
30 |
+ global $db; |
|
31 |
+ |
|
32 |
+ $req = $db->reqFirst('SELECT * FROM parties WHERE id='.$this->id.';'); |
|
33 |
+ |
|
34 |
+ if(!$req) { |
|
35 |
+ $this->_exist = false; |
|
36 |
+ return; |
|
37 |
+ } |
|
38 |
+ |
|
39 |
+ $this->nom = $req['nom']; |
|
40 |
+ $this->statut = $req['statut']; |
|
41 |
+ $this->wait = $req['wait']; |
|
42 |
+ |
|
43 |
+ for($i = 0 ; $i < 4 ; $i++) { |
|
44 |
+ $this->tresor[$i] = $req['tresor'.$i]; |
|
45 |
+ } |
|
46 |
+ |
|
47 |
+ $this->pioche = $req['pioche']; |
|
48 |
+ |
|
49 |
+ $this->joueurs = []; |
|
50 |
+ $req = $db->req("SELECT id FROM joueurs WHERE partie_id=".$this->id." AND statut>0;"); |
|
51 |
+ while( $req1 = $db->next($req) ) |
|
52 |
+ $this->joueurs[] = $req1['id']; |
|
53 |
+ $this->nbjoueurs = count($this->joueurs); |
|
54 |
+ |
|
55 |
+ $this->_exist = true; |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ public function piocheTxt() { |
|
59 |
+ if(!$this->_exist) return false; |
|
60 |
+ |
|
61 |
+ $piocheTxt = ''; |
|
62 |
+ for($i = 0 ; $i < count($req['pioche']) ; $i++) { |
|
63 |
+ if($i > 0) $piocheTxt .= ','; |
|
64 |
+ $piocheTxt .= $this->pioche[$i]; |
|
65 |
+ } |
|
66 |
+ return $piocheTxt; |
|
67 |
+ } |
|
68 |
+ |
|
69 |
+ public function nouvelle() { |
|
70 |
+ global $db; |
|
71 |
+ |
|
72 |
+ if(!$this->_exist) return false; |
|
73 |
+ |
|
74 |
+ $this->pioche = [ '1o', '1o', '1d', '1d', '1', '1', '1', '1', // | |
|
75 |
+ '2o', '2o', '2d', '2d', '2', '2', '2', '2', // - |
|
76 |
+ '3', '3', '3', '3', // + |
|
77 |
+ '4d', '4', '5', '5', '6', '6', '7', '7', // T |
|
78 |
+ '8d', '8d', '9d', '9', '10d', '10', '11d', '11' ]; // L |
|
79 |
+ |
|
80 |
+ shuffle($pioche); |
|
81 |
+ |
|
82 |
+ if($this->nbjoueurs == 2) $tresors = '53'; |
|
83 |
+ if($this->nbjoueurs == 3) $tresors = '532'; |
|
84 |
+ if($this->nbjoueurs == 4) $tresors = '5432'; |
|
85 |
+ if($this->nbjoueurs == 5) $tresors = '54322'; |
|
86 |
+ if($this->nbjoueurs == 6) $tresors = '543322'; |
|
87 |
+ if($this->nbjoueurs == 7) $tresors = '5443322'; |
|
88 |
+ if($this->nbjoueurs == 8) $tresors = '55443322'; |
|
89 |
+ if($this->nbjoueurs == 9) $tresors = '554433222'; |
|
90 |
+ if($this->nbjoueurs == 10) $tresors = '5544333222'; |
|
91 |
+ if($this->nbjoueurs == 11) $tresors = '55444333222'; |
|
92 |
+ if($this->nbjoueurs >= 12) $tresors = '555444333222'; |
|
93 |
+ |
|
94 |
+ |
|
95 |
+ for($i = 0 ; $i < $ccNbJoueurs ; $i++) { |
|
96 |
+ $req = $db->req("UPDATE joueurs SET plateau=',,,,,,,,,,,,,,,,,,,,,,,,,,,,,', tresor1='0', tresor2='0', tresor3='0', tresor4='0', pepite_diamant='0', pepite_or='0', dernier_coup='', position_meeple1=0, position_temple1=0, position_meeple2=0, position_temple2=0, position_meeple3=0, position_temple3=0, position_meeple4=0, position_temple4=0 WHERE partie_id=".$this->id." AND statut>0;"); |
|
97 |
+ if(!$req) return false; |
|
98 |
+ } |
|
99 |
+ |
|
100 |
+ $req = $db->req("UPDATE parties SET pioche='".$this->pioche."', statut=1, tresor1=".$tresors.", tresor2=".$tresors.", tresor3=".$tresors.", tresor4=".$tresors.", wait=0 WHERE id=".$this->id.";"); |
|
101 |
+ if(!$req) return false; |
|
102 |
+ |
|
103 |
+ return true; |
|
104 |
+ } |
|
105 |
+ |
|
106 |
+ |
|
107 |
+ |
|
108 |
+} |
|
109 |
+ |
|
110 |
+?> |