From f4b6a44e051dcc66ab885d2005c62a14c0d79427 Mon Sep 17 00:00:00 2001 From: annasandri Date: Mon, 17 May 2021 14:16:43 +0100 Subject: [PATCH] box --- .../.ipynb_checkpoints/park_N-checkpoint.html | 102 ++++++++++++------ tree/park_N.html | 87 +++++++-------- 2 files changed, 111 insertions(+), 78 deletions(-) diff --git a/tree/.ipynb_checkpoints/park_N-checkpoint.html b/tree/.ipynb_checkpoints/park_N-checkpoint.html index 8d804be..40e6207 100644 --- a/tree/.ipynb_checkpoints/park_N-checkpoint.html +++ b/tree/.ipynb_checkpoints/park_N-checkpoint.html @@ -8,22 +8,11 @@ -
- - - -
- - - - + +
@@ -37,16 +26,28 @@ - + + + + + + + + + + + + + + +
- - - -
-move +
+ Move around the park with the arrows ←↑↓→ and click on the people to ask them if they saw who left the newspaper on the bench. +
@@ -56,7 +57,7 @@ move // player moves var $div = $('#player_img'); - var screenLeftMin = 0; + var screenLeftMin = 200; var screenLeftMax = 870; function adjustScroll() { @@ -78,25 +79,55 @@ move $(document).keydown(function(e) { + var offset = $div.position(); + console.log("offset:", offset); + switch (e.which) { case 37: - $div.css('left', $div.offset().left - 20); - e.preventDefault(); - adjustScroll(); - break; + /* $div.css('left', $div.offset().left - 20);*/ + offset.left -= 20; + console.log("left"); + break; case 38: - $div.css('top', $div.offset().top - 20); + // $div.css('top', $div.offset().top - 20); + offset.top -= 20; + console.log("top"); break; case 39: - $div.css('left', $div.offset().left + 20); - e.preventDefault(); - adjustScroll(); + //$div.css('left', $div.offset().left + 20); + offset.left += 20; + console.log("right"); break; case 40: - $div.css('top', $div.offset().top + 20); + //$div.css('top', $div.offset().top + 20); + offset.top += 20; + console.log("down"); break; - } + } + //check the offset + if (offset.left < 0) { + offset.left = 0; + } + if (offset.left > $("#ground").width() - 50) { + offset.left = $("#ground").width() - 50; + + } + + if (offset.top < 0) { + offset.top = 0; + } + if (offset.top > $("#ground").height() - 100) { + offset.top = $("#ground").height() - 100; + + } + + $div.css("left", offset.left); + $div.css("top", offset.top); + e.preventDefault(); + adjustScroll(); + }) + // saves game step in the local storage window.onload = function() { @@ -112,13 +143,20 @@ $(document).keydown(function(e) { player_img.appendChild(img); //get player name from local storage - document.querySelector('#player_name').innerHTML =localStorage.playerName; + $("#woman").click (function(){ + $(".woman_bubble").toggle(); + }); + + $("#newspaper_seller").click (function(){ + $(".vendor_bubble").toggle(); + }); - + + \ No newline at end of file diff --git a/tree/park_N.html b/tree/park_N.html index 29890d1..40e6207 100644 --- a/tree/park_N.html +++ b/tree/park_N.html @@ -41,25 +41,13 @@ - - - - -
- Move around the park with the arrows ←↑↓→ and click on the people to ask them if they saw the owner of the newspaper. + Move around the park with the arrows ←↑↓→ and click on the people to ask them if they saw who left the newspaper on the bench.
- - -
@@ -91,29 +79,55 @@ $(document).keydown(function(e) { + var offset = $div.position(); + console.log("offset:", offset); + switch (e.which) { case 37: - $div.css('left', $div.offset().left - 20); - e.preventDefault(); - adjustScroll(); - break; + /* $div.css('left', $div.offset().left - 20);*/ + offset.left -= 20; + console.log("left"); + break; case 38: - $div.css('top', $div.offset().top - 20); - e.preventDefault(); - adjustScroll(); + // $div.css('top', $div.offset().top - 20); + offset.top -= 20; + console.log("top"); break; case 39: - $div.css('left', $div.offset().left + 20); - e.preventDefault(); - adjustScroll(); + //$div.css('left', $div.offset().left + 20); + offset.left += 20; + console.log("right"); break; case 40: - $div.css('top', $div.offset().top + 20); - e.preventDefault(); - adjustScroll(); + //$div.css('top', $div.offset().top + 20); + offset.top += 20; + console.log("down"); break; - } + } + //check the offset + if (offset.left < 0) { + offset.left = 0; + } + if (offset.left > $("#ground").width() - 50) { + offset.left = $("#ground").width() - 50; + + } + + if (offset.top < 0) { + offset.top = 0; + } + if (offset.top > $("#ground").height() - 100) { + offset.top = $("#ground").height() - 100; + + } + + $div.css("left", offset.left); + $div.css("top", offset.top); + e.preventDefault(); + adjustScroll(); + }) + // saves game step in the local storage window.onload = function() { @@ -139,25 +153,6 @@ $(document).keydown(function(e) { $(".vendor_bubble").toggle(); }); - $("#sport1").click (function(){ - $(".fit2_bubble").toggle(); - }); - - $("#sport2").click (function(){ - $(".fit1_bubble").toggle(); - }); - - $("#ned").click (function(){ - $(".ned_bubble1, .ned_bubble2").toggle(); - $(".message1").hide(); - $(".message2").show(); - }); - - $(".ned1").click (function(){ - $(".message2").hide(); - $(".ned_bubble3,.message3 ").show(); - }); -