var h5 = document.getElementsByTagName('h5')[0]; // var start = document.getElementById('strt'); // var stop = document.getElementById('stp'); // var reset = document.getElementById('rst'); var score = 0; var elScore = document.getElementById('score'); var sec = localStorage.getItem('globalTime'); var min = 0; var hrs = 0; var t; function tick(){ if( sec > 0){ sec--; if(sec == 0){ sec = 0; min = 0; hrs = 0; ress = confirm("This part is finished! YOU SCORE IS: " + score + " | Do you want to spot it again?"); if(ress){ window.location.href = "http://127.0.0.1:5000/rules"; } else{ window.location.href = "http://127.0.0.1:5000/"; } } } } function add() { tick(); h5.textContent = (hrs > 9 ? hrs : "0" + hrs) + ":" + (min > 9 ? min : "0" + min) + ":" + (sec > 9 ? sec : "0" + sec); timer(); } function timer() { t = setTimeout(add, 1000); } timer(); // start.onclick = timer; // stop.onclick = function() { // clearTimeout(t); // } // reset.onclick = function() { // h5.textContent = "00:00:00"; // seconds = 0; minutes = 0; hours = 0; // } var httpRequest; // document.getElementById('clickme').onclick = // var card1 = document.getElementById('clickme'); // var card2 = document.getElementById('card2'); // var card3 = document.getElementById('card3'); // var card4 = document.getElementById('card4'); var card1 = document.getElementById('clickme'); var card2 = document.getElementById('card1'); var card3 = document.getElementById('card2'); var card4 = document.getElementById('card'); const URL = 'http://192.168.37.69:50001/cards' var xhr = new XMLHttpRequest(); function clickEvent(e) { // e = Mouse click event. var rect = e.target.getBoundingClientRect(); var x = e.clientX - rect.left; //x position within the element. var y = e.clientY - rect.top; //y position within the element. // localStorage.setItem('xPosition', x); // localStorage.setItem('yPosition', y); console.log(card4); //console.log("OK"); //httpRequest = new XMLHttpRequest(); // if(!httpRequest) { // alert('Giving Up! Cannot send an XMLHTTO request.'); // } //httpRequest.open('POST', 'http://127.0.0.1:5000/apitest'); //console.log("OK"); //var data = JSON.stringify({X: x}); //console.log("OK"); //httpRequest.send(data); //console.log("OK"); //console.log(data) console.log("Left? : " + x + " ; Top? : " + y + "."); if( x >= 100 && x <= 157 && y >= 79 && y <= 160 ){ score++; elScore.textContent = ' '+ score; // ress = confirm("GOOD You win :) DO YOU WANT TO PLAY AGAIN ?"); // if(ress){ // sec = localStorage.getItem('globalTime'); // } // else{ // window.location.href = "http://127.0.0.1:5000/"; // } // xhr.onreadystatechange = function() { // if (xhr.readyState == XMLHttpRequest.DONE) { // json = JSON.parse(xhr.response); // var encodedData = btoa(json["la_carte"]); // var image = new Image(); // image.src = 'data:image/png;base64,'+encodedData; // // alert(encodedData); // } // } // xhr.open('GET', URL, true); // xhr.send(null); card2.src = card1.src; card1.style.display = "none"; card3.style.display = "block"; } } function restartGame() { window.location.href = "http://127.0.0.1:5000/rules"; } function clickEvent2(e) { var rect = e.target.getBoundingClientRect(); var x = e.clientX - rect.left; var y = e.clientY - rect.top; console.log("Left? : " + x + " ; Top? : " + y + "."); if( x >= 74 && x <= 198 && y >= 71 && y <= 196 ){ score++; elScore.textContent = ' '+ score; card2.src = card3.src; card3.style.display = "none"; card4.style.display = "block"; } } // // Diaporamaa : -------------------------------------- // var diaporama = 1; // affichage(diaporama); // function boutons(n) { // affichage(diaporama += n); // } // function actifIndic(n) { // affichage(diaporama = n); // } // function affichage(n) { // var i; // var diapoImg = document.getElementsByClassName("diapo"); // if (n > diapoImg.length) {diaporama = 1} // if (n < 1) {diaporama = diapoImg.length} // for (i = 0; i < diapoImg.length; i++) { // diapoImg[i].style.opacity = "0"; // } // diapoImg[diaporama-1].style.opacity = "1"; // }