|
@@ -11,29 +11,32 @@ var gameInfos;
|
11
|
11
|
var disconnect = true;
|
12
|
12
|
var scoreAdversaire = 0;
|
13
|
13
|
var pseudo ='';
|
|
14
|
+var reponseUser = -1, bonneReponse;
|
14
|
15
|
|
15
|
16
|
function init() {
|
16
|
17
|
|
|
18
|
+ var hostname = $('script')[1]['src'].match(/http:\/\/(.+)\:/)[1];
|
|
19
|
+
|
17
|
20
|
// Connexion à socket.io
|
18
|
|
- socket = io.connect('http://172.17.7.66:8000');
|
|
21
|
+ socket = io.connect('http://'+hostname+':8000');
|
19
|
22
|
|
20
|
23
|
// Gestion des evenements
|
21
|
24
|
setEventHandlers();
|
22
|
25
|
|
23
|
26
|
// On demande le pseudo a l'utilisateur, on l'envoie au serveur et on l'affiche dans le titre
|
24
|
|
- $("#game").html("<input type=\"text\" id=\"pseudo\" /><input type=\"submit\" id=\"start\" value=\"Valider\" />");
|
|
27
|
+ $("#game").html("<input type=\"text\" id=\"pseudo\" placeholder=\"Nom ou pseudonyme\" /><input type=\"submit\" id=\"start\" value=\"Valider\" />");
|
25
|
28
|
$("#start").on("click", function() {
|
26
|
29
|
pseudo = $("#pseudo").val();
|
27
|
30
|
socket.emit('nouveau', pseudo);
|
28
|
31
|
document.title = $("#pseudo").val() + ' - ' + document.title;
|
29
|
|
- $("#game").html("Recherche d'un adversare...");
|
|
32
|
+ $("#game").html("Recherche d'un adversaire...");
|
30
|
33
|
});
|
31
|
34
|
$("#pseudo").on('keypress', function(event) {
|
32
|
35
|
if(event.which == 13) {
|
33
|
36
|
pseudo = $("#pseudo").val();
|
34
|
37
|
socket.emit('nouveau', pseudo);
|
35
|
38
|
document.title = $("#pseudo").val() + ' - ' + document.title;
|
36
|
|
- $("#game").html("Recherche d'un adversare...");
|
|
39
|
+ $("#game").html("Recherche d'un adversaire...");
|
37
|
40
|
}
|
38
|
41
|
});
|
39
|
42
|
};
|
|
@@ -48,6 +51,10 @@ var setEventHandlers = function() {
|
48
|
51
|
socket.on("questions", play);
|
49
|
52
|
socket.on("lolheded", endGame);
|
50
|
53
|
socket.on("end", onEnd);
|
|
54
|
+ socket.on("qpass", function() {
|
|
55
|
+ reponseUser = -1;
|
|
56
|
+ checkAnswer();
|
|
57
|
+ })
|
51
|
58
|
};
|
52
|
59
|
|
53
|
60
|
function onEnd(score) {
|
|
@@ -85,7 +92,6 @@ var timing = 5, secRestantes, timer;
|
85
|
92
|
var baseWidth;
|
86
|
93
|
|
87
|
94
|
var score = 0;
|
88
|
|
-var reponseUser = -1, bonneReponse;
|
89
|
95
|
var canClick = true;
|
90
|
96
|
|
91
|
97
|
function apiReq() {
|
|
@@ -126,11 +132,11 @@ function quest(id) {
|
126
|
132
|
+theme.questions[id].intitule);
|
127
|
133
|
if(canClick) {
|
128
|
134
|
$("#rep1").off('click');
|
129
|
|
- $("#rep1").one("click", function() { reponseUser = 1; checkAnswer(); });
|
|
135
|
+ $("#rep1").one("click", function() { reponseUser = 1; checkAnswer(); socket.emit('nextQuestion'); });
|
130
|
136
|
$("#rep2").off('click');
|
131
|
|
- $("#rep2").one("click", function() { reponseUser = 2; checkAnswer(); });
|
|
137
|
+ $("#rep2").one("click", function() { reponseUser = 2; checkAnswer(); socket.emit('nextQuestion'); });
|
132
|
138
|
$("#both").off('click');
|
133
|
|
- $("#both").one("click", function() { reponseUser = 0; checkAnswer(); });
|
|
139
|
+ $("#both").one("click", function() { reponseUser = 0; checkAnswer(); socket.emit('nextQuestion'); });
|
134
|
140
|
}
|
135
|
141
|
}
|
136
|
142
|
|
|
@@ -191,7 +197,6 @@ function nextQuestion() {
|
191
|
197
|
}
|
192
|
198
|
|
193
|
199
|
function play(questions) {
|
194
|
|
- console.log(questions);
|
195
|
200
|
json = questions;
|
196
|
201
|
loadCat(id_cat);
|
197
|
202
|
}
|