Browse code

Ajout de la salle d'attente

schardon authored on 23/04/2020 14:33:40
Showing 7 changed files
... ...
@@ -5,7 +5,7 @@ function isAjax() {
5 5
 }
6 6
 
7 7
 
8
-if(!isAjax()) {
8
+if( !isAjax() ) {
9 9
   header('Location: ../index.php');
10 10
   exit();
11 11
 }
... ...
@@ -2,16 +2,43 @@
2 2
 
3 3
 include('backend.php');
4 4
 
5
-
6 5
 include('../include/partie.php');
7
-$scPartie = new PartieInfos();
6
+include('../include/joueur.php');
7
+include('../include/session.php');
8
+
8 9
 
9
-if( isset($_GET['p']) ) {
10
-  if( intval($_GET['p']) > 0)
11
-    $scPartie->init( intval($_GET['p']) );
10
+/*
11
+ * LA PARTIE A DEJA DEMARREE
12
+ */
13
+if( $scMoi->exist() && $scPartie->statut > 0 ) {
14
+  echo '{"mode": "g"}';
15
+  exit();
16
+}
17
+
18
+
19
+/*
20
+ * JOUEUR SORT DE LA SALLE D'ATTENTE
21
+ */
22
+if( isset($_GET['out']) && $scMoi->exist() ) {
23
+  $db->req("UPDATE joueurs SET statut=0 WHERE id=".$scMoi->id.";");
24
+  exit();
12 25
 }
13 26
 
14 27
 
28
+/*
29
+ * DEMARRAGE DE LA PARTIE
30
+ */
31
+if( isset($_GET['go']) && $scMoi->exist() ) {
32
+  if( $scPartie->nouvelle() )
33
+    header('Location: index.php?j='.$scMoi->id);
34
+  exit();
35
+}
36
+
37
+
38
+
39
+/*
40
+ * AJOUT D'UN NOUVEAU JOUEUR, OU D'UNE NOUVELLE PARTIE
41
+ */
15 42
 if( isset($_POST['ajouter']) ) {
16 43
   $ajouter = htmlentities($_POST['ajouter'], ENT_QUOTES);
17 44
 
... ...
@@ -28,8 +55,12 @@ if( isset($_POST['ajouter']) ) {
28 55
 }
29 56
 
30 57
 
58
+/*
59
+ * SUPPRESSION D'UN JOUEUR OU D'UNE PARTIE
60
+ */
31 61
 if( isset($_GET['suppr']) ) {
32 62
   $suppr = intval($_GET['suppr']);
63
+
33 64
   if( $scPartie->exist() ) {
34 65
     $db->req("DELETE FROM joueurs WHERE id=".$suppr." AND partie_id=".$scPartie->id.";");
35 66
   }
... ...
@@ -37,38 +68,55 @@ if( isset($_GET['suppr']) ) {
37 68
     $db->req("DELETE FROM parties WHERE id=".$suppr.";");
38 69
     $db->req("DELETE FROM joueurs WHERE partie_id=".$suppr.";");
39 70
   }
40
-}
41 71
 
72
+  exit();
73
+}
42 74
 
43
-if( $scPartie->exist() ) {
44 75
 
45
-  echo '{"mode":"j", ';
46
-  echo '"nom":"'.$scPartie->nom.'", ';
47
-  echo '"liste":{';
48
-  $req = $db->req("SELECT id, nom FROM joueurs WHERE partie_id=".$scPartie->id.";");
49
-  $first = true;
50
-  while($req1 = $db->next($req)) {
51
-    if($first) $first = false;
52
-    else echo ", ";
53
-    echo '"'.$req1['id'].'":"'.$req1['nom'].'"';
54
-  }
55
-  echo "}}";
56
-  
76
+/*
77
+ * ENTRER DANS LA SALLE D'ATTENTE
78
+ */
79
+if( $scMoi->exist() && $scMoi->statut < 1 ) {
80
+  $db->req("UPDATE joueurs SET statut=1 WHERE id=".$scMoi->id.";");
81
+  $scMoi->refresh();
57 82
 }
58
-else {
59 83
 
60
-  echo '{"mode":"p", ';
61
-  echo '"liste":{';
84
+
85
+/*
86
+ * ENVOI DES INFOS
87
+ */
88
+
89
+// Mode
90
+echo '{"mode":"';
91
+if( $scMoi->exist() ) echo 's'; // Salle d'attente
92
+elseif( $scPartie->exist() ) echo 'j'; // Joueurs
93
+else echo 'p'; // Parties
94
+echo '", ';
95
+
96
+// Nom de partie
97
+if( $scPartie->exist() )
98
+  echo '"partie":"'.$scPartie->nom.'", ';
99
+if( $scMoi->exist() )
100
+  echo '"joueur":"'.$scMoi->nom.'", ';
101
+
102
+// Donnees
103
+echo '"liste":{';
104
+
105
+if( $scMoi->exist() )
106
+  $req = $db->req("SELECT id, nom FROM joueurs WHERE partie_id=".$scPartie->id." AND statut>0;");
107
+elseif( $scPartie->exist() )
108
+  $req = $db->req("SELECT id, nom FROM joueurs WHERE partie_id=".$scPartie->id.";");
109
+else
62 110
   $req = $db->req("SELECT id, nom FROM parties;");
63
-  $first = true;
64
-  while($req1 = $db->next($req)) {
65
-    if($first) $first = false;
66
-    else echo ", ";
67
-    echo '"'.$req1['id'].'":"'.$req1['nom'].'"';
68
-  }
69
-  echo "}}";
70 111
 
112
+$first = true;
113
+while($req1 = $db->next($req)) {
114
+  if($first) $first = false;
115
+  else echo ", ";
116
+  echo '"'.$req1['id'].'":"'.$req1['nom'].'"';
71 117
 }
72 118
 
119
+echo '}}';
120
+
73 121
 
74 122
 ?>
... ...
@@ -23,13 +23,21 @@ body {
23 23
 }
24 24
 
25 25
 .creer-titre-partie {
26
-  background-color: #9AE;
26
+  background-color: #8AE;
27
+  border: 1px solid #57B;
27 28
 }
28 29
 
29 30
 .creer-titre-joueur {
30 31
   background-color: #EA8;
32
+  border: 1px solid #B75;
31 33
 }
32 34
 
35
+.creer-titre-attente {
36
+  background-color: #AE8;
37
+  border: 1px solid #7B5;
38
+}
39
+
40
+
33 41
 .creer-liste { /* div */
34 42
   width: 50%;
35 43
   margin: 10px auto;
... ...
@@ -47,6 +55,7 @@ body {
47 55
 
48 56
 .creer-liste-nom { /* td */
49 57
   font-variant-caps: small-caps;
58
+  padding: 15px;
50 59
 }
51 60
 
52 61
 .creer-liste-btn { /* td */
... ...
@@ -67,7 +76,6 @@ body {
67 76
 }
68 77
 
69 78
 
70
-
71 79
 .creer-form {
72 80
   width: 100%;
73 81
   padding: 30px 0;
... ...
@@ -75,18 +83,24 @@ body {
75 83
 }
76 84
 
77 85
 .creer-form-input {
78
-  border: 1px solid #ddd;
79 86
   border-radius: 5px;
80 87
   background-color: #eee;
88
+  border: 1px solid #ddd;
81 89
   padding: 5px 10px;
82 90
   margin: 0 5px;
83 91
 }
84 92
 
93
+.creer-go-btn,
85 94
 .creer-form-btn {
86 95
   background-color: #5A4;
87 96
   border: 1px solid #382;
88 97
 }
89 98
 
99
+.creer-go {
100
+  width: 200px;
101
+  margin: 20px auto;
102
+  text-align: center;
103
+}
90 104
 
91 105
 
92 106
 .creer-titre-retour {
... ...
@@ -1,9 +1,14 @@
1 1
 <html>
2 2
 <head>
3
-  <title>Karuba</title>
3
+  <title><?php echo $jeuNom; ?></title>
4 4
   <link rel="stylesheet" type="text/css" href="css/menu.css" />
5 5
   <script type="text/javascript" src="js/jquery-3.5.0.min.js"></script>
6 6
   <script type="text/javascript" src="js/menu.js"></script>
7
+  <script type="text/javascript">
8
+var scInput_PartieId = <?php echo ($scPartie->exist() ? $scPartie->id : '0'); ?>;
9
+var scInput_JoueurId = <?php echo ($scMoi->exist() ? $scMoi->id : '0'); ?>;
10
+var scInput_JeuNom = '<?php echo $jeuNom; ?>';
11
+  </script>
7 12
 </head>
8 13
 <body>
9 14
 
... ...
@@ -19,5 +24,7 @@
19 24
   </div>
20 25
 </form>
21 26
 
27
+<div class="creer-go" id="creerGo"><div class="creer-go-btn creer-btn">D&eacute;marrer la partie !</div></div>
28
+
22 29
 </body>
23 30
 </html>
... ...
@@ -6,15 +6,14 @@ $scJoueurs = [];
6 6
 
7 7
 if( isset($_GET['j']) ) {
8 8
   $scMoi->init( intval($_GET['j']) );
9
-
10
-  if( $scMoi->exist() )
11
-    $scPartie->init( $scMoi->partie_id );
12 9
 }
13 10
 
14
-if( !$scPartie->exist() ) {
15
-  include('include/creer.php');
16
-  exit();
11
+if( $scMoi->exist() ) {
12
+  $scPartie->init( $scMoi->partie_id );
17 13
 }
18 14
 
15
+if( !$scPartie->exist() && isset($_GET['p']) ) {
16
+  $scPartie->init( intval($_GET['p']) );
17
+}
19 18
 
20 19
 ?>
... ...
@@ -1,26 +1,27 @@
1 1
 <?php
2 2
 
3
+$jeuNom = 'Karuba';
4
+
3 5
 include('include/db.php');
4 6
 include('include/joueur.php');
5 7
 include('include/partie.php');
6 8
 include('include/session.php');
7 9
 
8 10
 
9
-
10
-
11
-if( isset($_GET['go']) ) {
12
-  if( $scPartie->nouvelle() )
13
-    header('Location: index.php?j='.$scMoi->id);
14
-  else
15
-    echo 'Erreur ?';
11
+if( !$scPartie->exist() || $scPartie->statut == 0 ) {
12
+  include('include/creer.php');
16 13
   exit();
17 14
 }
18 15
 
19 16
 
17
+
18
+
19
+
20
+
20 21
 foreach($scPartie->joueurs as $j) {
21 22
   if($j != $scMoi->id) {
22 23
     $scJoueurs[] = new JoueurInfos();
23
-    $scJoueurs[ count($scJoueurs) - 1 ].init( $req1['id'] );
24
+    $scJoueurs[ count($scJoueurs) - 1 ]->init( $req1['id'] );
24 25
   }
25 26
 }
26 27
 
... ...
@@ -2,36 +2,62 @@
2 2
 $(document).ready(function() {
3 3
 
4 4
   var menuList = [];
5
-  var scPartieId = 0;
5
+  var scPartieId = scInput_PartieId;
6
+  var scJoueurId = scInput_JoueurId;
6 7
   var menuMode = '';
7 8
 
8 9
   function refreshScreen(data) {
10
+    if(data['mode'] == 'g') {
11
+      if(scJoueurId > 0)
12
+        window.location.href = 'index.php?j=' + scJoueurId;
13
+      else
14
+        window.location.href = 'index.php';
15
+      return;
16
+    }
17
+
9 18
     if(data['mode'] != menuMode) {
10 19
       menuMode = data['mode'];
11 20
       if(menuMode == 'p') {
12
-        $('#creerTitre').html('Karuba - Choisir une partie');
21
+        $('#creerTitre').html(scInput_JeuNom.toUpperCase() + ' - Choisir une partie');
22
+        $('#creerTitre').removeClass('creer-titre-attente');
13 23
         $('#creerTitre').removeClass('creer-titre-joueur');
14 24
         $('#creerTitre').addClass('creer-titre-partie');
25
+        $('#creerForm').show();
26
+        $('#creerGo').hide();
15 27
         scPartieId = 0;
28
+        scJoueurId = 0;
16 29
       }
17 30
       if(menuMode == 'j') {
18
-        $('#creerTitre').html('<div class="creer-titre-retour creer-btn">&lt;&lt;</div>Karuba - Partie : ' + data['nom'] + ' - Choisir un joueur');
31
+        $('#creerTitre').html('<div class="creer-titre-retour creer-btn">&lt;&lt;</div>' + scInput_JeuNom.toUpperCase() + ' [ Partie : ' + data['partie'] + ' ] Choisir un joueur');
32
+        $('#creerTitre').removeClass('creer-titre-attente');
19 33
         $('#creerTitre').removeClass('creer-titre-partie');
20 34
         $('#creerTitre').addClass('creer-titre-joueur');
35
+        $('#creerForm').show();
36
+        $('#creerGo').hide();
37
+        scJoueurId = 0;
38
+      }
39
+      if(menuMode == 's') {
40
+        $('#creerTitre').html('<div class="creer-titre-retour creer-btn">&lt;&lt;</div>' + scInput_JeuNom.toUpperCase() + ' [ Partie : ' + data['partie'] + ' ] [ Joueur : ' + data['joueur'] + " ] Salle d'attente");
41
+        $('#creerTitre').removeClass('creer-titre-partie');
42
+        $('#creerTitre').removeClass('creer-titre-joueur');
43
+        $('#creerTitre').addClass('creer-titre-attente');
44
+        $('#creerForm').hide();
21 45
       }
22 46
       $('#creerListeTab').empty();
23 47
       menuList = [];
24 48
     }
25 49
 
26 50
     // Parties/Joueurs ajoutes ou modifies ?
51
+    var dataListeTaille = 0;
27 52
     for(var key in data['liste']) {
53
+      dataListeTaille++;
28 54
       var val = data['liste'][key];
29 55
       if( menuList[key] ) {
30 56
         if( menuList[key] != val )
31 57
           $('#creerListeItem' + key + ' .creer-liste-nom').html( val );
32 58
       }
33 59
       else {
34
-        var tr = $('<tr id="creerListeItem' + key + '"><td class="creer-liste-nom">' + val + '</td><td class="creer-liste-btn"><div class="creer-liste-btn-entrer creer-btn">Entrer</div><div class="creer-liste-btn-suppr creer-btn">Supprimer</div></td></tr>');
60
+        var tr = $('<tr id="creerListeItem' + key + '"><td class="creer-liste-nom">' + val + '</td>' + (scJoueurId > 0 ? '' : '<td class="creer-liste-btn"><div class="creer-liste-btn-entrer creer-btn">Entrer</div><div class="creer-liste-btn-suppr creer-btn">Supprimer</div></td>') + '</tr>');
35 61
         $('#creerListeTab').prepend(tr);
36 62
         tr.hide().fadeIn();
37 63
         menuList[key] = val;
... ...
@@ -45,10 +71,17 @@ $(document).ready(function() {
45 71
         menuList[key] = false;
46 72
       }
47 73
     }
74
+
75
+    if(data['mode'] == 's') {
76
+      if( dataListeTaille > 1 )
77
+        $('#creerGo').show();
78
+      else
79
+        $('#creerGo').hide();
80
+    }
48 81
   }
49 82
 
50 83
   function refresh() {
51
-    $.get('backend/creer.php?p=' + scPartieId)
84
+    $.get('backend/creer.php?p=' + scPartieId + '&j=' + scJoueurId)
52 85
       .done(function(data, text, jqxhr) {
53 86
         refreshScreen(  JSON.parse(jqxhr.responseText) );
54 87
       })
... ...
@@ -66,17 +99,34 @@ $(document).ready(function() {
66 99
 
67 100
   function creerSwitchTo(id) {
68 101
     if(scPartieId > 0)
69
-      window.location.href = 'index.php?j=' + id;
70
-    else {
102
+      scJoueurId = id;
103
+    else
71 104
       scPartieId = id;
72
-      clearTimeout(refreshTimer);
73
-      refresh();
74
-    }
105
+
106
+    clearTimeout(refreshTimer);
107
+    refresh();
75 108
   }
76 109
 
77 110
   $('#creerTitre').on('click', '.creer-titre-retour', function(e) {
78
-    scPartieId = 0;
79
-    creerSwitchTo(0);
111
+    if(scJoueurId > 0) {
112
+      var tempJ = scJoueurId;
113
+      scJoueurId = 0;
114
+      $.get('backend/creer.php?p=' + scPartieId + '&j=' + tempJ + '&out=1')
115
+        .done(function(data, text, jqxhr) {
116
+
117
+        })
118
+        .fail(function(jqxhr){
119
+  //        alert(jqxhr.responseText);
120
+        })
121
+        .always(function(){
122
+          clearTimeout(refreshTimer);
123
+          refresh();
124
+        });
125
+    }
126
+    else {
127
+      scPartieId = 0;
128
+      creerSwitchTo(0);
129
+    }
80 130
   });
81 131
 
82 132
   $('#creerListeTab').on('click', '.creer-liste-btn-entrer', function(e) {
... ...
@@ -88,7 +138,7 @@ $(document).ready(function() {
88 138
   $('#creerListeTab').on('click', '.creer-liste-btn-suppr', function(e) {
89 139
     e.preventDefault();
90 140
     var id = $(this).parents('tr').attr('id').substring('creerListeItem'.length);
91
-//    $(this).parents('td').empty();
141
+    $(this).parents('td').empty();
92 142
     $(this).parents('tr').fadeOut();
93 143
     menuList[id] = false;
94 144
     $.get('backend/creer.php?p=' + scPartieId + '&suppr=' + id)
... ...
@@ -103,6 +153,22 @@ $(document).ready(function() {
103 153
       });
104 154
   });
105 155
 
156
+  $('#creerGo .creer-go-btn').on('click', function(e) {
157
+    e.preventDefault();
158
+    $('#creerGo').fadeOut();
159
+
160
+    $.get('backend/creer.php?p=' + scPartieId + '&j=' + scJoueurId + '&go=1')
161
+      .done(function(data, text, jqxhr) {
162
+
163
+      })
164
+      .fail(function(jqxhr){
165
+//        alert(jqxhr.responseText);
166
+      })
167
+      .always(function(){
168
+        clearTimeout(refreshTimer);
169
+        refresh();
170
+      });
171
+  });
106 172
 
107 173
   $('#creerForm').on('submit', function(e) {
108 174
     e.preventDefault();