diff --git a/IPreoject-CLientSide/__pycache__/main.cpython-38.pyc b/IPreoject-CLientSide/__pycache__/main.cpython-38.pyc index 33f58f9..c96cb79 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 c048e58..064e10c 100644 --- a/IPreoject-CLientSide/main.py +++ b/IPreoject-CLientSide/main.py @@ -66,25 +66,41 @@ def stringToRGB(base64_string): -API_CARD = "http://192.168.37.69:50001/cards" +API_CARD = "http://192.168.37.69:50001/time" @app.route("/new-game", methods=['POST', 'GET']) def getCards(): res = requests.get(API_CARD).json() - card = res.get('la_carte') # our port - cards_array = np.array(json.loads(card)) - img = Image.fromarray(np.uint8(cards_array)) - pil_img = serve_pil_image(img) - print(type(pil_img)) - pil_img.direct_passthrough = False - print(type(pil_img.data)) - imageStream = io.BytesIO(pil_img.data) - imageFile = Image.open(imageStream) - print(type(imageFile)) + card1 = res.get('first_card') # our port + card2 = res.get('second_card') + + card1_array = np.array(json.loads(card1)) + card2_array = np.array(json.loads(card2)) + + img1 = Image.fromarray(np.uint8(card1_array)) + img2 = Image.fromarray(np.uint8(card2_array)) + + pil_img1 = serve_pil_image(img1) + pil_img2 = serve_pil_image(img2) + + pil_img1.direct_passthrough = False + pil_img2.direct_passthrough = False + + print(type(pil_img1.data)) + + imageStream1 = io.BytesIO(pil_img1.data) + imageFile1 = Image.open(imageStream1) + + imageStream2 = io.BytesIO(pil_img2.data) + imageFile2 = Image.open(imageStream2) + buffer = io.BytesIO() - imageFile.save(buffer, format='JPEG') - print(type(imageFile)) - card = imageFile.save("./static/images/temp/card1.jpg") + imageFile1.save(buffer, format='JPEG') + imageFile2.save(buffer, format='JPEG') + + imageFile1.save("./static/images/temp/card1.jpg") + imageFile2.save("./static/images/temp/card2.jpg") + return render_template('new-game.html') diff --git a/IPreoject-CLientSide/static/images/Card4.jpg b/IPreoject-CLientSide/static/images/Card4.jpg deleted file mode 100644 index da1ebe0..0000000 Binary files a/IPreoject-CLientSide/static/images/Card4.jpg and /dev/null differ diff --git a/IPreoject-CLientSide/static/images/card1.png b/IPreoject-CLientSide/static/images/card1.png deleted file mode 100644 index 0758422..0000000 Binary files a/IPreoject-CLientSide/static/images/card1.png and /dev/null differ diff --git a/IPreoject-CLientSide/static/images/card2.png b/IPreoject-CLientSide/static/images/card2.png deleted file mode 100644 index eafb64a..0000000 Binary files a/IPreoject-CLientSide/static/images/card2.png and /dev/null differ diff --git a/IPreoject-CLientSide/static/images/card3.png b/IPreoject-CLientSide/static/images/card3.png deleted file mode 100644 index 95116e9..0000000 Binary files a/IPreoject-CLientSide/static/images/card3.png and /dev/null differ diff --git a/IPreoject-CLientSide/static/images/card4.png b/IPreoject-CLientSide/static/images/card4.png deleted file mode 100644 index f2ebb78..0000000 Binary files a/IPreoject-CLientSide/static/images/card4.png and /dev/null differ diff --git a/IPreoject-CLientSide/static/images/temp/card1.jpg b/IPreoject-CLientSide/static/images/temp/card1.jpg index 80d04bb..c9a57c4 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 new file mode 100644 index 0000000..031b5e3 Binary files /dev/null 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 d28193d..9d26ab0 100644 --- a/IPreoject-CLientSide/static/js/new-g.js +++ b/IPreoject-CLientSide/static/js/new-g.js @@ -21,7 +21,7 @@ function tick(){ sec = 0; min = 0; hrs = 0; - ress = confirm("This part is finished! YOU SCORE IS:" + score + "Do you want to spot it again?"); + 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"; } @@ -70,10 +70,13 @@ var httpRequest; var card1 = document.getElementById('clickme'); -var card2 = document.getElementById('card2'); -var card3 = document.getElementById('card3'); -var card4 = document.getElementById('card4'); +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. @@ -83,54 +86,61 @@ function clickEvent(e) { // localStorage.setItem('xPosition', x); // localStorage.setItem('yPosition', y); - + console.log(card4); //console.log("OK"); - httpRequest = new XMLHttpRequest(); + //httpRequest = new XMLHttpRequest(); - if(!httpRequest) { - alert('Giving Up! Cannot send an XMLHTTO request.'); - } + // if(!httpRequest) { + // alert('Giving Up! Cannot send an XMLHTTO request.'); + // } - httpRequest.open('POST', 'http://127.0.0.1:5000/apitest'); + //httpRequest.open('POST', 'http://127.0.0.1:5000/apitest'); //console.log("OK"); - var data = JSON.stringify({X: x}); + //var data = JSON.stringify({X: x}); //console.log("OK"); - httpRequest.send(data); + //httpRequest.send(data); //console.log("OK"); //console.log(data) console.log("Left? : " + x + " ; Top? : " + y + "."); - if( x >= 161 && x <= 219 && y >= 50 && y <= 67 ){ + if( x >= 100 && x <= 157 && y >= 79 && y <= 160 ){ score++; - elScore.textContent = score; - ress = confirm("GOOD You win :) DO YOU WANT TO PLAY AGAIN ?"); + elScore.textContent = ' '+ score; + // ress = confirm("GOOD You win :) DO YOU WANT TO PLAY AGAIN ?"); - if(ress){ + // 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"; - - card1.style.display = "none"; - card2.style.display = "block"; - card3.style.display = "none"; - card4.style.display = "block"; - sec = localStorage.getItem('globalTime'); - } - else{ - window.location.href = "http://127.0.0.1:5000/"; - } } - - // var xhr = new XMLHttpRequest(); - // xhr.open("POST", yourUrl, true); - // xhr.setRequestHeader('Content-Type', 'application/json'); - // xhr.send(JSON.stringify({ - // x: x, - // y: y - // })) } function restartGame() { @@ -145,28 +155,17 @@ function clickEvent2(e) { var x = e.clientX - rect.left; var y = e.clientY - rect.top; - httpRequest = new XMLHttpRequest(); - - if(!httpRequest) { - alert('Giving Up! Cannot send an XMLHTTO request.'); - } - httpRequest.open('POST', 'http://127.0.0.1:5000/apitest'); - var data = JSON.stringify({X: x}); - httpRequest.send(data); console.log("Left? : " + x + " ; Top? : " + y + "."); - if( x >= 126 && x <= 218 && y >= 26 && y <= 276 ){ - 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/"; - } - } + 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 11e9aa4..c8f1461 100644 --- a/IPreoject-CLientSide/templates/new-game.html +++ b/IPreoject-CLientSide/templates/new-game.html @@ -25,7 +25,7 @@ - Score : 0 + Score : 0