From a4161f9e952dd10e554ff9358f2afc09ca6e26a6 Mon Sep 17 00:00:00 2001 From: Laurent Sehabiague Date: Wed, 15 Jan 2020 14:25:25 -0500 Subject: [PATCH 01/13] add door --- css/images/door.png | Bin 0 -> 24888 bytes css/main-snake.css | 11 ++++ js/snake.js | 132 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 css/images/door.png diff --git a/css/images/door.png b/css/images/door.png new file mode 100644 index 0000000000000000000000000000000000000000..8454761ec5dd712eab39bb5da1d2ecfb62056709 GIT binary patch literal 24888 zcmeHPc~q0vw*MGfu$DrkS9@C~#o_ikP>K|gA<)vIrHZzLNUhRA z;?M#zB=#z`_bQ@I5tOk?>jb3Y6^x8l5s{COGJF9-lDE%yJ|tni|K56Qy|-4fmdku+ zpS|~Q4`-i4vU9#%yC%%;nHQfS2*PgF%FuTS;^|=Y&-Q5;nfq+kN%+qq<=wE?i8GB( zz3^bo30WON5a%Q_CpJC>&oh!&Mx_wMbC=OSiz`V#eoPP>8dimd{DT)uwu?xEA+}|t zk@dnAR_4=D!FlU0&;H=XLGh z4Z9na{6_t#^3+=rN$JTN#jVbPIJS1!izbUt?dnl__-Y@^4gKW1wY)~%ZF#4NdWu6+ z3B^OlM*TIp;Q?vWxa^Csa_+dU(EgL*EbBg^5Oym?+o{W(oQ%4q)Ms7~(hGIpFl0$@ z5?eb*QQc2kadIr{sz{H5D($nh*e>_=_cO=BRb?_k8%FsGStQA=sjJr2m(*FJIbu)E zj=G6Ftx6ujwxXH7YVTtWaa9pAT`>k1d?;*1ys%i%qI_?{f}Y}X=eVn9&2K`3(!Y@& z5Zm13)lIypZNMD0&e6W{`ZoUfmRye&SgPvkAFQFC4o!jJ4~!)FjjUX@LD+|%)R&w* zYgBrfT;Yr7pSj8!%IR#8VTFo%)=;aex8+MgGc!LA=9lQSjK0>c%rTwH;L9H$*+c`X zU7TDuv7K7L(4PWbs%jPXifvfEKh=&YuQafR8Ux$6&}zgl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=DiCD>I(NZ~PGj%M2jsLA=7G-O zO_L9Z(t(w_p><@>2m`lA_2BViFy8EmP5BY#Z^p%d;DIx=MA2By14VXpUp>zwu+=JH(-Qb$qUrAg74XbUq*Ic9SRcj#>k zgQ^a%WBc5i&e@+v3yuh08Ztjgg!Tq_RleomXAmaBzQ^kh92jGZ^(7a5zc`eQXsg~_ L6ME+L4H^FhCHo3j literal 0 HcmV?d00001 diff --git a/css/main-snake.css b/css/main-snake.css index b8720340..9cdff81d 100755 --- a/css/main-snake.css +++ b/css/main-snake.css @@ -83,6 +83,17 @@ a.snake-link:hover { position: absolute; } +.door-block { + margin: 0px; + padding: 0px; + background-color: #FF0000; + border: 0px solid #000080; + position: absolute; + background-image: url('./images/door.png'); + background-position: center; + background-size: contain; +} + .snake-playing-field { margin: 0px; padding: 0px; diff --git a/js/snake.js b/js/snake.js index 02b6653f..e630a328 100644 --- a/js/snake.js +++ b/js/snake.js @@ -346,9 +346,21 @@ SNAKE.Snake = SNAKE.Snake || (function() { return; } setTimeout(function(){me.go();}, snakeSpeed); + } else if (grid[newHead.row][newHead.col] === playingBoard.getGridDoorValue()) { + grid[newHead.row][newHead.col] = 1; + if (!me.closeDoor()) { + return; + } + + showDoorMessage() + setTimeout(function(){me.go();}, snakeSpeed); } }; + function showDoorMessage() { + window.alert("TailGate ALERT!!!!! You left another door open behind you!"); + } + /** * This method is called when it is determined that the snake has eaten some food. * @method eatFood @@ -384,6 +396,14 @@ SNAKE.Snake = SNAKE.Snake || (function() { return true; }; + me.closeDoor = function() { + + if (!playingBoard.doorClosed()) { + return false; + } + return true; + }; + /** * This method handles what happens when the snake dies. * @method handleDeath @@ -564,6 +584,96 @@ SNAKE.Food = SNAKE.Food || (function() { }; })(); +SNAKE.Door = SNAKE.Door || (function() { + + // ------------------------------------------------------------------------- + // Private static variables and methods + // ------------------------------------------------------------------------- + + var instanceNumber = 0; + + function getRandomPosition(x, y){ + return Math.floor(Math.random()*(y+1-x)) + x; + } + + // ------------------------------------------------------------------------- + // Contructor + public and private definitions + // ------------------------------------------------------------------------- + + /* + config options: + playingBoard - the SnakeBoard that this object belongs too. + */ + return function(config) { + + if (!config||!config.playingBoard) {return;} + + // ----- private variables ----- + + var me = this; + var playingBoard = config.playingBoard; + var fRow, fColumn; + var myId = instanceNumber++; + + var elmDoor = document.createElement("div"); + elmDoor.setAttribute("id", "door-"+myId); + elmDoor.className = "door-block"; + elmDoor.style.width = playingBoard.getBlockWidth() + "px"; + elmDoor.style.height = playingBoard.getBlockHeight() + "px"; + elmDoor.style.left = "-1000px"; + elmDoor.style.top = "-1000px"; + playingBoard.getBoardContainer().appendChild(elmDoor); + + // ----- public methods ----- + + /** + * @method getFoodElement + * @return {DOM Element} The div the represents the food. + */ + me.getDoorElement = function() { + return elmDoor; + }; + + /** + * Randomly places the food onto an available location on the playing board. + * @method randomlyPlaceFood + * @return {bool} Whether a food was able to spawn (true) or not (false). + */ + me.randomlyPlaceDoor = function() { + // if there exist some food, clear its presence from the board + //if (playingBoard.grid[fRow] && playingBoard.grid[fRow][fColumn] === playingBoard.getGridDoorValue()){ + // playingBoard.grid[fRow][fColumn] = 0; + //} + + var row = 0, col = 0, numTries = 0; + + var maxRows = playingBoard.grid.length-1; + var maxCols = playingBoard.grid[0].length-1; + + while (playingBoard.grid[row][col] !== 0){ + row = getRandomPosition(1, maxRows); + col = getRandomPosition(1, maxCols); + + // in some cases there may not be any room to put food anywhere + // instead of freezing, exit out (and return false to indicate + // that the player beat the game) + numTries++; + if (numTries > 20000){ + return false; + } + } + + playingBoard.grid[row][col] = playingBoard.getGridDoorValue(); + fRow = row; + fColumn = col; + elmDoor.style.top = row * playingBoard.getBlockHeight() + "px"; + elmDoor.style.left = col * playingBoard.getBlockWidth() + "px"; + + return true; + }; + }; +})(); + /** * This class manages playing board for the game. * @class Board @@ -642,7 +752,9 @@ SNAKE.Board = SNAKE.Board || (function() { blockWidth = 20, blockHeight = 20, GRID_FOOD_VALUE = -1, // the value of a spot on the board that represents snake food, MUST BE NEGATIVE + GRID_DOOR_VALUE = -2, myFood, + myDoor, mySnake, boardState = 1, // 0: in active; 1: awaiting game start; 2: playing game myKeyListener, @@ -708,6 +820,7 @@ SNAKE.Board = SNAKE.Board || (function() { mySnake = new SNAKE.Snake({playingBoard:me,startRow:2,startCol:2}); myFood = new SNAKE.Food({playingBoard: me}); + myDoor = new SNAKE.Door({playingBoard: me}); elmWelcome.style.zIndex = 1000; } @@ -728,7 +841,7 @@ SNAKE.Board = SNAKE.Board || (function() { if (config.fullScreen) { fullScreenText = "On Windows, press F11 to play in Full Screen mode."; } - welcomeTxt.innerHTML = "JavaScript Snake

Use the arrow keys on your keyboard to play the game. " + fullScreenText + "

"; + welcomeTxt.innerHTML = "HIPAA Snake

You left a door open behind you on your way to HIPAA training, Close it now to prevent any intruder to get access to sensible information. Use the arrow keys on your keyboard to play the game. " + fullScreenText + "

"; var welcomeStart = document.createElement("button"); welcomeStart.appendChild(document.createTextNode("Play Game")); var loadGame = function() { @@ -786,10 +899,13 @@ SNAKE.Board = SNAKE.Board || (function() { return tmpElm; } + function createTryAgainElement() { return createGameEndElement("You died :(", "sbTryAgain", "snake-try-again-dialog"); } + + function createWinElement() { return createGameEndElement("You win! :D", "sbWin", "snake-win-dialog"); } @@ -853,6 +969,10 @@ SNAKE.Board = SNAKE.Board || (function() { me.getGridFoodValue = function() { return GRID_FOOD_VALUE; }; + + me.getGridDoorValue = function() { + return GRID_DOOR_VALUE; + }; /** * @method getPlayingFieldElement * @return {DOM Element} The div representing the playing field (this is where the snake can move). @@ -972,6 +1092,7 @@ SNAKE.Board = SNAKE.Board || (function() { } myFood.randomlyPlaceFood(); + myDoor.randomlyPlaceDoor(); myKeyListener = function(evt) { if (!evt) var evt = window.event; @@ -1037,6 +1158,13 @@ SNAKE.Board = SNAKE.Board || (function() { return true; }; + me.doorClosed = function() { + if (!myDoor.randomlyPlaceDoor()) { + return false; + } + return true; + }; + /** * This method is called when the snake dies. * @method handleDeath @@ -1077,3 +1205,5 @@ SNAKE.Board = SNAKE.Board || (function() { }; // end return function })(); + + From b32157a7243a75984e4e5a2146ff3adf39536bb4 Mon Sep 17 00:00:00 2001 From: Laurent Sehabiague Date: Wed, 15 Jan 2020 14:39:06 -0500 Subject: [PATCH 02/13] remove bottom links and theme select box --- js/snake.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/snake.js b/js/snake.js index e630a328..7a16d8f0 100644 --- a/js/snake.js +++ b/js/snake.js @@ -784,7 +784,7 @@ SNAKE.Board = SNAKE.Board || (function() { elmAboutPanel = document.createElement("div"); elmAboutPanel.className = "snake-panel-component"; - elmAboutPanel.innerHTML = "more patorjk.com apps - source code - pat's instagram"; + //elmAboutPanel.innerHTML = "more patorjk.com apps - source code - pat's instagram"; elmLengthPanel = document.createElement("div"); elmLengthPanel.className = "snake-panel-component"; From 9fc5df000bdc596bb1dd3b9d2b96fc7fcff084c9 Mon Sep 17 00:00:00 2001 From: Laurent Sehabiague Date: Wed, 15 Jan 2020 14:41:58 -0500 Subject: [PATCH 03/13] update instructions --- js/snake.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/snake.js b/js/snake.js index 7a16d8f0..ee7bf314 100644 --- a/js/snake.js +++ b/js/snake.js @@ -841,7 +841,7 @@ SNAKE.Board = SNAKE.Board || (function() { if (config.fullScreen) { fullScreenText = "On Windows, press F11 to play in Full Screen mode."; } - welcomeTxt.innerHTML = "HIPAA Snake

You left a door open behind you on your way to HIPAA training, Close it now to prevent any intruder to get access to sensible information. Use the arrow keys on your keyboard to play the game. " + fullScreenText + "

"; + welcomeTxt.innerHTML = "HIPAA Snake

You left a door open (green box) behind you on your way to HIPAA training (red box), Close it now to prevent any intruder to get access to sensible information. Use the arrow keys on your keyboard to play the game. " + fullScreenText + "

"; var welcomeStart = document.createElement("button"); welcomeStart.appendChild(document.createTextNode("Play Game")); var loadGame = function() { From 5cbd74a9cba6683ef0b7e80cf1af124bfeb9e69b Mon Sep 17 00:00:00 2001 From: Laurent Sehabiague Date: Wed, 15 Jan 2020 15:01:13 -0500 Subject: [PATCH 04/13] Hide select theme box and links and show door closed counter --- index.html | 6 +++--- js/snake.js | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 24330506..6ea0fa1e 100755 --- a/index.html +++ b/index.html @@ -40,7 +40,7 @@ case 2: changeTheme('css/dark-snake.css?' + Math.random()); break; - case 3: + case 3: changeTheme('css/green-snake.css?' + Math.random()); break; default: @@ -68,14 +68,14 @@
- Theme: +
Mode: diff --git a/js/snake.js b/js/snake.js index ee7bf314..018cd8e9 100644 --- a/js/snake.js +++ b/js/snake.js @@ -109,6 +109,7 @@ SNAKE.Snake = SNAKE.Snake || (function() { if (!config||!config.playingBoard) {return;} if (localStorage.jsSnakeHighScore === undefined) localStorage.setItem('jsSnakeHighScore', 0); + localStorage.setItem('jsSnakeDoorClosed', 0); // ----- private variables ----- @@ -760,7 +761,7 @@ SNAKE.Board = SNAKE.Board || (function() { myKeyListener, isPaused = false,//note: both the board and the snake can be paused // Board components - elmContainer, elmPlayingField, elmAboutPanel, elmLengthPanel, elmHighscorePanel, elmWelcome, elmTryAgain, elmWin, elmPauseScreen; + elmContainer, elmPlayingField, elmAboutPanel, elmLengthPanel, elmHighscorePanel, elmDoorClosedPanel, elmWelcome, elmTryAgain, elmWin, elmPauseScreen; // --- public variables --- me.grid = []; @@ -794,6 +795,10 @@ SNAKE.Board = SNAKE.Board || (function() { elmHighscorePanel.className = "snake-panel-component"; elmHighscorePanel.innerHTML = "Highscore: " + localStorage.jsSnakeHighScore; + elmDoorClosedPanel = document.createElement("div"); + elmDoorClosedPanel.className = "snake-panel-component"; + elmDoorClosedPanel.innerHTML = "Door Closed: " + localStorage.jsSnakeDoorClosed; + elmWelcome = createWelcomeElement(); elmTryAgain = createTryAgainElement(); elmWin = createWinElement(); @@ -814,6 +819,8 @@ SNAKE.Board = SNAKE.Board || (function() { elmContainer.appendChild(elmAboutPanel); elmContainer.appendChild(elmLengthPanel); elmContainer.appendChild(elmHighscorePanel); + + elmContainer.appendChild(elmDoorClosedPanel); elmContainer.appendChild(elmWelcome); elmContainer.appendChild(elmTryAgain); elmContainer.appendChild(elmWin); @@ -1069,6 +1076,9 @@ SNAKE.Board = SNAKE.Board || (function() { elmHighscorePanel.style.top = pLabelTop; elmHighscorePanel.style.left = cWidth - 140 + "px"; + elmDoorClosedPanel.style.top = pLabelTop; + elmDoorClosedPanel.style.left = cWidth - 340 + "px"; + // if width is too narrow, hide the about panel if (cWidth < 700) { elmAboutPanel.style.display = "none"; @@ -1159,6 +1169,9 @@ SNAKE.Board = SNAKE.Board || (function() { }; me.doorClosed = function() { + var doorClosed = parseInt(localStorage.getItem("jsSnakeDoorClosed"),10) + 1; + localStorage.setItem("jsSnakeDoorClosed", doorClosed); + elmDoorClosedPanel.innerHTML = "Door Closed: " + localStorage.jsSnakeDoorClosed; if (!myDoor.randomlyPlaceDoor()) { return false; } From 9f648469f8ec843b8341e8d4e1476a569bbf25cf Mon Sep 17 00:00:00 2001 From: Laurent Sehabiague Date: Wed, 15 Jan 2020 17:13:25 -0500 Subject: [PATCH 05/13] Remove full screen, make door block green --- css/main-snake.css | 2 +- index.html | 2 +- js/snake.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/css/main-snake.css b/css/main-snake.css index 9cdff81d..e5f7b5a0 100755 --- a/css/main-snake.css +++ b/css/main-snake.css @@ -86,7 +86,7 @@ a.snake-link:hover { .door-block { margin: 0px; padding: 0px; - background-color: #FF0000; + background-color: #00ff1f; border: 0px solid #000080; position: absolute; background-image: url('./images/door.png'); diff --git a/index.html b/index.html index 6ea0fa1e..6a7b55bb 100755 --- a/index.html +++ b/index.html @@ -85,7 +85,7 @@
-
+
- JavaScript Snake + HIPAA Snake