diff --git a/IPreoject-CLientSide/__pycache__/main.cpython-38.pyc b/IPreoject-CLientSide/__pycache__/main.cpython-38.pyc index c96cb79..99426cb 100644 Binary files a/IPreoject-CLientSide/__pycache__/main.cpython-38.pyc and b/IPreoject-CLientSide/__pycache__/main.cpython-38.pyc differ diff --git a/IPreoject-CLientSide/main.py b/IPreoject-CLientSide/main.py index 064e10c..1f6f61a 100644 --- a/IPreoject-CLientSide/main.py +++ b/IPreoject-CLientSide/main.py @@ -112,9 +112,9 @@ def apitest(): # reqParms = request # return render_template('test.html', param=reqParms) x = request.get_json(silent=True) - print(json.loads(request.data.decode("utf-8"))) + # print(json.loads(request.data.decode("utf-8"))) # log the user out - return render_template('test.html', X = x) + return x diff --git a/IPreoject-CLientSide/static/images/temp/card1.jpg b/IPreoject-CLientSide/static/images/temp/card1.jpg index 9e7451a..f4d5728 100644 Binary files a/IPreoject-CLientSide/static/images/temp/card1.jpg and b/IPreoject-CLientSide/static/images/temp/card1.jpg differ diff --git a/IPreoject-CLientSide/static/images/temp/card2.jpg b/IPreoject-CLientSide/static/images/temp/card2.jpg index 0d659ff..e5aa59e 100644 Binary files a/IPreoject-CLientSide/static/images/temp/card2.jpg and b/IPreoject-CLientSide/static/images/temp/card2.jpg differ diff --git a/IPreoject-CLientSide/static/js/new-g.js b/IPreoject-CLientSide/static/js/new-g.js index 9d26ab0..7552ab8 100644 --- a/IPreoject-CLientSide/static/js/new-g.js +++ b/IPreoject-CLientSide/static/js/new-g.js @@ -62,21 +62,15 @@ 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(); +const URL = 'http://192.168.37.69:50001/route/' + + +var count = 0; function clickEvent(e) { // e = Mouse click event. @@ -86,61 +80,74 @@ function clickEvent(e) { // localStorage.setItem('xPosition', x); // localStorage.setItem('yPosition', y); - console.log(card4); + + console.log("OK"); + httpRequest = new XMLHttpRequest(); - //console.log("OK"); - //httpRequest = new XMLHttpRequest(); + if(!httpRequest) { + alert('Giving Up! Cannot send an XMLHTTO request.'); + } + + // httpRequest.withCredentials = true; + httpRequest.open('POST', 'http://192.168.37.69:50001/pixels/'+count); + + + var card1 = document.getElementById('card1'); + var card2 = document.getElementById('card2'); + + console.log("OK"); + var data = {}; + data.X = x; + data.Y = y; + console.log(data) + var res = JSON.stringify(data); + console.log("OK"); + + httpRequest.send(res); + console.log("OK"); - // if(!httpRequest) { + httpRequest.onload = function() {//Call a function when the state changes. + console.log('-------------') + if(httpRequest.status == 200) { + if(this.responseText == "OK") { + + count++; + score++; + elScore.textContent = ' '+ score; + card1.src = URL + count; + card2. src = URL + (count+1); + + } else if(this.responseText == "FINI") { + 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/"; + } + } + } + } + //console.log(JSON.stringify(data)) + // var xhr = new XMLHttpRequest(); + + // if(!xhr) { // alert('Giving Up! Cannot send an XMLHTTO request.'); // } + + // xhr.open('POST', 'http://192.168.37.69:50001/pools'); + // xhr.send(); + + + // console.log(xhr.response); + + - //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() { @@ -149,24 +156,6 @@ function restartGame() { -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"; - - } -} diff --git a/IPreoject-CLientSide/templates/new-game.html b/IPreoject-CLientSide/templates/new-game.html index c8f1461..3ec1e0f 100644 --- a/IPreoject-CLientSide/templates/new-game.html +++ b/IPreoject-CLientSide/templates/new-game.html @@ -35,9 +35,7 @@

Click on the common object here

- simple card - - + simple card @@ -45,7 +43,7 @@ @@ -61,7 +59,7 @@ - +