From 79df1ed8e463860e288cf65ffc91c1343dc6c4a2 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Mon, 12 Apr 2021 02:01:46 +0200 Subject: [PATCH] Change left and right exit behaviour This changes the behaviour for left and right exits so that pac-man does not exit when entering the last accessible square but only when he goes left or right from the last square --- app.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index fa67849..4c79b85 100644 --- a/app.js +++ b/app.js @@ -80,15 +80,14 @@ document.addEventListener('DOMContentLoaded', () => { squares[pacmanCurrentIndex].classList.remove('pac-man') switch(e.keyCode) { case 37: - if( + if (squares[pacmanCurrentIndex -1] === squares[363]) { + pacmanCurrentIndex = 391 + } else if( pacmanCurrentIndex % width !== 0 && !squares[pacmanCurrentIndex -1].classList.contains('wall') && !squares[pacmanCurrentIndex -1].classList.contains('ghost-lair') ) pacmanCurrentIndex -= 1 - if (squares[pacmanCurrentIndex -1] === squares[363]) { - pacmanCurrentIndex = 391 - } break case 38: if( @@ -99,15 +98,14 @@ document.addEventListener('DOMContentLoaded', () => { pacmanCurrentIndex -= width break case 39: - if( + if (squares[pacmanCurrentIndex +1] === squares[392]) { + pacmanCurrentIndex = 364 + } else if( pacmanCurrentIndex % width < width - 1 && !squares[pacmanCurrentIndex +1].classList.contains('wall') && !squares[pacmanCurrentIndex +1].classList.contains('ghost-lair') ) pacmanCurrentIndex += 1 - if (squares[pacmanCurrentIndex +1] === squares[392]) { - pacmanCurrentIndex = 364 - } break case 40: if (