Browse Source

Commencé le js

Brendan Abolivier 9 years ago
parent
commit
6f43ed3ecd
2 changed files with 46 additions and 28 deletions
  1. 5
    28
      web/index.htm
  2. 41
    0
      web/js/game.js

+ 5
- 28
web/index.htm View File

4
     <title>fqsdhgfqjlsghoesf</title>
4
     <title>fqsdhgfqjlsghoesf</title>
5
     <meta charset="utf-8" />
5
     <meta charset="utf-8" />
6
     <script src="jquery-2.1.4.min.js"></script>
6
     <script src="jquery-2.1.4.min.js"></script>
7
+    <script src="js/game.js"></script>
7
   </head>
8
   </head>
8
   <body>
9
   <body>
9
-    <div id="yolo"></div>
10
-    <input type="submit" id="refresh" value="Refresh" />
10
+    <div id="game"></div>
11
+    <input type="submit" id="play" value="Play" />
11
     <script type="text/javascript">
12
     <script type="text/javascript">
12
-      $("#refresh").click(function() {
13
-        $.ajax({
14
-          url: "./api/",
15
-          dataType: 'json',
16
-          success: function(data) {
17
-            $("#yolo").html(JSON.stringify(data));
18
-          }
19
-        });
13
+      $("#play").click(function() {
14
+        play();
20
       });
15
       });
21
-/*      $(document).ready(function() {
22
-        $.ajax({
23
-          url: "./api/",
24
-          dataType: 'json',
25
-          success: function(data) {
26
-            //cat
27
-            var array = [];
28
-            array[data.cat1.nom_cat] = [];
29
-            data.cat1.themes.forEach(function(row) {
30
-              array[data.cat1.nom_cat].push(row);
31
-            });
32
-            array.forEach(function(row) {
33
-              $("#yolo").append("<strong>"+row);
34
-            });
35
-            $("#yolo").html(JSON.stringify(data));
36
-          }
37
-        });
38
-      });*/
39
     </script>
16
     </script>
40
   </body>
17
   </body>
41
 </html>
18
 </html>

+ 41
- 0
web/js/game.js View File

1
+var json, cat, theme, i = 0;
2
+
3
+function apiReq() {
4
+  $.ajax({
5
+    async: false,
6
+    url: "./api/",
7
+    dataType: 'json',
8
+    success: function(data) {
9
+      json = data;
10
+    }
11
+  });
12
+}
13
+
14
+function loadCat(id) {
15
+  if(i === 0) cat = json.cat1;
16
+  if(i === 1) cat = json.cat2;
17
+  $("#game").html("<p id=\"category\">Catégorie : "+category.nom_cat+"</p>");
18
+  loadTheme(1);
19
+}
20
+
21
+function loadTheme(id) {
22
+  theme = category.theme[id];
23
+  $("#game").append("<ul id=\"answers\"><li id=\"rep1\">"+theme.reponse1+"</li><li id=\"rep2\">"+theme.reponse2+"</li><li id=\"both\">Les deux</li></ul>");
24
+  $("#game").append("<p id=\"question\"></p>")
25
+  quest();
26
+}
27
+
28
+function quest() {
29
+  while(i < theme.questions.length) {
30
+    $("#question").html(theme.questions[i]);
31
+    $("#answers").click(function() {
32
+      
33
+    });
34
+  }
35
+}
36
+
37
+function play() {
38
+  $("#play").remove();
39
+  apiReq();
40
+
41
+}