From ba93182325dc990cb0350db4f1e1113120b1df5a Mon Sep 17 00:00:00 2001 From: weiks Date: Wed, 21 Feb 2018 16:48:35 -0500 Subject: [PATCH] Added Quarters --- CNAME | 1 + index.html | 18 ++++++++++++++++++ js/snake.js | 36 ++++++++++++++++++++++++++++-------- 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 CNAME diff --git a/CNAME b/CNAME new file mode 100644 index 00000000..62b6fac3 --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +js-snake.surge.sh diff --git a/index.html b/index.html index 04762927..7c13e04c 100755 --- a/index.html +++ b/index.html @@ -55,5 +55,23 @@ fullScreen: true }); + + + + diff --git a/js/snake.js b/js/snake.js index 3c9dabe0..8984498e 100644 --- a/js/snake.js +++ b/js/snake.js @@ -665,13 +665,25 @@ SNAKE.Board = SNAKE.Board || (function() { welcomeTxt.innerHTML = "JavaScript Snake

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

"; var welcomeStart = document.createElement("button"); welcomeStart.appendChild(document.createTextNode("Play Game")); + + var finishingLoadGame = function() { + me.setBoardState(1); + me.getBoardContainer().focus(); + } + var loadGame = function() { SNAKE.removeEventListener(window, "keyup", kbShortcut, false); tmpElm.style.display = "none"; - me.setBoardState(1); - me.getBoardContainer().focus(); + console.log("load game"); + document.querySelectorAll('.buy-quarters-button')[0].click(); + console.log("buy quarters") + window.onQuartersCallback = function(data) { + if (data.txId) { + return finishingLoadGame(); + } + } }; - + var kbShortcut = function(evt) { if (!evt) var evt = window.event; var keyNum = (evt.which) ? evt.which : evt.keyCode; @@ -679,6 +691,7 @@ SNAKE.Board = SNAKE.Board || (function() { loadGame(); } }; + SNAKE.addEventListener(window, "keyup", kbShortcut, false); SNAKE.addEventListener(welcomeStart, "click", loadGame, false); @@ -696,14 +709,21 @@ SNAKE.Board = SNAKE.Board || (function() { tryAgainTxt.innerHTML = "JavaScript Snake

You died :(.

"; var tryAgainStart = document.createElement("button"); tryAgainStart.appendChild( document.createTextNode("Play Again?")); - + + var finishingLoadGame = function() { + me.setBoardState(1); + me.getBoardContainer().focus(); + } var reloadGame = function() { tmpElm.style.display = "none"; me.resetBoard(); - me.setBoardState(1); - me.getBoardContainer().focus(); - }; - + document.querySelectorAll('.buy-quarters-button')[0].click(); + window.onQuartersCallback = function(data) { + if (data.txId) { + return finishingLoadGame(); + } + } + }; var kbTryAgainShortcut = function(evt) { if (boardState !== 0 || tmpElm.style.display !== "block") {return;} if (!evt) var evt = window.event;