-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjeu.php
359 lines (320 loc) · 14.1 KB
/
jeu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<!DOCTYPE html>
<html lang="fr">
<?php
// Chargement des données de configuration du jeu
include ('jeuConnexion.php');
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="description" content="MatrimoineGo">
<title><?php echo $titreJeu;?></title>
<link rel="shortcut icon" href="img/favicon.ico">
<link rel="stylesheet" href="css/style.css?v=<?php echo (time());?>">
<!------------------------------jquery-------------------------->
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://code.jquery.com/ui/1.8.21/jquery-ui.min.js"></script>
<!------------------------CDN jquery punch----------------------->
<script src="./js/jquery.ui.touch-punch.js"></script>
<!---------------------------- MapBox -------------------------->
<script src='https://api.mapbox.com/mapbox-gl-js/v1.0.0/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v1.0.0/mapbox-gl.css' rel='stylesheet' />
<!------------------------- OSM Buildings ----------------------->
<link href="https://cdn.osmbuildings.org/4.0.1/OSMBuildings.css" rel="stylesheet">
<script src="https://cdn.osmbuildings.org/4.0.1/OSMBuildings.js"></script>
<!----------------------- Matrimoine GO -------------------------->
<script src="js/matrimoineGo.js?v=<?php echo (time());?>"></script>
<script type="text/javascript">
function distance(x1,y1,x2,y2){
return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
var xCreatrice = 0;
var yCreatrice = 0;
var score = 10;
var nbrElementPoint=0;
//bonne réponse ou mauvaise
var imgRevient = true;
function changeScore(point){
$("#plurielScore").append("<div class='negatif'>"+point+"</div>");
$(".negatif").css({"left": $("#Tscore")[0].offsetLeft+ "px", "top":"-10px"});
if(point=="+1"){
$(".negatif").css({"color":"green"});
$(".negatif").animate({"top":"-200px","opacity":"0.2"},2000,function(){$(".negatif").remove();});
nbrElementPoint = nbrElementPoint + 1;
console.log(nbrElementPoint);
score = score + 1;
}
if(point=="-1"){
$(".negatif").css({"color":"red"});
$(".negatif").animate({"top":"5px","opacity":"0.2"},2000,function(){$(".negatif").remove();});
score = score - 1;
console.log("-1");
}
$("#Tscore").html(score);
if((score>-2) && (score<2)){
$("#plurielScore").hide();
} else {
$("#plurielScore").show();
}
// Mise à jour du lien de passage à l'étape suivante
$("#nextStep").attr("href","drag.php?id=<?php echo intval($_GET['id']); ?>&score="+score);
}
function finNiveau1(){
// Création d'une modale
//console.log(score);
pop_up('','<center><?php echo $messageScore ?>'+score+'.</center>','Étape suivante','drag.php?id=<?php echo intval($_GET['id']); ?>&score='+score,false,false);
}
function devoileCarte(){
$(".relative").animate({top:"0vh"},2000);
}
$(document).ready(function() {
pop_up("<p><strong>Première étape</strong></p>","<?php echo $accueil_jeu; ?>","","",true,false);
devoileCarte();
// initialisation du score
$("#Tscore").html(score);
map.addControl(new mapboxgl.GeolocateControl({positionOptions: {enableHighAccuracy: true},trackUserLocation: true}));
});
</script>
</head>
<body id="body3">
<div class="menuFemme">
<?php
// Création du menu femme (jcdd_contenu) et de la modale de biographie
$sql = "SELECT id, jeu, femme, photo_femme, photo_femme_source, photo_femme_licence, longitude, latitude, indice_femme,indice_lieu, photo_lieu, photo_lieu_source, photo_lieu_licence, date_naissance, date_mort, question_quizz, reponse1, reponse2, reponse3, ok_reponse1, ok_reponse2, ok_reponse3, biographie FROM jcdd_contenu WHERE jeu = ? ORDER BY RAND();";
$titreFemme = 'var titre =["","","","","",""];';
$biographie = 'var bio =["","","","",""];';
$req = $link->prepare($sql);
$req -> execute([intval($_GET['id'])]);
while($data = $req -> fetch()){
$balise_A_ouvrante="";
$balise_A_fermante="";
if ($data['photo_lieu_source']!="") {
$balise_A_fermante="</a>";
$balise_A_ouvrante='<a href=\\"'.$data['photo_lieu_source'].' \\"rel=\\"follow\\" target=\\"_blank\\">';
}
$titreFemme.='titre['.$data['id'].']="'.$data["femme"].'";';
$biographie.='bio['.$data['id'].']="<p><img src=\\"'.$data['photo_femme'].'\\" style=\\"float:right;margin-left:20px;\\" alt=\\"'.$data['femme'].'\\">'.$data["biographie"].'</p><p>Source du portrait : <a href=\\"'.$data['photo_femme_source'].' \\"rel=\\"follow\\" target=\\"_blank\\">'.$data['photo_femme_licence'].'</a></p>";';
echo '<div id="p'.$data['id'].'" class="relative"><img src="'.$data['photo_femme'].'" class="photoFemme" id="i'.$data['id'].'" alt="'.$data['femme'].'"><img class="questionMark" id="f'.$data['id'].'" src="img/icon/question-markB.png" alt="bouton qui est-ce" title="qui est-ce ?">
<script>
$("#f'.$data['id'].'").click(function() {
pop_up("<span style=\"color:#FC706D; font-size:1.1rem;margin:2px;\">'.$data['femme'].'</span>","<p>'.str_replace('"','\\"',$data['indice_femme']).'</p><p>Source du portrait : <a href=\\"'.$data['photo_femme_source'].' \\"rel=\\"follow\\" target=\\"_blank\\">'.$data['photo_femme_licence'].'</a></p>","","",true,false);
});
$(document).on("click","#m'.$data['id'].'",function(){
pop_up("","<strong>Indice :</strong> '.$data['indice_lieu'].'<br><img class=\"imgIndiceLieu\" src=\"'.$data['photo_lieu'].'\" alt=\"\"><div class=\"center\"><br>'.$balise_A_ouvrante.$data['photo_lieu_licence'].$balise_A_fermante.'</div><h2>Bonus Quizz</h2> <h4 style=\"margin:0;\">'.str_replace('"','\\"',$data['question_quizz']).'</h4><br><input type=\"checkbox\" id=\"rep1\" name=\"rep1\" data-reponse1=\"'.$data['ok_reponse1'].'\"><label id=\"t_quizz1\" for=\"rep1\">'.str_replace('"','\\"',$data['reponse1']).'</label><br><input type=\"checkbox\" id=\"rep2\" name=\"rep2\"data-reponse2=\"'.$data['ok_reponse2'].'\"><label id=\"t_quizz2\" for=\"rep2\">'.str_replace('"','\\"',$data['reponse2']).'</label><br><input type=\"checkbox\" id=\"rep3\" name=\"rep3\"data-reponse3=\"'.$data['ok_reponse3'].'\"><label id=\"t_quizz3\" for=\"rep3\">'.str_replace('"','\\"',$data['reponse3']).'</label><br><input class=\"butSol\" type=\"submit\" value=\"Solution\">","","",true,true);
});
</script>
</div>';
}
?>
</div>
<?php
//Préparation de la carte-------------
$sql = "SELECT id,jeu,femme,photo_femme, femme, longitude, latitude, indice_femme ,categorie FROM jcdd_contenu WHERE jeu = ? AND categorie>0 ORDER BY RAND()" ;
$req = $link->prepare($sql);
$req -> execute([intval($_GET['id'])]);
$moyennelg = 0;
$moyennelt = 0;
$compteur = 0;
while($data = $req -> fetch()){
$lg= $data['longitude'];
$lt= $data['latitude'];
$moyennelg += $lg;
$moyennelt += $lt;
$compteur ++;
}
$moyennelg /= $compteur;
$moyennelt /= $compteur;
?>
<div id="map" style="align-content: center;justify-content:center;height:90vh; margin-top:10vh; margin-bottom:auto"></div>
<script type="text/javascript">$(document).ready(function() {
<?php
echo $biographie;
echo $titreFemme;
?>
$('.relative').draggable({
scroll: false,
containment: ".body3",
revert: false,
cursorAt: {bottom:5},
distance: 50,
snap: true,//valeur default
both: true,
start: function( event, ui ) {
xCreatrice=$(this).css("left");
yCreatrice=$(this).css("top");
ui.helper.context.style.opacity="0.7";
},
drag: function(event, ui) {
var distanceMini;
var compteurDrag=0;
var meilleurMarker;
$(".marker").each(function(){
var c = $(this).css('transform') ;
var t = c.replace(')','').split(',');
var xp = ui.offset.left;
var yp = ui.offset.top-parseInt($(this).css("height"));
var xm = t[t.length-2];
var ym = t[t.length-1];
if(compteurDrag==0 || distance(xp,yp,xm,ym)<distanceMini){
distanceMini= distance(xp,yp,xm,ym);
meilleurMarker=$(this);
}
compteurDrag++;
})
if(distanceMini <50){
$(".marker").addClass('markerR');
$(".marker").removeClass('markerB');
meilleurMarker.addClass('markerB');
meilleurMarker.removeClass('markerR');
//console.log("markeur");
//console.log(ui.helper.context.firstElementChild.currentSrc);
//console.log(ui);
} else{
meilleurMarker.addClass('markerR');
meilleurMarker.removeClass('markerB');
}
},
stop: function( event, ui ) {
imgRevient=true;
ui.helper.context.style.opacity="1";
var distanceMini;
var compteurDrag = 0;
var meilleurMarker;
$(".marker").each(function(){
var c = $(this).css('transform') ;
var t = c.replace(')','').split(',');
var xp = ui.offset.left;
var yp = ui.offset.top-parseInt($(this).css("height"));
var xm = t[t.length-2];
var ym = t[t.length-1];
if(compteurDrag==0 || distance(xp,yp,xm,ym)<distanceMini){
distanceMini= distance(xp,yp,xm,ym);
meilleurMarker=$(this);
}
compteurDrag++;
$(this).children().hide();
//console.log('cache');
})
if(distanceMini <50){
if($(this).attr("id").replace("p","") == meilleurMarker.attr("id").replace("m","")){
// Bonne réponse
changeScore("+1");
// Remplacement de l'image du marqueur par le portrait de la femme
imgRevient=false;
ui.helper.context.style.display = "none";
meilleurMarker.removeClass('markerB');
meilleurMarker.css('background-image',"url("+ui.helper.context.firstElementChild.currentSrc+")");
// Affichage de la biographie
pop_up('<span style=\"color:#FC706D; font-size:1.1rem;margin:2px;\">'+titre[$(this).attr("id").replace("p","")]+' ',''+bio[$(this).attr("id").replace("p","")]+'','','',true,true);
} else{
// Si mauvaise réponse, -1
changeScore("-1");
}
}
if(imgRevient==true){
// L'image de l'artiste revient à son emplacement initial
ui.helper.context.style.display="block";
meilleurMarker.removeClass('markerB');
meilleurMarker.addClass('markerR');
$("#Tscore").html(score);
}
if(imgRevient){
$(this).animate({left:xCreatrice,top:yCreatrice},600,"easeOutCirc");
}
}
});
});
// Initialisation de la carte
mapboxgl.accessToken = '<?php echo ($clefApiMapbox); ?>';
var map = new mapboxgl.Map({
style: 'https://data.osmbuildings.org/0.2/anonymous/style.json',
center: [ <?php echo $moyennelg; ?> , <?php echo $moyennelt; ?> ],
zoom: 15.3,
pitch: 45,
bearing: -17.6,
container: 'map'
});
// The 'building' layer in the mapbox-streets vector source contains building-height
// data from OpenStreetMap.
map.on('load', function() {
// Insert the layer beneath any symbol layer.
var layers = map.getStyle().layers;
var labelLayerId;
for (var i = 0; i < layers.length; i++) {
if (layers[i].type === 'symbol' && layers[i].layout['text-field']) {
labelLayerId = layers[i].id;
break;
}
}
map.addLayer({
'id': '3d-buildings',
'source': 'composite',
'source-layer': 'building',
'filter': ['==', 'extrude', 'true'],
'type': 'fill-extrusion',
'minzoom': 15,
'paint': {
'fill-extrusion-color': '#aaa',
// use an 'interpolate' expression to add a smooth transition effect to the
// buildings as the user zooms in
'fill-extrusion-height': [
"interpolate", ["linear"],
["zoom"],
15, 0,
15.05, ["get", "height"]
],
'fill-extrusion-base': [
"interpolate", ["linear"],
["zoom"],
15, 0,
15.05, ["get", "min_height"]
],
'fill-extrusion-opacity': .6
}
}, labelLayerId);
});
map.on('load', function() {
//Création des marqueurs
var geojson = {
type: 'FeatureCollection',
features: [ <?php
$sql = "SELECT id,jeu,femme,photo_femme, femme, longitude, latitude, indice_lieu, adresse ,categorie FROM jcdd_contenu WHERE jeu = ? AND categorie>0 ORDER BY RAND()";
$req = $link -> prepare($sql);
$req -> execute([intval($_GET['id'])]);
while ($data = $req -> fetch()) {
echo "{
type: 'Feature',id:".$data['id'] ." ,
geometry: {
type: 'Point',
coordinates: [".$data['longitude'] .", ". $data['latitude'] ."]
},
properties: {
title: 'Mapbox',
description: \"".str_replace('"', '\"', $data['adresse'])."\"
}
}, ";
}
?>
]
};
geojson.features.forEach(function(marker) {
// create a HTML element for each feature
var el = document.createElement('div');
el.className = 'marker markerR';
// make a marker for each feature and add to the map
var mark = new mapboxgl.Marker(el, {})
.setLngLat(marker.geometry.coordinates)
.addTo(map);
mark._element.id="m"+marker.id;
});
});
// Add zoom and rotation controls to the map.
map.addControl(new mapboxgl.NavigationControl());
</script>
<div class="score">
<span class="Tscore"><span id="Tscore"></span> point<span id="plurielScore">s</span></span>
<div class="Tscore" style="position:absolute;right:20px; "><a id="nextStep" href="drag.php?id=<?php echo intval($_GET['id']); ?>&score=10">Étape suivante</a></div>
</div>
</body>
</html>