From f4229707adcf6837bdf21364ba127297e48dfc39 Mon Sep 17 00:00:00 2001 From: Bo Date: Wed, 18 Nov 2015 16:51:16 -0800 Subject: [PATCH 01/34] added new key bindings that print to console --- js/input.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/js/input.js b/js/input.js index c559fb003..5d7d0cf72 100644 --- a/js/input.js +++ b/js/input.js @@ -51,6 +51,27 @@ function addKeyListeners() { } }); + keypress.register_combo({ + keys: "up", + on_keydown: function() { + console.log("Up button pressed"); + } + }); + + keypress.register_combo({ + keys: "down", + on_keydown: function() { + console.log("Down button pressed"); + } + }); + + keypress.register_combo({ + keys: "c", + on_keydown: function() { + console.log("C button pressed"); + } + }); + keypress.register_combo({ keys: "enter", on_keydown: function() { From 341d8d87d7f1ea5ce9e500e025c0d7914560c10f Mon Sep 17 00:00:00 2001 From: Bo Date: Thu, 19 Nov 2015 10:50:34 -0800 Subject: [PATCH 02/34] moved colour blind colours to a TOGGLE function, will impelment a true toggle later. --- js/input.js | 32 +++++++++++++++++++++++++++++++- js/qunit.htm | 20 ++++++++++++++++++++ js/tests.js | 0 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 js/qunit.htm create mode 100644 js/tests.js diff --git a/js/input.js b/js/input.js index 5d7d0cf72..91185f124 100644 --- a/js/input.js +++ b/js/input.js @@ -69,6 +69,8 @@ function addKeyListeners() { keys: "c", on_keydown: function() { console.log("C button pressed"); + togglecolor(); + } }); @@ -100,11 +102,39 @@ function addKeyListeners() { return false; }); + function togglecolor(){ + console.log("Hit toggle colour method"); + //window.colors = ["#8e44ad", "#f1c40f", "#3498db", "#d35400"]; + window.colors = ["#ffffff", "#f1c40f", "#3498db", "#d35400"]; + window.hexColorsToTintedColors = { + //"#8e44ad": "rgb(229,152,102)", + "#ffffff": "rgb(000,000,000)", + "#f1c40f": "rgb(246,223,133)", + "#3498db": "rgb(151,201,235)", + "#d35400": "rgb(210,180,222)" + }; + + window.rgbToHex = { + "rgb(142,68,173)": "#8e44ad", + "rgb(241,196,15)": "#f1c40f", + "rgb(52,152,219)": "#3498db", + "rgb(211,84,0)": "#d35400" + }; + + window.rgbColorsToTintedColors = { + "rgb(142,68,173)": "rgb(229,152,102)", + "rgb(241,196,15)": "rgb(246,223,133)", + "rgb(52,152,219)": "rgb(151,201,235)", + "rgb(46,204,113)": "rgb(210,180,222)" + }; + } + $("#colorBlindBtn").on('touchstart mousedown', function() { window.colors = ["#8e44ad", "#f1c40f", "#3498db", "#d35400"]; window.hexColorsToTintedColors = { - "#8e44ad": "rgb(229,152,102)", + //"#8e44ad": "rgb(229,152,102)", + "#ffffff": "rgb(000,000,000)", "#f1c40f": "rgb(246,223,133)", "#3498db": "rgb(151,201,235)", "#d35400": "rgb(210,180,222)" diff --git a/js/qunit.htm b/js/qunit.htm new file mode 100644 index 000000000..5f1024b0a --- /dev/null +++ b/js/qunit.htm @@ -0,0 +1,20 @@ + + + + + QUnit Example + + + + + + +
+
+ + \ No newline at end of file diff --git a/js/tests.js b/js/tests.js new file mode 100644 index 000000000..e69de29bb From 66e0237c8aec1d951303348a073ec3472e1cc41c Mon Sep 17 00:00:00 2001 From: Bo Date: Thu, 19 Nov 2015 19:53:25 -0800 Subject: [PATCH 03/34] some work done --- js/initialization.js | 6 +++++ js/input.js | 55 ++++++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/js/initialization.js b/js/initialization.js index 64d0e6680..b7bb5085f 100644 --- a/js/initialization.js +++ b/js/initialization.js @@ -2,6 +2,12 @@ $(document).ready(function() { initialize(); }); function initialize(a) { + // color blind mode variables + // max amount of color blind modes + window.maxColorBlindMode = 2; + window.currColorBlindMode = 0; + + window.rush = 1; window.lastTime = Date.now(); window.iframHasLoaded = false; diff --git a/js/input.js b/js/input.js index 91185f124..3598c810e 100644 --- a/js/input.js +++ b/js/input.js @@ -102,32 +102,6 @@ function addKeyListeners() { return false; }); - function togglecolor(){ - console.log("Hit toggle colour method"); - //window.colors = ["#8e44ad", "#f1c40f", "#3498db", "#d35400"]; - window.colors = ["#ffffff", "#f1c40f", "#3498db", "#d35400"]; - window.hexColorsToTintedColors = { - //"#8e44ad": "rgb(229,152,102)", - "#ffffff": "rgb(000,000,000)", - "#f1c40f": "rgb(246,223,133)", - "#3498db": "rgb(151,201,235)", - "#d35400": "rgb(210,180,222)" - }; - - window.rgbToHex = { - "rgb(142,68,173)": "#8e44ad", - "rgb(241,196,15)": "#f1c40f", - "rgb(52,152,219)": "#3498db", - "rgb(211,84,0)": "#d35400" - }; - - window.rgbColorsToTintedColors = { - "rgb(142,68,173)": "rgb(229,152,102)", - "rgb(241,196,15)": "rgb(246,223,133)", - "rgb(52,152,219)": "rgb(151,201,235)", - "rgb(46,204,113)": "rgb(210,180,222)" - }; - } $("#colorBlindBtn").on('touchstart mousedown', function() { window.colors = ["#8e44ad", "#f1c40f", "#3498db", "#d35400"]; @@ -135,7 +109,8 @@ function addKeyListeners() { window.hexColorsToTintedColors = { //"#8e44ad": "rgb(229,152,102)", "#ffffff": "rgb(000,000,000)", - "#f1c40f": "rgb(246,223,133)", + "#000000": "rgp(000,000,000)", + //"#f1c40f": "rgb(246,223,133)", "#3498db": "rgb(151,201,235)", "#d35400": "rgb(210,180,222)" }; @@ -240,3 +215,29 @@ function handleClickTap(x,y) { } } +function togglecolor(a){ + console.log("Hit toggle colour method"); + //window.colors = ["#8e44ad", "#f1c40f", "#3498db", "#d35400"]; + window.colors = ["#ffffff", "#f1c40f", "#3498db", "#d35400"]; + window.hexColorsToTintedColors = { + //"#8e44ad": "rgb(229,152,102)", + "#ffffff": "rgb(000,000,000)", + "#f1c40f": "rgb(246,223,133)", + "#3498db": "rgb(151,201,235)", + "#d35400": "rgb(210,180,222)" + }; + + window.rgbToHex = { + "rgb(142,68,173)": "#8e44ad", + "rgb(241,196,15)": "#f1c40f", + "rgb(52,152,219)": "#3498db", + "rgb(211,84,0)": "#d35400" + }; + + window.rgbColorsToTintedColors = { + "rgb(142,68,173)": "rgb(229,152,102)", + "rgb(241,196,15)": "rgb(246,223,133)", + "rgb(52,152,219)": "rgb(151,201,235)", + "rgb(46,204,113)": "rgb(210,180,222)" + }; +} From 802284f786cd4e8b60d005473bed885207f90a98 Mon Sep 17 00:00:00 2001 From: Bo Date: Thu, 19 Nov 2015 22:53:42 -0800 Subject: [PATCH 04/34] proof of concept for colour changing. --- js/Hex.js | 21 +++++++++++++++++---- js/initialization.js | 10 +++++++--- js/input.js | 26 +++++++++++++++++++++++--- js/qunit.htm | 1 + 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/js/Hex.js b/js/Hex.js index 64f917b0c..6fb777398 100644 --- a/js/Hex.js +++ b/js/Hex.js @@ -20,7 +20,7 @@ function Hex(sideLength) { this.lastColorScored = "#000"; this.comboTime = 1; this.texts = []; - this.lastRotate = Date.now(); + this.lastRotate = Date.now(); for (var i = 0; i < this.sides; i++) { this.blocks.push([]); } @@ -52,6 +52,18 @@ function Hex(sideLength) { lane = (lane + this.sides) % this.sides; block.distFromHex = MainHex.sideLength / 2 * Math.sqrt(3) + block.height * this.blocks[lane].length; this.blocks[lane].push(block); + + // TODO: TESTING FUNCTION REMOVE AFTER + //for(var i = 0; i < this.blocks.length; i++) { + // for (var j = 0; j < this.blocks[i].length; j++) { + // console.log(i, " ", j, ": "); + // console.log(this.blocks[i][j].color) + // if (this.blocks[i][j].color == "#000000") + // this.blocks[i][j].color="#00ffff"; + // else + // console.log("nomatch"); + // } + //} block.attachedLane = lane; block.checked = 1; }; @@ -105,7 +117,7 @@ function Hex(sideLength) { }; this.rotate = function(steps) { - if(Date.now()-this.lastRotate<75 && !(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) ) return; + if(Date.now()-this.lastRotate<75 && !(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) ) return; if (!(gameState === 1 || gameState === 0)) return; this.position += steps; if (!history[this.ct]) { @@ -131,7 +143,7 @@ function Hex(sideLength) { }); this.targetAngle = this.targetAngle - steps * 60; - this.lastRotate = Date.now(); + this.lastRotate = Date.now(); }; this.draw = function() { @@ -160,7 +172,7 @@ function Hex(sideLength) { else { this.angle += this.angularVelocity; } - + drawPolygon(this.x + gdx, this.y + gdy + this.dy, this.sides, this.sideLength, this.angle,arrayToColor(this.fillColor) , 0, 'rgba(0,0,0,0)'); }; } @@ -168,3 +180,4 @@ function Hex(sideLength) { function arrayToColor(arr){ return 'rgb(' + arr[0]+ ','+arr[1]+','+arr[2]+')'; } + diff --git a/js/initialization.js b/js/initialization.js index b7bb5085f..d02283974 100644 --- a/js/initialization.js +++ b/js/initialization.js @@ -4,14 +4,18 @@ $(document).ready(function() { function initialize(a) { // color blind mode variables // max amount of color blind modes - window.maxColorBlindMode = 2; - window.currColorBlindMode = 0; - + window.currcb = 0; + window.prevcb = 0; + window.cbcolors = [ + ["#e74c3c", "#f1c40f", "#3498db", "#2ecc71"], + ["#8e44ad", "#f1c40f", "#3498db", "#d35400"] + ] window.rush = 1; window.lastTime = Date.now(); window.iframHasLoaded = false; window.colors = ["#e74c3c", "#f1c40f", "#3498db", "#2ecc71"]; + window.hexColorsToTintedColors = { "#e74c3c": "rgb(241,163,155)", "#f1c40f": "rgb(246,223,133)", diff --git a/js/input.js b/js/input.js index 3598c810e..5f26d9d7f 100644 --- a/js/input.js +++ b/js/input.js @@ -74,6 +74,27 @@ function addKeyListeners() { } }); + keypress.register_combo({ + keys: "t", + on_keydown: function() { + console.log("T button pressed"); + + window.prevcb = window.currcb; + + thishex = MainHex; + for(var i = 0; i < thishex.blocks.length; i++) { + for (var j = 0; j < thishex.blocks[i].length; j++) { + console.log(i, " ", j, ": "); + console.log(thishex.blocks[i][j].color) + if (thishex.blocks[i][j].color == "#000000") + thishex.blocks[i][j].color="#ffffff"; + else + console.log("nomatch"); + } + } + } + }); + keypress.register_combo({ keys: "enter", on_keydown: function() { @@ -218,10 +239,9 @@ function handleClickTap(x,y) { function togglecolor(a){ console.log("Hit toggle colour method"); //window.colors = ["#8e44ad", "#f1c40f", "#3498db", "#d35400"]; - window.colors = ["#ffffff", "#f1c40f", "#3498db", "#d35400"]; + window.colors = ["#ffffff", "#000000", "#3498db", "#d35400"]; window.hexColorsToTintedColors = { - //"#8e44ad": "rgb(229,152,102)", - "#ffffff": "rgb(000,000,000)", + "#8e44ad": "rgb(229,152,102)", "#f1c40f": "rgb(246,223,133)", "#3498db": "rgb(151,201,235)", "#d35400": "rgb(210,180,222)" diff --git a/js/qunit.htm b/js/qunit.htm index 5f1024b0a..a35e30f5f 100644 --- a/js/qunit.htm +++ b/js/qunit.htm @@ -10,6 +10,7 @@ QUnit.test( "hello test", function( assert ) { assert.ok( 1 == "1", "Passed!" ); assert.ok( 1 == testFunc(), "Passed2"); + assert.ok("abc" == "abc", "passed3"); }); From 54eec34d840eba0defe7866fe640330067b06ea2 Mon Sep 17 00:00:00 2001 From: Bo Date: Fri, 20 Nov 2015 20:26:07 -0800 Subject: [PATCH 05/34] work done at school today --- js/initialization.js | 4 ++++ js/input.js | 51 +++++++++++++++++++++++++++++++++++--------- js/main.js | 4 ++++ js/wavegen.js | 9 ++++++-- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/js/initialization.js b/js/initialization.js index d02283974..89d2a1ea0 100644 --- a/js/initialization.js +++ b/js/initialization.js @@ -11,6 +11,10 @@ function initialize(a) { ["#8e44ad", "#f1c40f", "#3498db", "#d35400"] ] + + window.speedscale = 1; + window.oldspeedscale = 1; + window.rush = 1; window.lastTime = Date.now(); window.iframHasLoaded = false; diff --git a/js/input.js b/js/input.js index 5f26d9d7f..38e39e370 100644 --- a/js/input.js +++ b/js/input.js @@ -55,6 +55,16 @@ function addKeyListeners() { keys: "up", on_keydown: function() { console.log("Up button pressed"); + if (window.speedscale < 2){ + window.speedscale += 0.1; + console.log(window.speedscale); + } + + for (var k = 0; k < window.blocks.length; k++){ + window.blocks[k].iter = (speedscale*window.blocks[k].iter)/oldspeedscale; + } + window.oldspeedscale = window.speedscale; + } }); @@ -62,6 +72,18 @@ function addKeyListeners() { keys: "down", on_keydown: function() { console.log("Down button pressed"); + if (window.speedscale >= 0.2){ + window.speedscale -= 0.1; + console.log(window.speedscale); + } + + for (var k = 0; k < window.blocks.length; k++){ + console.log(k, " "); + //console.log(window.blocks[k].iter); + window.blocks[k].iter = (window.speedscale*window.blocks[k].iter)/oldspeedscale; + //console.log(window.blocks[k].iter); + } + window.oldspeedscale = window.speedscale; } }); @@ -81,17 +103,26 @@ function addKeyListeners() { window.prevcb = window.currcb; - thishex = MainHex; - for(var i = 0; i < thishex.blocks.length; i++) { - for (var j = 0; j < thishex.blocks[i].length; j++) { - console.log(i, " ", j, ": "); - console.log(thishex.blocks[i][j].color) - if (thishex.blocks[i][j].color == "#000000") - thishex.blocks[i][j].color="#ffffff"; - else - console.log("nomatch"); - } + for (var k = 0; k < window.blocks.length; k++){ + console.log(k, " "); + console.log(blocks[k].color); + if (blocks[k].color == "#000000") + blocks[k].color="#ffffff"; + else + console.log("nomatch"); } + // + //thishex = MainHex; + //for(var i = 0; i < thishex.blocks.length; i++) { + // for (var j = 0; j < thishex.blocks[i].length; j++) { + // console.log(i, " ", j, ": "); + // console.log(thishex.blocks[i][j].color) + // if (thishex.blocks[i][j].color == "#000000") + // thishex.blocks[i][j].color="#ffffff"; + // else + // console.log("nomatch"); + // } + //} } }); diff --git a/js/main.js b/js/main.js index afc8515d6..9a9d8b253 100644 --- a/js/main.js +++ b/js/main.js @@ -184,6 +184,10 @@ function init(b) { function addNewBlock(blocklane, color, iter, distFromHex, settled) { //last two are optional parameters iter *= settings.speedModifier; + + //TODO: added code + iter *= window.speedscale; + if (!history[MainHex.ct]) { history[MainHex.ct] = {}; } diff --git a/js/wavegen.js b/js/wavegen.js index a4e85ff77..a657806fe 100644 --- a/js/wavegen.js +++ b/js/wavegen.js @@ -28,15 +28,20 @@ function waveGen(hex) { this.currentFunction(); this.dt = (settings.platform == 'mobile' ? 14 : 16.6667) * MainHex.ct; this.computeDifficulty(); + // TODO: added this + //if ((this.dt - this.lastGen) * settings.creationSpeedModifier > this.nextGen) { if ((this.dt - this.lastGen) * settings.creationSpeedModifier > this.nextGen) { - if (this.nextGen > 600) { - this.nextGen -= 11 * ((this.nextGen / 1300)) * settings.creationSpeedModifier; + if (this.nextGen > 600) { + //this.nextGen -= 11 * ((this.nextGen / 1300)) * settings.creationSpeedModifier; + this.nextGen -= 11 * ((this.nextGen / 1300)) * settings.creationSpeedModifier * (1/window.speedscale); + console.log(this.nextGen); } } }; this.randomGeneration = function() { if (this.dt - this.lastGen > this.nextGen) { + Console.log("randomgen"); this.ct++; this.lastGen = this.dt; var fv = randInt(0, MainHex.sides); From 05fc7bd0aa0f164426b3cc37528a1cefdbda4db1 Mon Sep 17 00:00:00 2001 From: Bo Date: Fri, 20 Nov 2015 23:13:18 -0800 Subject: [PATCH 06/34] updated read added draft of scenarios modified adjust speed function for wave generation, more work needs to be done --- README.md | 11 +++++++++ docs/scenarios.txt | 57 ++++++++++++++++++++++++++++++++++++++++++++++ js/input.js | 12 +++++++--- js/wavegen.js | 14 ++++++------ 4 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 docs/scenarios.txt diff --git a/README.md b/README.md index c9da637bc..29d586564 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ +CPEN 321 L1A Group Members: + +Team 06 + +1. Bo Hu +2. Xin Wei (Patrick) Tee +3. William (Will) Tang + + +Original Project Infomration: + Hextris ========== diff --git a/docs/scenarios.txt b/docs/scenarios.txt new file mode 100644 index 000000000..621d9c3d2 --- /dev/null +++ b/docs/scenarios.txt @@ -0,0 +1,57 @@ +Github issue: +Please allow for a more gradual increase of speed +#129 opened on Mar 3 by EricViala + +1. User Story: +As a player +I want to have the ability to speed up or slow down the game +So that I am able to adjust the game for my skill level + +Acceptance Criteria: + +Scenario 1.1: Game is currently at 30% of its original speed or higher +Given that the game has started + And the player is currently playing the game + And the game is at 30% of its original playing speed or higher +When the player presses the "Down" arrow key +Then the speed of the dropping blocks will be slowed down by 10% + And the rate of generation of blocks will be slowed down by 10% + And the game continues. + +Scenario 1.2: Game is currently at 20% of its original speed (game is too slow) +Given that the game has started + And the player is currently playing the game + And the game is at 20% of its original playing speed +When the player presses the "Down" arrow key +Then the speed of the dropping blocks will remain the same + And the rate of generation of blocks blocks will remain the same + And the game continues. + +Scenario 1.3: Game is currently at 190% of its original speed or lower +Given that the game has started + And the player is currently playing the game + And the game is at 190% of its original playing speed or lower +When the player presses the "UP" arrow key +Then the speed of the dropping blocks will be sped up by 10% + And the rate of generation of blocks will be sped up by 10% + And the game continues. + +Scenario 1.4: Game is currently at 200% of its original speed +Given that the game has started + And the player is currently playing the game + And the game is at 200% of its original playing speed +When the player presses the "UP" arrow key +Then the speed of the dropping blocks will remain the same + And the rate of generation of blocks will remain the same + And the game continues. + + +===================================================== +Github issue: +Alternate color combination to Red/Green, Color blind people may face issue. enhancement +#74 opened on Aug 17, 2014 by tripples + +As a colourblind player +I want to have the ability change the appearence of the colours of the block +So that I am able to distinguish the blocks from each other + diff --git a/js/input.js b/js/input.js index 38e39e370..76646fde6 100644 --- a/js/input.js +++ b/js/input.js @@ -55,11 +55,12 @@ function addKeyListeners() { keys: "up", on_keydown: function() { console.log("Up button pressed"); - if (window.speedscale < 2){ + if (window.speedscale < 1.8){ window.speedscale += 0.1; console.log(window.speedscale); } + waveone.nextGen = waveone.nextGen*(2-window.speedscale)/(2-window.oldspeedscale); for (var k = 0; k < window.blocks.length; k++){ window.blocks[k].iter = (speedscale*window.blocks[k].iter)/oldspeedscale; } @@ -77,10 +78,15 @@ function addKeyListeners() { console.log(window.speedscale); } + waveone.nextGen = waveone.nextGen*(2-window.speedscale)/(2-window.oldspeedscale); + //settings.creationSpeedModifier = settings.creationSpeedModifier*window.speedscale/window.oldspeedscale; + //settings.speedModifier = settings.speedModifier*window.speedscale/window.oldspeedscale; + //console.log(settings.speedModifier); + //console.log(settings.creationSpeedModifier); + for (var k = 0; k < window.blocks.length; k++){ - console.log(k, " "); //console.log(window.blocks[k].iter); - window.blocks[k].iter = (window.speedscale*window.blocks[k].iter)/oldspeedscale; + window.blocks[k].iter = (window.speedscale*window.blocks[k].iter)/window.oldspeedscale; //console.log(window.blocks[k].iter); } window.oldspeedscale = window.speedscale; diff --git a/js/wavegen.js b/js/wavegen.js index a657806fe..78ce5aef5 100644 --- a/js/wavegen.js +++ b/js/wavegen.js @@ -7,6 +7,9 @@ function blockDestroyed() { waveone.nextGen = 600; } + // TODO: implement algorithm to slow down speed + waveone.nextGen = waveone.nextGen*(2-window.speedscale); + if (waveone.difficulty < 35) { waveone.difficulty += 0.085 * settings.speedModifier; } else { @@ -28,20 +31,17 @@ function waveGen(hex) { this.currentFunction(); this.dt = (settings.platform == 'mobile' ? 14 : 16.6667) * MainHex.ct; this.computeDifficulty(); - // TODO: added this - //if ((this.dt - this.lastGen) * settings.creationSpeedModifier > this.nextGen) { if ((this.dt - this.lastGen) * settings.creationSpeedModifier > this.nextGen) { - if (this.nextGen > 600) { - //this.nextGen -= 11 * ((this.nextGen / 1300)) * settings.creationSpeedModifier; - this.nextGen -= 11 * ((this.nextGen / 1300)) * settings.creationSpeedModifier * (1/window.speedscale); - console.log(this.nextGen); + if (this.nextGen > 600) { + this.nextGen -= 11 * ((this.nextGen / 1300)) * settings.creationSpeedModifier; } + this.nextGen = this.nextGen*(2-window.speedscale); + console.log(this.nextGen); } }; this.randomGeneration = function() { if (this.dt - this.lastGen > this.nextGen) { - Console.log("randomgen"); this.ct++; this.lastGen = this.dt; var fv = randInt(0, MainHex.sides); From 22b7950f498f1487a483135236f49c6f255904f6 Mon Sep 17 00:00:00 2001 From: Bo Date: Sat, 21 Nov 2015 17:03:49 -0800 Subject: [PATCH 07/34] clean up readme file, refer to original push for info --- README.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/README.md b/README.md index 29d586564..76d40fae0 100644 --- a/README.md +++ b/README.md @@ -18,19 +18,6 @@ Contributors: - Noah Moroze (@nmoroze) - Michael Yang (@themichaelyang) -#Conribtions -Please submit pull requests to clay-improvements - -# Releases -#### iOS: https://itunes.apple.com/us/app/hextris/id903769553?mt=8 -![](http://i.imgur.com/KBYZcf5.png) - -#### Android: https://play.google.com/store/apps/details?id=com.hextris.hextris -![](http://i.imgur.com/mxj8yKs.png) - -#### Firefox OS: https://marketplace.firefox.com/app/hextris-app -![](http://i.imgur.com/RhECXPg.png) - ## Press kit http://hextris.github.io/presskit/info.html From 2cfaf1964e9db2c7f542785a050eff3c8a355beb Mon Sep 17 00:00:00 2001 From: Bo Date: Sun, 22 Nov 2015 00:03:46 -0800 Subject: [PATCH 08/34] implemented colour change, todo: fix test for colour change feature --- js/Hex.js | 12 ---- js/Hex_test.js | 140 ++++++++++++++++++++++++++++++++++++++ js/initialization.js | 9 ++- js/initialization_test.js | 102 +++++++++++++++++++++++++++ js/input.js | 140 ++++++++++++++++---------------------- js/qunit.htm | 21 ------ js/tests.js | 0 qunit.htm | 31 +++++++++ 8 files changed, 337 insertions(+), 118 deletions(-) create mode 100644 js/Hex_test.js create mode 100644 js/initialization_test.js delete mode 100644 js/qunit.htm delete mode 100644 js/tests.js create mode 100644 qunit.htm diff --git a/js/Hex.js b/js/Hex.js index 6fb777398..ef54ff426 100644 --- a/js/Hex.js +++ b/js/Hex.js @@ -52,18 +52,6 @@ function Hex(sideLength) { lane = (lane + this.sides) % this.sides; block.distFromHex = MainHex.sideLength / 2 * Math.sqrt(3) + block.height * this.blocks[lane].length; this.blocks[lane].push(block); - - // TODO: TESTING FUNCTION REMOVE AFTER - //for(var i = 0; i < this.blocks.length; i++) { - // for (var j = 0; j < this.blocks[i].length; j++) { - // console.log(i, " ", j, ": "); - // console.log(this.blocks[i][j].color) - // if (this.blocks[i][j].color == "#000000") - // this.blocks[i][j].color="#00ffff"; - // else - // console.log("nomatch"); - // } - //} block.attachedLane = lane; block.checked = 1; }; diff --git a/js/Hex_test.js b/js/Hex_test.js new file mode 100644 index 000000000..790e3cad4 --- /dev/null +++ b/js/Hex_test.js @@ -0,0 +1,140 @@ +function Hex(sideLength) { + this.playThrough = 0; + this.fillColor = [44,62,80]; + this.tempColor = [44,62,80]; + this.angularVelocity = 0; + this.position = 0; + this.dy = 0; + this.dt = 1; + this.sides = 6; + this.blocks = []; + this.angle = 180 / this.sides; + this.targetAngle = this.angle; + this.shakes = []; + this.sideLength = sideLength; + this.strokeColor = 'blue'; + this.ct = 0; + this.lastCombo = this.ct - settings.comboTime; + this.lastColorScored = "#000"; + this.comboTime = 1; + this.texts = []; + this.lastRotate = Date.now(); + for (var i = 0; i < this.sides; i++) { + this.blocks.push([]); + } + + this.shake = function(obj) { //lane as in particle lane + var angle = 30 + obj.lane * 60; + angle *= Math.PI / 180; + var dx = Math.cos(angle) * obj.magnitude; + var dy = Math.sin(angle) * obj.magnitude; + gdx -= dx; + gdy += dy; + obj.magnitude /= 2 * this.dt; + if (obj.magnitude < 1) { + for (var i = 0; i < this.shakes.length; i++) { + if (this.shakes[i] == obj) { + this.shakes.splice(i, 1); + } + } + } + }; + + this.addBlock = function(block) { + if (!(gameState == 1 || gameState === 0)) return; + block.settled = 1; + block.tint = 0.6; + var lane = this.sides - block.fallingLane;// -this.position; + this.shakes.push({lane:block.fallingLane, magnitude:4.5 * (window.devicePixelRatio ? window.devicePixelRatio : 1) * (settings.scale)}); + lane += this.position; + lane = (lane + this.sides) % this.sides; + block.distFromHex = MainHex.sideLength / 2 * Math.sqrt(3) + block.height * this.blocks[lane].length; + this.blocks[lane].push(block); + block.attachedLane = lane; + block.checked = 1; + }; + + this.doesBlockCollide = function(block, position, tArr) { + if (block.settled) { + return; + } + + if (position !== undefined) { + arr = tArr; + if (position <= 0) { + if (block.distFromHex - block.iter * this.dt * settings.scale - (this.sideLength / 2) * Math.sqrt(3) <= 0) { + block.distFromHex = (this.sideLength / 2) * Math.sqrt(3); + block.settled = 1; + block.checked = 1; + } else { + block.settled = 0; + block.iter = 1.5 + (waveone.difficulty/15) * 3; + } + } else { + if (arr[position - 1].settled && block.distFromHex - block.iter * this.dt * settings.scale - arr[position - 1].distFromHex - arr[position - 1].height <= 0) { + block.distFromHex = arr[position - 1].distFromHex + arr[position - 1].height; + block.settled = 1; + block.checked = 1; + } + else { + block.settled = 0; + block.iter = 1.5 + (waveone.difficulty/15) * 3; + } + } + } else { + var lane = this.sides - block.fallingLane;// -this.position; + lane += this.position; + + lane = (lane+this.sides) % this.sides; + var arr = this.blocks[lane]; + + if (arr.length > 0) { + if (block.distFromHex + block.iter * this.dt * settings.scale - arr[arr.length - 1].distFromHex - arr[arr.length - 1].height <= 0) { + block.distFromHex = arr[arr.length - 1].distFromHex + arr[arr.length - 1].height; + this.addBlock(block); + } + } else { + if (block.distFromHex + block.iter * this.dt * settings.scale - (this.sideLength / 2) * Math.sqrt(3) <= 0) { + block.distFromHex = (this.sideLength / 2) * Math.sqrt(3); + this.addBlock(block); + } + } + } + }; + + this.rotate = function(steps) { + if(Date.now()-this.lastRotate<75 && !(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) ) return; + if (!(gameState === 1 || gameState === 0)) return; + this.position += steps; + if (!history[this.ct]) { + history[this.ct] = {}; + } + + if (!history[this.ct].rotate) { + history[this.ct].rotate = steps; + } + else { + history[this.ct].rotate += steps; + } + + while (this.position < 0) { + this.position += 6; + } + + this.position = this.position % this.sides; + this.blocks.forEach(function(blocks) { + blocks.forEach(function(block) { + block.targetAngle = block.targetAngle - steps * 60; + }); + }); + + this.targetAngle = this.targetAngle - steps * 60; + this.lastRotate = Date.now(); + }; + +} + +function arrayToColor(arr){ + return 'rgb(' + arr[0]+ ','+arr[1]+','+arr[2]+')'; +} + diff --git a/js/initialization.js b/js/initialization.js index 89d2a1ea0..e54865bd8 100644 --- a/js/initialization.js +++ b/js/initialization.js @@ -6,19 +6,22 @@ function initialize(a) { // max amount of color blind modes window.currcb = 0; window.prevcb = 0; + window.cbcolors = [ ["#e74c3c", "#f1c40f", "#3498db", "#2ecc71"], - ["#8e44ad", "#f1c40f", "#3498db", "#d35400"] + ["#8e44ad", "#f1c41f", "#3499db", "#d35400"], + ["#000000", "#445555", "#c0c0c0", "#ffffff"] ] - + // variables to adjust speed of game window.speedscale = 1; window.oldspeedscale = 1; window.rush = 1; window.lastTime = Date.now(); window.iframHasLoaded = false; - window.colors = ["#e74c3c", "#f1c40f", "#3498db", "#2ecc71"]; + + window.colors = window.cbcolors[0]; window.hexColorsToTintedColors = { "#e74c3c": "rgb(241,163,155)", diff --git a/js/initialization_test.js b/js/initialization_test.js new file mode 100644 index 000000000..c9b785ee7 --- /dev/null +++ b/js/initialization_test.js @@ -0,0 +1,102 @@ +/* This code in this function is identical to that of initialization.js with the exception: + - UI methods are stripped as this is to test the colour change functionality on + the backbone of the game, ensuring that the blocks change colour correctly. + */ +function initialize(a) { + // color blind mode variables + // max amount of color blind modes + window.currcb = 0; + window.prevcb = 0; + + window.cbcolors = [ + ["#e74c3c", "#f1c40f", "#3498db", "#2ecc71"], + ["#8e44ad", "#f1c41f", "#3499db", "#d35400"], + ["#000000", "#445555", "#c0c0c0", "#ffffff"] + ] + + // variables to adjust speed of game + window.speedscale = 1; + window.oldspeedscale = 1; + + window.rush = 1; + window.lastTime = Date.now(); + window.iframHasLoaded = false; + + window.colors = window.cbcolors[0]; + + window.hexColorsToTintedColors = { + "#e74c3c": "rgb(241,163,155)", + "#f1c40f": "rgb(246,223,133)", + "#3498db": "rgb(151,201,235)", + "#2ecc71": "rgb(150,227,183)" + }; + + window.rgbToHex = { + "rgb(231,76,60)": "#e74c3c", + "rgb(241,196,15)": "#f1c40f", + "rgb(52,152,219)": "#3498db", + "rgb(46,204,113)": "#2ecc71" + }; + + window.rgbColorsToTintedColors = { + "rgb(231,76,60)": "rgb(241,163,155)", + "rgb(241,196,15)": "rgb(246,223,133)", + "rgb(52,152,219)": "rgb(151,201,235)", + "rgb(46,204,113)": "rgb(150,227,183)" + }; + + window.hexagonBackgroundColor = 'rgb(236, 240, 241)'; + window.hexagonBackgroundColorClear = 'rgba(236, 240, 241, 0.5)'; + window.centerBlue = 'rgb(44,62,80)'; + window.angularVelocityConst = 4; + window.scoreOpacity = 0; + window.textOpacity = 0; + window.prevGameState = undefined; + window.op = 0; + window.saveState = localStorage.getItem("saveState") || "{}"; + if (saveState !== "{}") { + op = 1; + } + + + window.framerate = 60; + window.history = {}; + window.score = 0; + window.scoreAdditionCoeff = 1; + window.prevScore = 0; + window.numHighScores = 3; + + highscores = []; + + window.blocks = []; + window.MainHex; + window.gdx = 0; + window.gdy = 0; + window.devMode = 0; + window.lastGen = undefined; + window.prevTimeScored = undefined; + window.nextGen = undefined; + window.spawnLane = 0; + window.importing = 0; + window.importedHistory = undefined; + window.startTime = undefined; + window.gameState; + + settings = { + os: "other", + platform: "nonmobile", + baseScale: 1, + startDist: 340, + creationDt: 9, + scale: 1, + prevScale: 1, + hexWidth: 65, + baseHexWidth: 87, + baseBlockHeight: 20, + blockHeight: 15, + rows: 8, + speedModifier: 0.65, + creationSpeedModifier: 0.65, + comboTime: 310 + }; +} \ No newline at end of file diff --git a/js/input.js b/js/input.js index 76646fde6..976738be3 100644 --- a/js/input.js +++ b/js/input.js @@ -51,6 +51,22 @@ function addKeyListeners() { } }); + keypress.register_combo({ + keys: "s", + on_keydown: function() { + console.log("s pressed"); + window.saveblocks = copyObject(MainHex.blocks); + } + }); + + keypress.register_combo({ + keys: "u", + on_keydown: function() { + console.log("u pressed"); + MainHex.blocks = window.saveblocks; + } + }); + keypress.register_combo({ keys: "up", on_keydown: function() { @@ -79,10 +95,6 @@ function addKeyListeners() { } waveone.nextGen = waveone.nextGen*(2-window.speedscale)/(2-window.oldspeedscale); - //settings.creationSpeedModifier = settings.creationSpeedModifier*window.speedscale/window.oldspeedscale; - //settings.speedModifier = settings.speedModifier*window.speedscale/window.oldspeedscale; - //console.log(settings.speedModifier); - //console.log(settings.creationSpeedModifier); for (var k = 0; k < window.blocks.length; k++){ //console.log(window.blocks[k].iter); @@ -104,31 +116,8 @@ function addKeyListeners() { keypress.register_combo({ keys: "t", - on_keydown: function() { - console.log("T button pressed"); - - window.prevcb = window.currcb; - - for (var k = 0; k < window.blocks.length; k++){ - console.log(k, " "); - console.log(blocks[k].color); - if (blocks[k].color == "#000000") - blocks[k].color="#ffffff"; - else - console.log("nomatch"); - } - // - //thishex = MainHex; - //for(var i = 0; i < thishex.blocks.length; i++) { - // for (var j = 0; j < thishex.blocks[i].length; j++) { - // console.log(i, " ", j, ": "); - // console.log(thishex.blocks[i][j].color) - // if (thishex.blocks[i][j].color == "#000000") - // thishex.blocks[i][j].color="#ffffff"; - // else - // console.log("nomatch"); - // } - //} + on_keydown: function(){ + togglecolor(); } }); @@ -160,35 +149,6 @@ function addKeyListeners() { return false; }); - - $("#colorBlindBtn").on('touchstart mousedown', function() { - window.colors = ["#8e44ad", "#f1c40f", "#3498db", "#d35400"]; - - window.hexColorsToTintedColors = { - //"#8e44ad": "rgb(229,152,102)", - "#ffffff": "rgb(000,000,000)", - "#000000": "rgp(000,000,000)", - //"#f1c40f": "rgb(246,223,133)", - "#3498db": "rgb(151,201,235)", - "#d35400": "rgb(210,180,222)" - }; - - window.rgbToHex = { - "rgb(142,68,173)": "#8e44ad", - "rgb(241,196,15)": "#f1c40f", - "rgb(52,152,219)": "#3498db", - "rgb(211,84,0)": "#d35400" - }; - - window.rgbColorsToTintedColors = { - "rgb(142,68,173)": "rgb(229,152,102)", - "rgb(241,196,15)": "rgb(246,223,133)", - "rgb(52,152,219)": "rgb(151,201,235)", - "rgb(46,204,113)": "rgb(210,180,222)" - }; - }); - - if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { $("#restart").on('touchstart', function() { init(); @@ -273,28 +233,44 @@ function handleClickTap(x,y) { } } -function togglecolor(a){ +function togglecolor(){ console.log("Hit toggle colour method"); - //window.colors = ["#8e44ad", "#f1c40f", "#3498db", "#d35400"]; - window.colors = ["#ffffff", "#000000", "#3498db", "#d35400"]; - window.hexColorsToTintedColors = { - "#8e44ad": "rgb(229,152,102)", - "#f1c40f": "rgb(246,223,133)", - "#3498db": "rgb(151,201,235)", - "#d35400": "rgb(210,180,222)" - }; - - window.rgbToHex = { - "rgb(142,68,173)": "#8e44ad", - "rgb(241,196,15)": "#f1c40f", - "rgb(52,152,219)": "#3498db", - "rgb(211,84,0)": "#d35400" - }; - - window.rgbColorsToTintedColors = { - "rgb(142,68,173)": "rgb(229,152,102)", - "rgb(241,196,15)": "rgb(246,223,133)", - "rgb(52,152,219)": "rgb(151,201,235)", - "rgb(46,204,113)": "rgb(210,180,222)" - }; -} + + // compute the current and next color + window.prevcb = window.currcb; + window.currcb = (window.prevcb + 1) % window.maxcbcolors; + + // set the current window color to the one we need + window.colors = window.cbcolors[currcb]; + + // obtain all the current falling blocks + for (var i = 0; i < window.blocks.length; i++){ + + // find the colour of the block and change accordingly + for (var j = 0; j < window.cbcolors[window.prevcb].length; j++){ + if (window.blocks[i].color == window.cbcolors[window.prevcb][j]){ + window.blocks[i].color = window.cbcolors[window.currcb][j]; + } + else { + console.log("Error: Colour ", window.blocks[i].color, "doesn't exist"); + } + } + } + + // obtain all colours from the hex and change them + for(var k = 0; k < MainHex.blocks.length; k++) { + for (var l = 0; l < MainHex.blocks[k].length; l++) { + for (var m = 0; m < window.cbcolors[window.prevcb].length; m++){ + + // find the colour of the block and change accordingly + if (MainHex.blocks[k][l].color == window.cbcolors[window.prevcb][m]){ + MainHex.blocks[k][l].color = window.cbcolors[window.currcb][m]; + } + else { + console.log("Error: Colour ", window.blocks[i].color, "doesn't exist"); + } + } + } + } + +} \ No newline at end of file diff --git a/js/qunit.htm b/js/qunit.htm deleted file mode 100644 index a35e30f5f..000000000 --- a/js/qunit.htm +++ /dev/null @@ -1,21 +0,0 @@ - - - - - QUnit Example - - - - - - -
-
- - \ No newline at end of file diff --git a/js/tests.js b/js/tests.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/qunit.htm b/qunit.htm new file mode 100644 index 000000000..b921e05a8 --- /dev/null +++ b/qunit.htm @@ -0,0 +1,31 @@ + + + + + Hetrix Acceptance Tests + + + + + + + + + + + + + + + +
+
+ + \ No newline at end of file From 5467d68d8b4ed4017a48760b742904ad572969cf Mon Sep 17 00:00:00 2001 From: Bo Date: Sun, 22 Nov 2015 01:35:26 -0800 Subject: [PATCH 09/34] the beginning of creating test cases --- index.html | 2 +- js/Block_test.js | 214 ++++++++++++++++++++++++++++++++++++++ js/Hex_test.js | 29 ++++-- js/initialization_test.js | 2 +- js/input.js | 27 ++--- js/test.js | 3 + qunit.htm | 14 ++- 7 files changed, 264 insertions(+), 27 deletions(-) create mode 100644 js/Block_test.js create mode 100644 js/test.js diff --git a/index.html b/index.html index a8287cc56..0d1966ad7 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@ - + diff --git a/js/Block_test.js b/js/Block_test.js new file mode 100644 index 000000000..0efc23e78 --- /dev/null +++ b/js/Block_test.js @@ -0,0 +1,214 @@ +function Block(fallingLane, color, iter, distFromHex, settled) { + settings = { + os: "other", + platform: "nonmobile", + baseScale: 1, + startDist: 340, + creationDt: 9, + scale: 1, + prevScale: 1, + hexWidth: 65, + baseHexWidth: 87, + baseBlockHeight: 20, + blockHeight: 15, + rows: 8, + speedModifier: 0.65, + creationSpeedModifier: 0.65, + comboTime: 310 + }; + // whether or not a block is rested on the center hex or another block + this.settled = (settled === undefined) ? 0 : 1; + this.height = settings.blockHeight; + //the lane which the block was shot from + this.fallingLane = fallingLane; + + this.checked=0; + //the angle at which the block falls + this.angle = 90 - (30 + 60 * fallingLane); + //for calculating the rotation of blocks attached to the center hex + this.angularVelocity = 0; + this.targetAngle = this.angle; + this.color = color; + //blocks that are slated to be deleted after a valid score has happened + this.deleted = 0; + //blocks slated to be removed from falling and added to the hex + this.removed = 0; + //value for the opacity of the white blcok drawn over falling block to give it the glow as it attaches to the hex + this.tint = 0; + //value used for deletion animation + this.opacity = 1; + //boolean for when the block is expanding + this.initializing = 1; + //speed of block + this.iter = iter; + //number of iterations before starting to drop + this.initLen = settings.creationDt; + //side which block is attached too + this.attachedLane = 0; + //distance from center hex + this.distFromHex = distFromHex || settings.startDist * settings.scale ; + + this.incrementOpacity = function() { + if (this.deleted) { + //add shakes + if (this.opacity >= 0.925) { + var tLane = this.attachedLane - MainHex.position; + tLane = MainHex.sides - tLane; + while (tLane < 0) { + tLane += MainHex.sides; + } + + tLane %= MainHex.sides; + MainHex.shakes.push({lane:tLane, magnitude:3 * (window.devicePixelRatio ? window.devicePixelRatio : 1) * (settings.scale)}); + } + //fade out the opacity + this.opacity = this.opacity - 0.075 * MainHex.dt; + if (this.opacity <= 0) { + //slate for final deletion + this.opacity = 0; + this.deleted = 2; + if (gameState == 1 || gameState==0) { + localStorage.setItem("saveState", exportSaveState()); + } + } + } + }; + + this.getIndex = function (){ + //get the index of the block in its stack + var parentArr = MainHex.blocks[this.attachedLane]; + for (var i = 0; i < parentArr.length; i++) { + if (parentArr[i] == this) { + return i; + } + } + }; + + this.draw = function(attached, index) { + this.height = settings.blockHeight; + if (Math.abs(settings.scale - settings.prevScale) > 0.000000001) { + this.distFromHex *= (settings.scale/settings.prevScale); + } + + this.incrementOpacity(); + if(attached === undefined) + attached = false; + + if(this.angle > this.targetAngle) { + this.angularVelocity -= angularVelocityConst * MainHex.dt; + } + else if(this.angle < this.targetAngle) { + this.angularVelocity += angularVelocityConst * MainHex.dt; + } + + if (Math.abs(this.angle - this.targetAngle + this.angularVelocity) <= Math.abs(this.angularVelocity)) { //do better soon + this.angle = this.targetAngle; + this.angularVelocity = 0; + } + else { + this.angle += this.angularVelocity; + } + + this.width = 2 * this.distFromHex / Math.sqrt(3); + this.widthWide = 2 * (this.distFromHex + this.height) / Math.sqrt(3); + //this.widthWide = this.width + this.height + 3; + var p1; + var p2; + var p3; + var p4; + if (this.initializing) { + var rat = ((MainHex.ct - this.ict)/this.initLen); + if (rat > 1) { + rat = 1; + } + p1 = rotatePoint((-this.width / 2) * rat, this.height / 2, this.angle); + p2 = rotatePoint((this.width / 2) * rat, this.height / 2, this.angle); + p3 = rotatePoint((this.widthWide / 2) * rat, -this.height / 2, this.angle); + p4 = rotatePoint((-this.widthWide / 2) * rat, -this.height / 2, this.angle); + if ((MainHex.ct - this.ict) >= this.initLen) { + this.initializing = 0; + } + } else { + p1 = rotatePoint(-this.width / 2, this.height / 2, this.angle); + p2 = rotatePoint(this.width / 2, this.height / 2, this.angle); + p3 = rotatePoint(this.widthWide / 2, -this.height / 2, this.angle); + p4 = rotatePoint(-this.widthWide / 2, -this.height / 2, this.angle); + } + + if (this.deleted) { + ctx.fillStyle = "#FFF"; + } else if (gameState === 0) { + if (this.color.charAt(0) == 'r') { + ctx.fillStyle = rgbColorsToTintedColors[this.color]; + } + else { + ctx.fillStyle = hexColorsToTintedColors[this.color]; + } + } + else { + ctx.fillStyle = this.color; + } + + ctx.globalAlpha = this.opacity; + var baseX = trueCanvas.width / 2 + Math.sin((this.angle) * (Math.PI / 180)) * (this.distFromHex + this.height / 2) + gdx; + var baseY = trueCanvas.height / 2 - Math.cos((this.angle) * (Math.PI / 180)) * (this.distFromHex + this.height / 2) + gdy; + ctx.beginPath(); + ctx.moveTo(baseX + p1.x, baseY + p1.y); + ctx.lineTo(baseX + p2.x, baseY + p2.y); + ctx.lineTo(baseX + p3.x, baseY + p3.y); + ctx.lineTo(baseX + p4.x, baseY + p4.y); + //ctx.lineTo(baseX + p1.x, baseY + p1.y); + ctx.closePath(); + ctx.fill(); + + if (this.tint) { + if (this.opacity < 1) { + if (gameState == 1 || gameState==0) { + localStorage.setItem("saveState", exportSaveState()); + } + + this.iter = 2.25; + this.tint = 0; + } + + ctx.fillStyle = "#FFF"; + ctx.globalAlpha = this.tint; + ctx.beginPath(); + ctx.moveTo(baseX + p1.x, baseY + p1.y); + ctx.lineTo(baseX + p2.x, baseY + p2.y); + ctx.lineTo(baseX + p3.x, baseY + p3.y); + ctx.lineTo(baseX + p4.x, baseY + p4.y); + ctx.lineTo(baseX + p1.x, baseY + p1.y); + ctx.closePath(); + ctx.fill(); + this.tint -= 0.02 * MainHex.dt; + if (this.tint < 0) { + this.tint = 0; + } + } + + ctx.globalAlpha = 1; + }; +} + +function findCenterOfBlocks(arr) { + var avgDFH = 0; + var avgAngle = 0; + for (var i = 0; i < arr.length; i++) { + avgDFH += arr[i].distFromHex; + var ang = arr[i].angle; + while (ang < 0) { + ang += 360; + } + + avgAngle += ang % 360; + } + + avgDFH /= arr.length; + avgAngle /= arr.length; + + return { + x:trueCanvas.width/2 + Math.cos(avgAngle * (Math.PI / 180)) * avgDFH, + y:trueCanvas.height/2 + Math.sin(avgAngle * (Math.PI / 180)) * avgDFH + }; +} diff --git a/js/Hex_test.js b/js/Hex_test.js index 790e3cad4..fef2aadfd 100644 --- a/js/Hex_test.js +++ b/js/Hex_test.js @@ -1,4 +1,21 @@ function Hex(sideLength) { + window.settings = { + os: "other", + platform: "nonmobile", + baseScale: 1, + startDist: 340, + creationDt: 9, + scale: 1, + prevScale: 1, + hexWidth: 65, + baseHexWidth: 87, + baseBlockHeight: 20, + blockHeight: 15, + rows: 8, + speedModifier: 0.65, + creationSpeedModifier: 0.65, + comboTime: 310 + }; this.playThrough = 0; this.fillColor = [44,62,80]; this.tempColor = [44,62,80]; @@ -14,7 +31,7 @@ function Hex(sideLength) { this.sideLength = sideLength; this.strokeColor = 'blue'; this.ct = 0; - this.lastCombo = this.ct - settings.comboTime; + this.lastCombo = this.ct - window.settings.comboTime; this.lastColorScored = "#000"; this.comboTime = 1; this.texts = []; @@ -45,7 +62,7 @@ function Hex(sideLength) { block.settled = 1; block.tint = 0.6; var lane = this.sides - block.fallingLane;// -this.position; - this.shakes.push({lane:block.fallingLane, magnitude:4.5 * (window.devicePixelRatio ? window.devicePixelRatio : 1) * (settings.scale)}); + this.shakes.push({lane:block.fallingLane, magnitude:4.5 * (window.devicePixelRatio ? window.devicePixelRatio : 1) * (window.settings.scale)}); lane += this.position; lane = (lane + this.sides) % this.sides; block.distFromHex = MainHex.sideLength / 2 * Math.sqrt(3) + block.height * this.blocks[lane].length; @@ -62,7 +79,7 @@ function Hex(sideLength) { if (position !== undefined) { arr = tArr; if (position <= 0) { - if (block.distFromHex - block.iter * this.dt * settings.scale - (this.sideLength / 2) * Math.sqrt(3) <= 0) { + if (block.distFromHex - block.iter * this.dt * window.settings.scale - (this.sideLength / 2) * Math.sqrt(3) <= 0) { block.distFromHex = (this.sideLength / 2) * Math.sqrt(3); block.settled = 1; block.checked = 1; @@ -71,7 +88,7 @@ function Hex(sideLength) { block.iter = 1.5 + (waveone.difficulty/15) * 3; } } else { - if (arr[position - 1].settled && block.distFromHex - block.iter * this.dt * settings.scale - arr[position - 1].distFromHex - arr[position - 1].height <= 0) { + if (arr[position - 1].settled && block.distFromHex - block.iter * this.dt * window.settings.scale - arr[position - 1].distFromHex - arr[position - 1].height <= 0) { block.distFromHex = arr[position - 1].distFromHex + arr[position - 1].height; block.settled = 1; block.checked = 1; @@ -89,12 +106,12 @@ function Hex(sideLength) { var arr = this.blocks[lane]; if (arr.length > 0) { - if (block.distFromHex + block.iter * this.dt * settings.scale - arr[arr.length - 1].distFromHex - arr[arr.length - 1].height <= 0) { + if (block.distFromHex + block.iter * this.dt * window.settings.scale - arr[arr.length - 1].distFromHex - arr[arr.length - 1].height <= 0) { block.distFromHex = arr[arr.length - 1].distFromHex + arr[arr.length - 1].height; this.addBlock(block); } } else { - if (block.distFromHex + block.iter * this.dt * settings.scale - (this.sideLength / 2) * Math.sqrt(3) <= 0) { + if (block.distFromHex + block.iter * this.dt * window.settings.scale - (this.sideLength / 2) * Math.sqrt(3) <= 0) { block.distFromHex = (this.sideLength / 2) * Math.sqrt(3); this.addBlock(block); } diff --git a/js/initialization_test.js b/js/initialization_test.js index c9b785ee7..6eb2e0e91 100644 --- a/js/initialization_test.js +++ b/js/initialization_test.js @@ -82,7 +82,7 @@ function initialize(a) { window.startTime = undefined; window.gameState; - settings = { + window.settings = { os: "other", platform: "nonmobile", baseScale: 1, diff --git a/js/input.js b/js/input.js index 976738be3..ef1e3d0c2 100644 --- a/js/input.js +++ b/js/input.js @@ -117,7 +117,7 @@ function addKeyListeners() { keypress.register_combo({ keys: "t", on_keydown: function(){ - togglecolor(); + togglecolor(window.blocks, MainHex); } }); @@ -233,41 +233,34 @@ function handleClickTap(x,y) { } } -function togglecolor(){ +function togglecolor(blocks, hex){ console.log("Hit toggle colour method"); // compute the current and next color window.prevcb = window.currcb; - window.currcb = (window.prevcb + 1) % window.maxcbcolors; + window.currcb = (window.prevcb + 1) % window.cbcolors.length; // set the current window color to the one we need window.colors = window.cbcolors[currcb]; // obtain all the current falling blocks - for (var i = 0; i < window.blocks.length; i++){ + for (var i = 0; i < blocks.length; i++){ // find the colour of the block and change accordingly for (var j = 0; j < window.cbcolors[window.prevcb].length; j++){ - if (window.blocks[i].color == window.cbcolors[window.prevcb][j]){ - window.blocks[i].color = window.cbcolors[window.currcb][j]; - } - else { - console.log("Error: Colour ", window.blocks[i].color, "doesn't exist"); + if (blocks[i].color == window.cbcolors[window.prevcb][j]){ + blocks[i].color = window.cbcolors[window.currcb][j] } } } // obtain all colours from the hex and change them - for(var k = 0; k < MainHex.blocks.length; k++) { - for (var l = 0; l < MainHex.blocks[k].length; l++) { + for(var k = 0; k < hex.blocks.length; k++) { + for (var l = 0; l < hex.blocks[k].length; l++) { for (var m = 0; m < window.cbcolors[window.prevcb].length; m++){ - // find the colour of the block and change accordingly - if (MainHex.blocks[k][l].color == window.cbcolors[window.prevcb][m]){ - MainHex.blocks[k][l].color = window.cbcolors[window.currcb][m]; - } - else { - console.log("Error: Colour ", window.blocks[i].color, "doesn't exist"); + if (hex.blocks[k][l].color == window.cbcolors[window.prevcb][m]){ + hex.blocks[k][l].color = window.cbcolors[window.currcb][m]; } } } diff --git a/js/test.js b/js/test.js new file mode 100644 index 000000000..cad3efd37 --- /dev/null +++ b/js/test.js @@ -0,0 +1,3 @@ +function testFunc(){ + return 1; +} \ No newline at end of file diff --git a/qunit.htm b/qunit.htm index b921e05a8..e9779d951 100644 --- a/qunit.htm +++ b/qunit.htm @@ -8,7 +8,7 @@ - + @@ -17,10 +17,20 @@ From ed61a3d2978c3f443dbbe3469966fef20117db32 Mon Sep 17 00:00:00 2001 From: Bo Date: Sun, 22 Nov 2015 10:52:41 -0800 Subject: [PATCH 10/34] updated scenarios, added unit tests, extracted method to adjust speed and colours --- docs/scenarios.txt | 35 ++++++++++++----- js/input.js | 98 +++++++++++++++++++++------------------------- qunit.htm | 65 +++++++++++++++++++++++++----- 3 files changed, 126 insertions(+), 72 deletions(-) diff --git a/docs/scenarios.txt b/docs/scenarios.txt index 621d9c3d2..23f6062bf 100644 --- a/docs/scenarios.txt +++ b/docs/scenarios.txt @@ -1,6 +1,6 @@ Github issue: Please allow for a more gradual increase of speed -#129 opened on Mar 3 by EricViala +#129 opened on Mar 3, 2015 by EricViala 1. User Story: As a player @@ -9,37 +9,37 @@ So that I am able to adjust the game for my skill level Acceptance Criteria: -Scenario 1.1: Game is currently at 30% of its original speed or higher +Scenario 1.1: Game is currently at 40% of its original speed or higher Given that the game has started And the player is currently playing the game - And the game is at 30% of its original playing speed or higher + And the game is at 40% of its original playing speed or higher When the player presses the "Down" arrow key Then the speed of the dropping blocks will be slowed down by 10% And the rate of generation of blocks will be slowed down by 10% And the game continues. -Scenario 1.2: Game is currently at 20% of its original speed (game is too slow) +Scenario 1.2: Game is currently at 30% of its original speed (game is very slow) Given that the game has started And the player is currently playing the game - And the game is at 20% of its original playing speed + And the game is at 30% of its original playing speed When the player presses the "Down" arrow key Then the speed of the dropping blocks will remain the same And the rate of generation of blocks blocks will remain the same And the game continues. -Scenario 1.3: Game is currently at 190% of its original speed or lower +Scenario 1.3: Game is currently at 170% of its original speed or lower Given that the game has started And the player is currently playing the game - And the game is at 190% of its original playing speed or lower + And the game is at 170% of its original playing speed or lower When the player presses the "UP" arrow key Then the speed of the dropping blocks will be sped up by 10% And the rate of generation of blocks will be sped up by 10% And the game continues. -Scenario 1.4: Game is currently at 200% of its original speed +Scenario 1.4: Game is currently at 180% of its original speed (game is very fast) Given that the game has started And the player is currently playing the game - And the game is at 200% of its original playing speed + And the game is at 180% of its original playing speed When the player presses the "UP" arrow key Then the speed of the dropping blocks will remain the same And the rate of generation of blocks will remain the same @@ -51,7 +51,24 @@ Github issue: Alternate color combination to Red/Green, Color blind people may face issue. enhancement #74 opened on Aug 17, 2014 by tripples +2. User Story: As a colourblind player I want to have the ability change the appearence of the colours of the block So that I am able to distinguish the blocks from each other +Scenario 2.1: User Press Colourblind Toggle Button when in the default colour +Given that the game has started + And the player is currently playing the game +When the player presses the "T" key +Then the colour of the blocks will change to another colour that is friendly for the colourblind + And the game continues. + +Scenario 2.2: User Press Colourblind Toggle Button when in a colourblind mode +Given that the game has started + And the player is currently playing the game + And the blocks are currently in a colourblind colour +When the player presses the "T" key +Then the colour of the blocks will change to anothe set of colours that is friendly for the colourblind, + if the player has not cycled through all the colourblind colours yet, otherwise the colour of the blocks + will revert back to the default colour. + And the game continues. diff --git a/js/input.js b/js/input.js index ef1e3d0c2..c0acc4291 100644 --- a/js/input.js +++ b/js/input.js @@ -51,69 +51,23 @@ function addKeyListeners() { } }); - keypress.register_combo({ - keys: "s", - on_keydown: function() { - console.log("s pressed"); - window.saveblocks = copyObject(MainHex.blocks); - } - }); - - keypress.register_combo({ - keys: "u", - on_keydown: function() { - console.log("u pressed"); - MainHex.blocks = window.saveblocks; - } - }); - + // speed up key keypress.register_combo({ keys: "up", on_keydown: function() { - console.log("Up button pressed"); - if (window.speedscale < 1.8){ - window.speedscale += 0.1; - console.log(window.speedscale); - } - - waveone.nextGen = waveone.nextGen*(2-window.speedscale)/(2-window.oldspeedscale); - for (var k = 0; k < window.blocks.length; k++){ - window.blocks[k].iter = (speedscale*window.blocks[k].iter)/oldspeedscale; - } - window.oldspeedscale = window.speedscale; - + togglespeed(0.1, window.blocks, MainHex); } }); + // slow down key keypress.register_combo({ keys: "down", on_keydown: function() { - console.log("Down button pressed"); - if (window.speedscale >= 0.2){ - window.speedscale -= 0.1; - console.log(window.speedscale); - } - - waveone.nextGen = waveone.nextGen*(2-window.speedscale)/(2-window.oldspeedscale); - - for (var k = 0; k < window.blocks.length; k++){ - //console.log(window.blocks[k].iter); - window.blocks[k].iter = (window.speedscale*window.blocks[k].iter)/window.oldspeedscale; - //console.log(window.blocks[k].iter); - } - window.oldspeedscale = window.speedscale; - } - }); - - keypress.register_combo({ - keys: "c", - on_keydown: function() { - console.log("C button pressed"); - togglecolor(); - + togglespeed(-0.1, window.blocks, MainHex); } }); + // colour blind toggle key keypress.register_combo({ keys: "t", on_keydown: function(){ @@ -234,8 +188,6 @@ function handleClickTap(x,y) { } function togglecolor(blocks, hex){ - console.log("Hit toggle colour method"); - // compute the current and next color window.prevcb = window.currcb; window.currcb = (window.prevcb + 1) % window.cbcolors.length; @@ -265,5 +217,43 @@ function togglecolor(blocks, hex){ } } } +} + +function togglespeed(increment, blocks, hex){ -} \ No newline at end of file + // check if we are incrementing or decrementing the game speed + if (increment < 0){ + + // if incrementing, adjust the speed accordingly + if (window.speedscale >= 0.3){ + window.speedscale -= 0.1; + console.log(window.speedscale); + } + } + else { // increment is positive + // if decrementing, adjust the speed accordingly + if (window.speedscale < 1.7){ + window.speedscale += 0.1; + console.log(window.speedscale); + } + } + + // slow down the generation of the wave speeds + waveone.nextGen = waveone.nextGen*(2-window.speedscale)/(2-window.oldspeedscale); + var iterfactor = window.speedscale / window.oldspeedscale; + + // slow down speed of falling blocks + for (var k = 0; k < blocks.length; k++){ + blocks[k].iter = blocks[k].iter * iterfactor; + } + + // obtain all speeds from the hex and change thems + for(var k = 0; k < hex.blocks.length; k++) { + for (var l = 0; l < hex.blocks[k].length; l++) { + hex.blocks[k][l].iter = hex.blocks[k][l].iter*iterfactor; + } + } + + // store the old value of so speed can be adjusted in future + window.oldspeedscale = window.speedscale; +} diff --git a/qunit.htm b/qunit.htm index e9779d951..5d5bd59e1 100644 --- a/qunit.htm +++ b/qunit.htm @@ -16,21 +16,68 @@ From 98cd9b0177c5e1be1bd9f32aced78ffa59e9924d Mon Sep 17 00:00:00 2001 From: Bo Date: Sun, 22 Nov 2015 11:20:42 -0800 Subject: [PATCH 11/34] updated wave generation to better be suited to speed changes --- js/input.js | 2 +- js/wavegen.js | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/js/input.js b/js/input.js index c0acc4291..08f5f3e03 100644 --- a/js/input.js +++ b/js/input.js @@ -239,7 +239,7 @@ function togglespeed(increment, blocks, hex){ } // slow down the generation of the wave speeds - waveone.nextGen = waveone.nextGen*(2-window.speedscale)/(2-window.oldspeedscale); + waveone.nextGen = waveone.nextGen*(1/window.speedscale)/(1/window.oldspeedscale); var iterfactor = window.speedscale / window.oldspeedscale; // slow down speed of falling blocks diff --git a/js/wavegen.js b/js/wavegen.js index 78ce5aef5..c01b7b66e 100644 --- a/js/wavegen.js +++ b/js/wavegen.js @@ -1,14 +1,18 @@ function blockDestroyed() { - if (waveone.nextGen > 1350) { + + // PRJ: all * window.speedscale + if (waveone.nextGen*window.speedscale > 1350) { waveone.nextGen -= 30 * settings.creationSpeedModifier; - } else if (waveone.nextGen > 600) { + } else if (waveone.nextGen*window.speedscale > 600) { waveone.nextGen -= 8 * settings.creationSpeedModifier; } else { waveone.nextGen = 600; } - // TODO: implement algorithm to slow down speed - waveone.nextGen = waveone.nextGen*(2-window.speedscale); + // PRJ: this function scales down nextGen + if (window.speedscale > 0.001) { + waveone.nextGen = waveone.nextGen / window.speedscale; + } if (waveone.difficulty < 35) { waveone.difficulty += 0.085 * settings.speedModifier; @@ -32,10 +36,14 @@ function waveGen(hex) { this.dt = (settings.platform == 'mobile' ? 14 : 16.6667) * MainHex.ct; this.computeDifficulty(); if ((this.dt - this.lastGen) * settings.creationSpeedModifier > this.nextGen) { - if (this.nextGen > 600) { + + // PRJ: * window.speedscale + if (this.nextGen*window.speedscale > 600) { this.nextGen -= 11 * ((this.nextGen / 1300)) * settings.creationSpeedModifier; } - this.nextGen = this.nextGen*(2-window.speedscale); + + // PRJ + this.nextGen = this.nextGen/window.speedscale; console.log(this.nextGen); } }; From 05d301ab63527ebf9a56fbde2775e4acba3add68 Mon Sep 17 00:00:00 2001 From: Bo Date: Sun, 22 Nov 2015 11:40:29 -0800 Subject: [PATCH 12/34] added 1.1 test for changing speed, update more later. --- qunit.htm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/qunit.htm b/qunit.htm index 5d5bd59e1..c78d8de44 100644 --- a/qunit.htm +++ b/qunit.htm @@ -11,6 +11,7 @@ + @@ -79,6 +80,28 @@ } assert.ok(window.blocks.length == 0, "Falling blocks list empty."); }); + + + QUnit.test( "Speed up test, scenario 1.1", function( assert ) { + initialize(1); + // given + window.gameState = 1; // game is starting + var testblk1 = new Block(1, "#e74c3c", 8, -1, 1); + var testblk2 = new Block(2, "#f1c40f", 8, -1, 1); + var testblk3 = new Block(3, "#3498db", 8, -1, 0); + var testblk4 = new Block(4, "#2ecc71", 8, -1, 0); + MainHex = new Hex(6); + waveone = new waveGen(MainHex); + MainHex.blocks[0].push(testblk1); + MainHex.blocks[1].push(testblk2); + window.blocks.push(testblk3); + window.blocks.push(testblk4); + // when + togglespeed(-1, blocks, MainHex); + // then + // Assert speed of generation has changed + }); + From 2de7b07ad8814a4dfbff4d07d0e2c613389bc7d5 Mon Sep 17 00:00:00 2001 From: Bo Date: Sun, 22 Nov 2015 11:51:13 -0800 Subject: [PATCH 13/34] need to update tests case, resume work later. --- js/main.js | 2 +- qunit.htm | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index 9a9d8b253..1a227c908 100644 --- a/js/main.js +++ b/js/main.js @@ -185,7 +185,7 @@ function init(b) { function addNewBlock(blocklane, color, iter, distFromHex, settled) { //last two are optional parameters iter *= settings.speedModifier; - //TODO: added code + // PRJ: this line will scale the speed of the block by its respective amount specified in scale iter *= window.speedscale; if (!history[MainHex.ct]) { diff --git a/qunit.htm b/qunit.htm index c78d8de44..dd8b834a7 100644 --- a/qunit.htm +++ b/qunit.htm @@ -100,6 +100,7 @@ togglespeed(-1, blocks, MainHex); // then // Assert speed of generation has changed + assert.ok(1, "ok"); }); From 049b60a9ccd100e802e60f6e3a14931500b157a5 Mon Sep 17 00:00:00 2001 From: Bo Date: Sun, 22 Nov 2015 18:56:02 -0800 Subject: [PATCH 14/34] attempt at blanket --- js/test.js | 3 --- qunit.htm | 14 +++++++------- qunit2.htm | 24 ++++++++++++++++++++++++ vendor/blanket.min.js | 6 ++++++ 4 files changed, 37 insertions(+), 10 deletions(-) delete mode 100644 js/test.js create mode 100644 qunit2.htm create mode 100644 vendor/blanket.min.js diff --git a/js/test.js b/js/test.js deleted file mode 100644 index cad3efd37..000000000 --- a/js/test.js +++ /dev/null @@ -1,3 +0,0 @@ -function testFunc(){ - return 1; -} \ No newline at end of file diff --git a/qunit.htm b/qunit.htm index dd8b834a7..fb560d196 100644 --- a/qunit.htm +++ b/qunit.htm @@ -4,15 +4,15 @@ Hetrix Acceptance Tests - - + + - - - - - + + + + + diff --git a/qunit2.htm b/qunit2.htm new file mode 100644 index 000000000..cc4538467 --- /dev/null +++ b/qunit2.htm @@ -0,0 +1,24 @@ + + + + + Hetrix Acceptance Tests + + + + + + + + + +
+
+ + \ No newline at end of file diff --git a/vendor/blanket.min.js b/vendor/blanket.min.js new file mode 100644 index 000000000..c7d6ec526 --- /dev/null +++ b/vendor/blanket.min.js @@ -0,0 +1,6 @@ +/*! blanket - v1.2.0 */ +"undefined"!=typeof QUnit&&(QUnit.config.autostart=!1),function(a){}(null),function(a){window.isArguments=a.exports}({exports:{}}),function(a){window.forEach=a.exports}({exports:{}}),function(a){window.isArray=a.exports}({exports:{}}),function(a,b){window.objectKeys=b.exports}(function(){return isArguments},{exports:{}}),/*! + * falafel (c) James Halliday / MIT License + * https://github.com/substack/node-falafel + */ +function(a,b){function c(a,b,c){function d(b){c[a.range[0]]=b;for(var d=a.range[0]+1;dparseInt(b,10)}).forEach(function(b){e+=f+"['"+a+"']["+b+"]=0;\n"}),c&&_blanket._branchingArraySetup.sort(function(a,b){return a.line>b.line}).sort(function(a,b){return a.column>b.column}).forEach(function(b){b.file===a&&(e+="if (typeof "+f+"['"+a+"'].branchData["+b.line+"] === 'undefined'){\n",e+=f+"['"+a+"'].branchData["+b.line+"]=[];\n",e+="}",e+=f+"['"+a+"'].branchData["+b.line+"]["+b.column+"] = [];\n",e+=f+"['"+a+"'].branchData["+b.line+"]["+b.column+"].consequent = "+JSON.stringify(b.consequent)+";\n",e+=f+"['"+a+"'].branchData["+b.line+"]["+b.column+"].alternate = "+JSON.stringify(b.alternate)+";\n")}),e+="}"},_blockifyIf:function(a){if(c.indexOf(a.type)>-1){var b=a.consequent||a.body,d=a.alternate;d&&"BlockStatement"!==d.type&&d.update("{\n"+d.source()+"}\n"),b&&"BlockStatement"!==b.type&&b.update("{\n"+b.source()+"}\n")}},_trackBranch:function(a,b){var c=a.loc.start.line,d=a.loc.start.column;_blanket._branchingArraySetup.push({line:c,column:d,file:b,consequent:a.consequent.loc,alternate:a.alternate.loc});var e="_$branchFcn('"+b+"',"+c+","+d+","+a.test.source()+")?"+a.consequent.source()+":"+a.alternate.source();a.update(e)},_addTracking:function(a){var c=_blanket.getCovVar();return function(d){if(_blanket._blockifyIf(d),b.indexOf(d.type)>-1&&"LabeledStatement"!==d.parent.type){if(_blanket._checkDefs(d,a),"VariableDeclaration"===d.type&&("ForStatement"===d.parent.type||"ForInStatement"===d.parent.type))return;if(!d.loc||!d.loc.start)throw new Error("The instrumenter encountered a node with no location: "+Object.keys(d));d.update(c+"['"+a+"']["+d.loc.start.line+"]++;\n"+d.source()),_blanket._trackingArraySetup.push(d.loc.start.line)}else _blanket.options("branchTracking")&&"ConditionalExpression"===d.type?_blanket._trackBranch(d,a):"Literal"===d.type&&"use strict"===d.value&&d.parent&&"ExpressionStatement"===d.parent.type&&d.parent.parent&&"Program"===d.parent.parent.type&&(_blanket._useStrictMode=!0)}},_checkDefs:function(a,b){if(inBrowser){if("VariableDeclaration"===a.type&&a.declarations&&a.declarations.forEach(function(c){if("window"===c.id.name)throw new Error("Instrumentation error, you cannot redefine the 'window' variable in "+b+":"+a.loc.start.line)}),"FunctionDeclaration"===a.type&&a.params&&a.params.forEach(function(c){if("window"===c.name)throw new Error("Instrumentation error, you cannot redefine the 'window' variable in "+b+":"+a.loc.start.line)}),"ExpressionStatement"===a.type&&a.expression&&a.expression.left&&a.expression.left.object&&a.expression.left.property&&a.expression.left.object.name+"."+a.expression.left.property.name===_blanket.getCovVar())throw new Error("Instrumentation error, you cannot redefine the coverage variable in "+b+":"+a.loc.start.line)}else if("ExpressionStatement"===a.type&&a.expression&&a.expression.left&&!a.expression.left.object&&!a.expression.left.property&&a.expression.left.name===_blanket.getCovVar())throw new Error("Instrumentation error, you cannot redefine the coverage variable in "+b+":"+a.loc.start.line)},setupCoverage:function(){e.instrumentation="blanket",e.stats={suites:0,tests:0,passes:0,pending:0,failures:0,start:new Date}},_checkIfSetup:function(){if(!e.stats)throw new Error("You must call blanket.setupCoverage() first.")},onTestStart:function(){_blanket.options("debug")&&console.log("BLANKET-Test event started"),this._checkIfSetup(),e.stats.tests++,e.stats.pending++},onTestDone:function(a,b){this._checkIfSetup(),b===a?e.stats.passes++:e.stats.failures++,e.stats.pending--},onModuleStart:function(){this._checkIfSetup(),e.stats.suites++},onTestsDone:function(){_blanket.options("debug")&&console.log("BLANKET-Test event done"),this._checkIfSetup(),e.stats.end=new Date,inBrowser?this.report(e):(_blanket.options("branchTracking")||delete(inBrowser?window:global)[_blanket.getCovVar()].branchFcn,this.options("reporter").call(this,e))}},_blanket}(),function(a){var b=a.options;a.extend({outstandingRequireFiles:[],options:function(c,d){var e={};if("string"!=typeof c)b(c),e=c;else{if("undefined"==typeof d)return b(c);b(c,d),e[c]=d}e.adapter&&a._loadFile(e.adapter),e.loader&&a._loadFile(e.loader)},requiringFile:function(b,c){"undefined"==typeof b?a.outstandingRequireFiles=[]:"undefined"==typeof c?a.outstandingRequireFiles.push(b):a.outstandingRequireFiles.splice(a.outstandingRequireFiles.indexOf(b),1)},requireFilesLoaded:function(){return 0===a.outstandingRequireFiles.length},showManualLoader:function(){if(!document.getElementById("blanketLoaderDialog")){var a="
";a+=" 
",a+="
",a+="
",a+="Error: Blanket.js encountered a cross origin request error while instrumenting the source files. ",a+="

This is likely caused by the source files being referenced locally (using the file:// protocol). ",a+="

Some solutions include starting Chrome with special flags, running a server locally, or using a browser without these CORS restrictions (Safari).",a+="
","undefined"!=typeof FileReader&&(a+="
Or, try the experimental loader. When prompted, simply click on the directory containing all the source files you want covered.",a+="Start Loader",a+=""),a+="
Close",a+="
",a+="
";var b=".blanketDialogWrapper {";b+="display:block;",b+="position:fixed;",b+="z-index:40001; }",b+=".blanketDialogOverlay {",b+="position:fixed;",b+="width:100%;",b+="height:100%;",b+="background-color:black;",b+="opacity:.5; ",b+="-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=50)'; ",b+="filter:alpha(opacity=50); ",b+="z-index:40001; }",b+=".blanketDialogVerticalOffset { ",b+="position:fixed;",b+="top:30%;",b+="width:100%;",b+="z-index:40002; }",b+=".blanketDialogBox { ",b+="width:405px; ",b+="position:relative;",b+="margin:0 auto;",b+="background-color:white;",b+="padding:10px;",b+="border:1px solid black; }";var c=document.createElement("style");c.innerHTML=b,document.head.appendChild(c);var d=document.createElement("div");d.id="blanketLoaderDialog",d.className="blanketDialogWrapper",d.innerHTML=a,document.body.insertBefore(d,document.body.firstChild)}},manualFileLoader:function(a){function b(a){var b=new FileReader;b.onload=g,b.readAsText(a)}var c=Array.prototype.slice;a=c.call(a).filter(function(a){return""!==a.type});var d=a.length-1,e=0,f={};sessionStorage.blanketSessionLoader&&(f=JSON.parse(sessionStorage.blanketSessionLoader));var g=function(c){var g=c.currentTarget.result,h=a[e],i=h.webkitRelativePath&&""!==h.webkitRelativePath?h.webkitRelativePath:h.name;f[i]=g,e++,e===d?(sessionStorage.setItem("blanketSessionLoader",JSON.stringify(f)),document.location.reload()):b(a[e])};b(a[e])},_loadFile:function(b){if("undefined"!=typeof b){var c=new XMLHttpRequest;c.open("GET",b,!1),c.send(),a._addScript(c.responseText)}},_addScript:function(a){var b=document.createElement("script");b.type="text/javascript",b.text=a,(document.body||document.getElementsByTagName("head")[0]).appendChild(b)},hasAdapter:function(b){return null!==a.options("adapter")},report:function(b){document.getElementById("blanketLoaderDialog")||(a.blanketSession=null),b.files=window._$blanket;blanket.options("commonJS")?blanket._commonjs.require:window.require;if(!b.files||!Object.keys(b.files).length)return void(a.options("debug")&&console.log("BLANKET-Reporting No files were instrumented."));if("undefined"!=typeof b.files.branchFcn&&delete b.files.branchFcn,"string"==typeof a.options("reporter"))a._loadFile(a.options("reporter")),a.customReporter(b,a.options("reporter_options"));else if("function"==typeof a.options("reporter"))a.options("reporter")(b,a.options("reporter_options"));else{if("function"!=typeof a.defaultReporter)throw new Error("no reporter defined.");a.defaultReporter(b,a.options("reporter_options"))}},_bindStartTestRunner:function(a,b){a?a(b):"complete"===document.readyState?b():window.addEventListener("load",b,!1)},_loadSourceFiles:function(b){blanket.options("commonJS")?blanket._commonjs.require:window.require;a.options("debug")&&console.log("BLANKET-Collecting page scripts");var c=a.utils.collectPageScripts();if(0===c.length)b();else{sessionStorage.blanketSessionLoader&&(a.blanketSession=JSON.parse(sessionStorage.blanketSessionLoader)),c.forEach(function(b,c){a.utils.cache[b]={loaded:!1}});var d=-1;a.utils.loadAll(function(a){return a?"undefined"!=typeof c[d+1]:(d++,d>=c.length?null:c[d])},b)}},beforeStartTestRunner:function(b){b=b||{},b.checkRequirejs="undefined"==typeof b.checkRequirejs?!0:b.checkRequirejs,b.callback=b.callback||function(){},b.coverage="undefined"==typeof b.coverage?!0:b.coverage,b.coverage?a._bindStartTestRunner(b.bindEvent,function(){a._loadSourceFiles(function(){var c=function(){return b.condition?b.condition():a.requireFilesLoaded()},d=function(){if(c()){a.options("debug")&&console.log("BLANKET-All files loaded, init start test runner callback.");var e=a.options("testReadyCallback");e?"function"==typeof e?e(b.callback):"string"==typeof e&&(a._addScript(e),b.callback()):b.callback()}else setTimeout(d,13)};d()})}):b.callback()},utils:{qualifyURL:function(a){var b=document.createElement("a");return b.href=a,b.href}}})}(blanket),blanket.defaultReporter=function(a){function b(a){var b=document.getElementById(a);"block"===b.style.display?b.style.display="none":b.style.display="block"}function c(a){return a.replace(/\&/g,"&").replace(//g,">").replace(/\"/g,""").replace(/\'/g,"'").replace(/`/g,"`").replace(/[$]/g,"$").replace(/&/g,"&")}function d(a,b){var c=b?0:1;return"undefined"==typeof a||null===typeof a||"undefined"==typeof a[c]?!1:a[c].length>0}function e(a,b,f,g,h){var i="",j="";if(q.length>0)if(i+="",q[0][0].end.line===h){if(i+=c(b.slice(0,q[0][0].end.column))+"",b=b.slice(q[0][0].end.column),q.shift(),q.length>0)if(i+="",q[0][0].end.line===h){if(i+=c(b.slice(0,q[0][0].end.column))+"",b=b.slice(q[0][0].end.column),q.shift(),!f)return{src:i+c(b),cols:f}}else{if(!f)return{src:i+c(b)+"",cols:f};j=""}else if(!f)return{src:i+c(b),cols:f}}else{if(!f)return{src:i+c(b)+"",cols:f};j=""}var k=f[a],l=k.consequent;if(l.start.line>h)q.unshift([k.alternate,k]),q.unshift([l,k]),b=c(b);else{var m="";if(i+=c(b.slice(0,l.start.column-g))+m,f.length>a+1&&f[a+1].consequent.start.line===h&&f[a+1].consequent.start.column-g";var o=k.alternate;if(o.start.line>h)i+=c(b.slice(l.end.column-g)),q.unshift([o,k]);else{if(i+=c(b.slice(l.end.column-g,o.start.column-g)),m="",i+=m,f.length>a+1&&f[a+1].consequent.start.line===h&&f[a+1].consequent.start.column-g",i+=c(b.slice(o.end.column-g)),b=i}}return{src:b+j,cols:f}}var f="#blanket-main {margin:2px;background:#EEE;color:#333;clear:both;font-family:'Helvetica Neue Light', 'HelveticaNeue-Light', 'Helvetica Neue', Calibri, Helvetica, Arial, sans-serif; font-size:17px;} #blanket-main a {color:#333;text-decoration:none;} #blanket-main a:hover {text-decoration:underline;} .blanket {margin:0;padding:5px;clear:both;border-bottom: 1px solid #FFFFFF;} .bl-error {color:red;}.bl-success {color:#5E7D00;} .bl-file{width:auto;} .bl-cl{float:left;} .blanket div.rs {margin-left:50px; width:150px; float:right} .bl-nb {padding-right:10px;} #blanket-main a.bl-logo {color: #EB1764;cursor: pointer;font-weight: bold;text-decoration: none} .bl-source{ overflow-x:scroll; background-color: #FFFFFF; border: 1px solid #CBCBCB; color: #363636; margin: 25px 20px; width: 80%;} .bl-source div{white-space: pre;font-family: monospace;} .bl-source > div > span:first-child{background-color: #EAEAEA;color: #949494;display: inline-block;padding: 0 10px;text-align: center;width: 30px;} .bl-source .hit{background-color:#c3e6c7} .bl-source .miss{background-color:#e6c3c7} .bl-source span.branchWarning{color:#000;background-color:yellow;} .bl-source span.branchOkay{color:#000;background-color:transparent;}",g=60,h=document.head,i=0,j=document.body,k=Object.keys(a.files).some(function(b){return"undefined"!=typeof a.files[b].branchData}),l="
results
Coverage (%)
Covered/Total Smts.
"+(k?"
Covered/Total Branches
":"")+"
",m="
{{fileNumber}}.{{file}}
{{percentage}} %
{{numberCovered}}/{{totalSmts}}
"+(k?"
{{passedBranches}}/{{totalBranches}}
":"")+"
";grandTotalTemplate="
{{rowTitle}}
{{percentage}} %
{{numberCovered}}/{{totalSmts}}
"+(k?"
{{passedBranches}}/{{totalBranches}}
":"")+"
";var n=document.createElement("script");n.type="text/javascript",n.text=b.toString().replace("function "+b.name,"function blanket_toggleSource"),j.appendChild(n);var o=function(a,b){return Math.round(a/b*100*100)/100},p=function(a,b,c){var d=document.createElement(a);d.innerHTML=c,b.appendChild(d)},q=[],r=function(a){return"undefined"!=typeof a},s=a.files,t={totalSmts:0,numberOfFilesCovered:0,passedBranches:0,totalBranches:0,moduleTotalStatements:{},moduleTotalCoveredStatements:{},moduleTotalBranches:{},moduleTotalCoveredBranches:{}},u=_blanket.options("modulePattern"),v=u?new RegExp(u):null;for(var w in s)if(s.hasOwnProperty(w)){i++;var x,y=s[w],z=0,A=0,B=[];for(x=0;x0||"undefined"!=typeof y.branchData)if("undefined"!=typeof y.branchData[x+1]){var D=y.branchData[x+1].filter(r),E=0;C=e(E,C,D,0,x+1).src}else C=q.length?e(0,C,null,0,x+1).src:c(C);else C=c(C);var F="";y[x+1]?(A+=1,z+=1,F="hit"):0===y[x+1]&&(z++,F="miss"),B[x+1]="
"+(x+1)+""+C+"
"}t.totalSmts+=z,t.numberOfFilesCovered+=A;var G=0,H=0;if("undefined"!=typeof y.branchData)for(var I=0;I0&&"undefined"!=typeof y.branchData[I][J][1]&&y.branchData[I][J][1].length>0&&H++);if(t.passedBranches+=H,t.totalBranches+=G,v){var K=w.match(v)[1];t.moduleTotalStatements.hasOwnProperty(K)||(t.moduleTotalStatements[K]=0,t.moduleTotalCoveredStatements[K]=0),t.moduleTotalStatements[K]+=z,t.moduleTotalCoveredStatements[K]+=A,t.moduleTotalBranches.hasOwnProperty(K)||(t.moduleTotalBranches[K]=0,t.moduleTotalCoveredBranches[K]=0),t.moduleTotalBranches[K]+=G,t.moduleTotalCoveredBranches[K]+=H}var L=o(A,z),M=m.replace("{{file}}",w).replace("{{percentage}}",L).replace("{{numberCovered}}",A).replace(/\{\{fileNumber\}\}/g,i).replace("{{totalSmts}}",z).replace("{{totalBranches}}",G).replace("{{passedBranches}}",H).replace("{{source}}",B.join(" "));M=g>L?M.replace("{{statusclass}}","bl-error"):M.replace("{{statusclass}}","bl-success"),l+=M}var N=function(a,b,c,d,e){var f=o(b,a),h=g>f?"bl-error":"bl-success",i=e?"Total for module: "+e:"Global total",j=grandTotalTemplate.replace("{{rowTitle}}",i).replace("{{percentage}}",f).replace("{{numberCovered}}",b).replace("{{totalSmts}}",a).replace("{{passedBranches}}",d).replace("{{totalBranches}}",c).replace("{{statusclass}}",h);l+=j};if(v)for(var O in t.moduleTotalStatements)if(t.moduleTotalStatements.hasOwnProperty(O)){var P=t.moduleTotalStatements[O],Q=t.moduleTotalCoveredStatements[O],R=t.moduleTotalBranches[O],S=t.moduleTotalCoveredBranches[O];N(P,Q,R,S,O)}N(t.totalSmts,t.numberOfFilesCovered,t.totalBranches,t.passedBranches,null),l+="
",p("style",h,f),document.getElementById("blanket-main")?document.getElementById("blanket-main").innerHTML=l.slice(23,-6):p("div",j,l)},function(){var a={},b=Array.prototype.slice,c=b.call(document.scripts);b.call(c[c.length-1].attributes).forEach(function(b){if("data-cover-only"===b.nodeName&&(a.filter=b.nodeValue),"data-cover-never"===b.nodeName&&(a.antifilter=b.nodeValue),"data-cover-reporter"===b.nodeName&&(a.reporter=b.nodeValue),"data-cover-adapter"===b.nodeName&&(a.adapter=b.nodeValue),"data-cover-loader"===b.nodeName&&(a.loader=b.nodeValue),"data-cover-timeout"===b.nodeName&&(a.timeout=b.nodeValue),"data-cover-modulepattern"===b.nodeName&&(a.modulePattern=b.nodeValue),"data-cover-reporter-options"===b.nodeName)try{a.reporter_options=JSON.parse(b.nodeValue)}catch(c){if(blanket.options("debug"))throw new Error("Invalid reporter options. Must be a valid stringified JSON object.")}if("data-cover-testReadyCallback"===b.nodeName&&(a.testReadyCallback=b.nodeValue),"data-cover-customVariable"===b.nodeName&&(a.customVariable=b.nodeValue),"data-cover-flags"===b.nodeName){var d=" "+b.nodeValue+" ";d.indexOf(" ignoreError ")>-1&&(a.ignoreScriptError=!0),d.indexOf(" autoStart ")>-1&&(a.autoStart=!0),d.indexOf(" ignoreCors ")>-1&&(a.ignoreCors=!0),d.indexOf(" branchTracking ")>-1&&(a.branchTracking=!0),d.indexOf(" sourceURL ")>-1&&(a.sourceURL=!0),d.indexOf(" debug ")>-1&&(a.debug=!0),d.indexOf(" engineOnly ")>-1&&(a.engineOnly=!0),d.indexOf(" commonJS ")>-1&&(a.commonJS=!0),d.indexOf(" instrumentCache ")>-1&&(a.instrumentCache=!0)}}),blanket.options(a),"undefined"!=typeof requirejs&&blanket.options("existingRequireJS",!0),blanket.options("commonJS")&&(blanket._commonjs={})}(),function(a){a.extend({utils:{normalizeBackslashes:function(a){return a.replace(/\\/g,"/")},matchPatternAttribute:function(b,c){if("string"==typeof c){if(0===c.indexOf("[")){var d=c.slice(1,c.length-1).split(",");return d.some(function(c){return a.utils.matchPatternAttribute(b,a.utils.normalizeBackslashes(c.slice(1,-1)))})}if(0===c.indexOf("//")){var e=c.slice(2,c.lastIndexOf("/")),f=c.slice(c.lastIndexOf("/")+1),g=new RegExp(e,f);return g.test(b)}return 0===c.indexOf("#")?window[c.slice(1)].call(window,b):b.indexOf(a.utils.normalizeBackslashes(c))>-1}return c instanceof Array?c.some(function(c){return a.utils.matchPatternAttribute(b,c)}):c instanceof RegExp?c.test(b):"function"==typeof c?c.call(window,b):void 0},blanketEval:function(b){a._addScript(b)},collectPageScripts:function(){var b=Array.prototype.slice,c=(b.call(document.scripts),[]),d=[],e=a.options("filter");if(null!=e){var f=a.options("antifilter");c=b.call(document.scripts).filter(function(c){return 1===b.call(c.attributes).filter(function(b){return"src"===b.nodeName&&a.utils.matchPatternAttribute(b.nodeValue,e)&&("undefined"==typeof f||!a.utils.matchPatternAttribute(b.nodeValue,f))}).length})}else c=b.call(document.querySelectorAll("script[data-cover]"));return d=c.map(function(c){return a.utils.qualifyURL(b.call(c.attributes).filter(function(a){return"src"===a.nodeName})[0].nodeValue)}),e||a.options("filter","['"+d.join("','")+"']"),d},loadAll:function(b,c,d){var e=b(),f=a.utils.scriptIsLoaded(e,a.utils.ifOrdered,b,c);if(a.utils.cache[e]&&a.utils.cache[e].loaded)f();else{var g=function(){a.options("debug")&&console.log("BLANKET-Mark script:"+e+", as loaded and move to next script."),f()},h=function(b){a.options("debug")&&console.log("BLANKET-File loading finished"),"undefined"!=typeof b&&(a.options("debug")&&console.log("BLANKET-Add file to DOM."),a._addScript(b)),g()};a.utils.attachScript({url:e},function(b){a.utils.processFile(b,e,h,h)})}},attachScript:function(b,c){var d=a.options("timeout")||3e3;setTimeout(function(){if(!a.utils.cache[b.url].loaded)throw new Error("error (timeout="+d+") loading source script: "+b.url)},d),a.utils.getFile(b.url,c,function(){throw new Error("error loading source script: "+b.url)})},ifOrdered:function(b,c){var d=b(!0);d?a.utils.loadAll(b,c):c(new Error("Error in loading chain."))},scriptIsLoaded:function(b,c,d,e){return a.options("debug")&&console.log("BLANKET-Returning function"),function(){a.options("debug")&&console.log("BLANKET-Marking file as loaded: "+b),a.utils.cache[b].loaded=!0,a.utils.allLoaded()?(a.options("debug")&&console.log("BLANKET-All files loaded"),e()):c&&(a.options("debug")&&console.log("BLANKET-Load next file."),c(d,e))}},cache:{},allLoaded:function(){for(var b=Object.keys(a.utils.cache),c=0;cb;b+=1){c=progIds[b];try{new ActiveXObject(c);break}catch(d){}}this.createXhr=function(){return new a(c)}}},craeteXhr:function(){throw new Error("cacheXhrConstructor is supposed to overwrite this function.")},getFile:function(b,c,d,e){var f=!1;if(a.blanketSession)for(var g=Object.keys(a.blanketSession),h=0;h-1)return c(a.blanketSession[i]),void(f=!0)}if(!f){var j=a.utils.createXhr();j.open("GET",b,!0),e&&e(j,b),j.onreadystatechange=function(a){var e,f;4===j.readyState&&(e=j.status,e>399&&600>e?(f=new Error(b+" HTTP status: "+e),f.xhr=j,d(f)):c(j.responseText))};try{j.send(null)}catch(k){if(!k.code||101!==k.code&&1012!==k.code||a.options("ignoreCors")!==!1)throw k;a.showManualLoader()}}}}}),function(){var b=(blanket.options("commonJS")?blanket._commonjs.require:window.require,blanket.options("commonJS")?blanket._commonjs.requirejs:window.requirejs);!a.options("engineOnly")&&a.options("existingRequireJS")&&(a.utils.oldloader=b.load,b.load=function(b,c,d){a.requiringFile(d),a.utils.getFile(d,function(e){a.utils.processFile(e,d,function(){b.completeLoad(c)},function(){a.utils.oldloader(b,c,d)})},function(b){throw a.requiringFile(),b})}),a.utils.cacheXhrConstructor()}()}(blanket),function(){if("undefined"!=typeof QUnit){var a=function(){return window.QUnit.config.queue.length>0&&blanket.noConflict().requireFilesLoaded()};QUnit.config.urlConfig[0].tooltip?(QUnit.config.urlConfig.push({id:"coverage",label:"Enable coverage",tooltip:"Enable code coverage."}),QUnit.urlParams.coverage||blanket.options("autoStart")?(QUnit.begin(function(){blanket.noConflict().setupCoverage()}),QUnit.done(function(a,b){blanket.noConflict().onTestsDone()}),QUnit.moduleStart(function(a){blanket.noConflict().onModuleStart()}),QUnit.testStart(function(a){blanket.noConflict().onTestStart()}),QUnit.testDone(function(a){blanket.noConflict().onTestDone(a.total,a.passed)}),blanket.noConflict().beforeStartTestRunner({condition:a,callback:function(){(!blanket.options("existingRequireJS")||blanket.options("autoStart"))&&QUnit.start()}})):(blanket.options("existingRequireJS")&&(requirejs.load=_blanket.utils.oldloader),blanket.noConflict().beforeStartTestRunner({condition:a,callback:function(){(!blanket.options("existingRequireJS")||blanket.options("autoStart"))&&QUnit.start()},coverage:!1}))):(QUnit.begin=function(){blanket.noConflict().setupCoverage()},QUnit.done=function(a,b){blanket.noConflict().onTestsDone()},QUnit.moduleStart=function(a){blanket.noConflict().onModuleStart()},QUnit.testStart=function(a){blanket.noConflict().onTestStart()},QUnit.testDone=function(a){blanket.noConflict().onTestDone(a.total,a.passed)},blanket.beforeStartTestRunner({condition:a,callback:QUnit.start}))}}(); \ No newline at end of file From 61caf65919db56b2b4efd990f7b0972126b6c6d6 Mon Sep 17 00:00:00 2001 From: patrick455 Date: Mon, 23 Nov 2015 22:05:00 -0800 Subject: [PATCH 15/34] Added qunit tests for scenarios 1.2 to 1.4 --- qunit.htm | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/qunit.htm b/qunit.htm index fb560d196..30c21ca79 100644 --- a/qunit.htm +++ b/qunit.htm @@ -5,7 +5,7 @@ Hetrix Acceptance Tests - + @@ -96,11 +96,98 @@ MainHex.blocks[1].push(testblk2); window.blocks.push(testblk3); window.blocks.push(testblk4); + + + //game currently runs at 40% of original speed + window.speedscale = 0.4; + var prevSpeed = window.speedscale; + // when togglespeed(-1, blocks, MainHex); // then // Assert speed of generation has changed - assert.ok(1, "ok"); + assert.equal(prevSpeed-0.1, window.speedscale); + }); + + QUnit.test( "Speed up test, scenario 1.2", function( assert ) { + initialize(1); + // given + window.gameState = 1; // game is starting + var testblk1 = new Block(1, "#e74c3c", 8, -1, 1); + var testblk2 = new Block(2, "#f1c40f", 8, -1, 1); + var testblk3 = new Block(3, "#3498db", 8, -1, 0); + var testblk4 = new Block(4, "#2ecc71", 8, -1, 0); + MainHex = new Hex(6); + waveone = new waveGen(MainHex); + MainHex.blocks[0].push(testblk1); + MainHex.blocks[1].push(testblk2); + window.blocks.push(testblk3); + window.blocks.push(testblk4); + + + //game currently runs at 20% of original speed + window.speedscale = 0.2; + var prevSpeed = window.speedscale; + + // when + togglespeed(-1, blocks, MainHex); + // then + // Assert speed of generation has changed + assert.equal(prevSpeed, window.speedscale); + }); + + QUnit.test( "Speed up test, scenario 1.3", function( assert ) { + initialize(1); + // given + window.gameState = 1; // game is starting + var testblk1 = new Block(1, "#e74c3c", 8, -1, 1); + var testblk2 = new Block(2, "#f1c40f", 8, -1, 1); + var testblk3 = new Block(3, "#3498db", 8, -1, 0); + var testblk4 = new Block(4, "#2ecc71", 8, -1, 0); + MainHex = new Hex(6); + waveone = new waveGen(MainHex); + MainHex.blocks[0].push(testblk1); + MainHex.blocks[1].push(testblk2); + window.blocks.push(testblk3); + window.blocks.push(testblk4); + + + //game currently runs at 150% of original speed + window.speedscale = 1.5; + var prevSpeed = window.speedscale; + + // when + togglespeed(1, blocks, MainHex); + // then + // Assert speed of generation has changed + assert.equal(prevSpeed+0.1, window.speedscale); + }); + + QUnit.test( "Speed up test, scenario 1.4", function( assert ) { + initialize(1); + // given + window.gameState = 1; // game is starting + var testblk1 = new Block(1, "#e74c3c", 8, -1, 1); + var testblk2 = new Block(2, "#f1c40f", 8, -1, 1); + var testblk3 = new Block(3, "#3498db", 8, -1, 0); + var testblk4 = new Block(4, "#2ecc71", 8, -1, 0); + MainHex = new Hex(6); + waveone = new waveGen(MainHex); + MainHex.blocks[0].push(testblk1); + MainHex.blocks[1].push(testblk2); + window.blocks.push(testblk3); + window.blocks.push(testblk4); + + + //game currently runs at 180% of original speed + window.speedscale = 1.8; + var prevSpeed = window.speedscale; + + // when + togglespeed(1, blocks, MainHex); + // then + // Assert speed of generation has changed + assert.equal(prevSpeed, window.speedscale); }); From e9830ecd6ea470bc57eedb2cb7da9c00eeb45f73 Mon Sep 17 00:00:00 2001 From: patrick455 Date: Wed, 25 Nov 2015 11:47:45 -0800 Subject: [PATCH 16/34] Added comments to doesBlockCollide. Refactoring to be performed (block settled) --- js/Hex.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/js/Hex.js b/js/Hex.js index ef54ff426..3f6fc7e4b 100644 --- a/js/Hex.js +++ b/js/Hex.js @@ -57,6 +57,8 @@ function Hex(sideLength) { }; this.doesBlockCollide = function(block, position, tArr) { + + //block has rested on either the center of hex or on another block. Collision happened if (block.settled) { return; } @@ -64,38 +66,57 @@ function Hex(sideLength) { if (position !== undefined) { arr = tArr; if (position <= 0) { + //current block has hit the center hex + if (block.distFromHex - block.iter * this.dt * settings.scale - (this.sideLength / 2) * Math.sqrt(3) <= 0) { block.distFromHex = (this.sideLength / 2) * Math.sqrt(3); block.settled = 1; block.checked = 1; - } else { + } + + //current block is still falling, increment iterations + else { block.settled = 0; block.iter = 1.5 + (waveone.difficulty/15) * 3; } - } else { + } + + else { + + //current block is above an existing settled block and hits the existing block + if (arr[position - 1].settled && block.distFromHex - block.iter * this.dt * settings.scale - arr[position - 1].distFromHex - arr[position - 1].height <= 0) { block.distFromHex = arr[position - 1].distFromHex + arr[position - 1].height; block.settled = 1; block.checked = 1; } + + //either the lower block has not settled yet OR current block has not settled (still falling) else { block.settled = 0; block.iter = 1.5 + (waveone.difficulty/15) * 3; } } - } else { + } + + //block is yet created (position is not defined) + else { var lane = this.sides - block.fallingLane;// -this.position; lane += this.position; lane = (lane+this.sides) % this.sides; var arr = this.blocks[lane]; + // + if (arr.length > 0) { if (block.distFromHex + block.iter * this.dt * settings.scale - arr[arr.length - 1].distFromHex - arr[arr.length - 1].height <= 0) { block.distFromHex = arr[arr.length - 1].distFromHex + arr[arr.length - 1].height; this.addBlock(block); } - } else { + } + + else { if (block.distFromHex + block.iter * this.dt * settings.scale - (this.sideLength / 2) * Math.sqrt(3) <= 0) { block.distFromHex = (this.sideLength / 2) * Math.sqrt(3); this.addBlock(block); From de23d3aa68d08d5513575ae3e0d1832c0d4db624 Mon Sep 17 00:00:00 2001 From: patrick455 Date: Thu, 26 Nov 2015 23:49:08 -0800 Subject: [PATCH 17/34] Added toggleDrop function in input.js: block drops immediately upon corresponding keypress(space-key for now) --- js/input.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/js/input.js b/js/input.js index 08f5f3e03..ee27774db 100644 --- a/js/input.js +++ b/js/input.js @@ -41,7 +41,7 @@ function addKeyListeners() { keypress.register_combo({ keys: "space", - on_keydown: function(){pause();} + on_keydown: function(){toggleDrop(window.blocks, MainHex);} }); keypress.register_combo({ @@ -257,3 +257,11 @@ function togglespeed(increment, blocks, hex){ // store the old value of so speed can be adjusted in future window.oldspeedscale = window.speedscale; } + +// When called, the currently falling blocks will immediately fall towards the center of hex +function toggleDrop(blocks, hex){ + + //obtain current falling blocks; blocks[0] for a single falling block, [1] for a joint falling block + blocks[0].distFromHex = 0; + blocks[1].distFromHex = 0; +} From d689f50d84711156df0359c102cf7c199872f9ef Mon Sep 17 00:00:00 2001 From: patrick455 Date: Fri, 27 Nov 2015 17:11:36 -0800 Subject: [PATCH 18/34] Edited toggleDrop function --- js/input.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/js/input.js b/js/input.js index ee27774db..cb82561f3 100644 --- a/js/input.js +++ b/js/input.js @@ -261,7 +261,8 @@ function togglespeed(increment, blocks, hex){ // When called, the currently falling blocks will immediately fall towards the center of hex function toggleDrop(blocks, hex){ - //obtain current falling blocks; blocks[0] for a single falling block, [1] for a joint falling block - blocks[0].distFromHex = 0; - blocks[1].distFromHex = 0; + //obtain current falling blocks; blocks[0] for a single falling block, [1] for a joint falling block... + for (var i = 0; i < blocks.length; i++){ + blocks[i].distFromHex = 0; + } } From 2df0d52b86162c2afa07043de54fa2717b1afe7a Mon Sep 17 00:00:00 2001 From: Bo Date: Sun, 29 Nov 2015 10:42:59 -0800 Subject: [PATCH 19/34] drop only closest block to hex feature implemented --- js/input.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/js/input.js b/js/input.js index cb82561f3..a15c781ec 100644 --- a/js/input.js +++ b/js/input.js @@ -227,14 +227,12 @@ function togglespeed(increment, blocks, hex){ // if incrementing, adjust the speed accordingly if (window.speedscale >= 0.3){ window.speedscale -= 0.1; - console.log(window.speedscale); } } else { // increment is positive // if decrementing, adjust the speed accordingly if (window.speedscale < 1.7){ window.speedscale += 0.1; - console.log(window.speedscale); } } @@ -260,9 +258,23 @@ function togglespeed(increment, blocks, hex){ // When called, the currently falling blocks will immediately fall towards the center of hex function toggleDrop(blocks, hex){ - + + // tolerance for comparing doubles + var tolearnce = 0.01; + + // extract only the closest block to the + var minDist = 999999; + for (var i = 0; i < blocks.length; i++){ + console.log(blocks[i].distFromHex); + if (blocks[i].distFromHex < minDist){ + minDist = blocks[i].distFromHex; + } + } + //obtain current falling blocks; blocks[0] for a single falling block, [1] for a joint falling block... for (var i = 0; i < blocks.length; i++){ - blocks[i].distFromHex = 0; + if (blocks[i].distFromHex >= (minDist - tolearnce) && blocks[i].distFromHex <= (minDist + tolearnce)){ + blocks[i].distFromHex = 0; + } } } From c335a719555573a2d18004dd752dd36ec202e019 Mon Sep 17 00:00:00 2001 From: patrick455 Date: Sun, 29 Nov 2015 17:31:19 -0800 Subject: [PATCH 20/34] Updated scenarios for toggleDrop; Modified toggleDrop function to use existing Hex.addblock instead of setting distFromHex = 0; Added unit tests for toggleDrop function --- docs/scenarios.txt | 33 +++++++++++++++++++ js/input.js | 4 +-- qunit.htm | 80 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 111 insertions(+), 6 deletions(-) diff --git a/docs/scenarios.txt b/docs/scenarios.txt index 23f6062bf..7d4f84575 100644 --- a/docs/scenarios.txt +++ b/docs/scenarios.txt @@ -72,3 +72,36 @@ Then the colour of the blocks will change to anothe set of colours that is frien if the player has not cycled through all the colourblind colours yet, otherwise the colour of the blocks will revert back to the default colour. And the game continues. + +===================================================== +Additional Feature: +Block falls immediately onto center hex upon keypress + +3. User Story: +As a player +I want to be able to drop the closest falling block immediately onto the side of the center hex I have rotated to immediately +So that I am able to play the game at a faster pace + +Scenario 3.1: User presses Drop Block Toggle Button when a single block is falling +Given that the game has started + And the player is currently playing the game + And a single-block is currently falling +When the player presses the "space" key +Then the currently falling single-block will fall instantly onto the side of the center hex the player has rotated to + And the game continues. + +Scenario 3.2: User presses Drop Block Toggle Button when a doubly-joint block is falling +Given that the game has started + And the player is currently playing the game + And a doubly-joint block is currently falling +When the player presses the "space" key +Then the whole joint block will fall instantly onto the side of the center hex the player has rotated to as a single piece + And the game continues. + +Scenario 3.3: User presses Drop Block Toggle Button when multiple blocks are falling on the screen +Given taht the game has started + And the player is currently playing the game + And there are 2 blocks both falling onto the center hex on the same lane +Whe the player presses the "space" key +Then only the block closest to the center hex falls instantly while the other falling block remains falling at its original speed + And the game continues. diff --git a/js/input.js b/js/input.js index a15c781ec..e43757588 100644 --- a/js/input.js +++ b/js/input.js @@ -231,7 +231,7 @@ function togglespeed(increment, blocks, hex){ } else { // increment is positive // if decrementing, adjust the speed accordingly - if (window.speedscale < 1.7){ + if (window.speedscale < 1.4){ window.speedscale += 0.1; } } @@ -274,7 +274,7 @@ function toggleDrop(blocks, hex){ //obtain current falling blocks; blocks[0] for a single falling block, [1] for a joint falling block... for (var i = 0; i < blocks.length; i++){ if (blocks[i].distFromHex >= (minDist - tolearnce) && blocks[i].distFromHex <= (minDist + tolearnce)){ - blocks[i].distFromHex = 0; + hex.addBlock(blocks[i]); } } } diff --git a/qunit.htm b/qunit.htm index 30c21ca79..8d9059f9f 100644 --- a/qunit.htm +++ b/qunit.htm @@ -152,15 +152,15 @@ window.blocks.push(testblk4); - //game currently runs at 150% of original speed - window.speedscale = 1.5; + //game currently runs at 130% of original speed + window.speedscale = 1.3; var prevSpeed = window.speedscale; // when togglespeed(1, blocks, MainHex); // then - // Assert speed of generation has changed - assert.equal(prevSpeed+0.1, window.speedscale); + // Assert that gamespeed is increased by 0.1, since it has not reached the limit of 1.4 yet + assert.equal(prevSpeed + 0.1, window.speedscale); }); QUnit.test( "Speed up test, scenario 1.4", function( assert ) { @@ -190,6 +190,78 @@ assert.equal(prevSpeed, window.speedscale); }); + QUnit.test( "Block Drop Test, scenario 3.1", function( assert ) { + initialize(1); + // given + window.gameState = 1; // game is starting + + //a single falling block + var testblk1 = new Block(1, "#e74c3c", 8, settings.startDist * settings.scale); + MainHex = new Hex(6); + waveone = new waveGen(MainHex); + + //block is falling + window.blocks.push(testblk1); + assert.equal(testblk1.settled, 0); + + // when + toggleDrop(blocks, MainHex); + // then + // Assert only testblk1 has fell immediately onto center hex + assert.equal(testblk1.settled, 1); + }); + + QUnit.test( "Block Drop Test, scenario 3.2", function( assert ) { + initialize(1); + // given + window.gameState = 1; // game is starting + + //a doubly-joint falling block + var testblk1 = new Block(1, "#e74c3c", 8, settings.startDist * settings.scale); + var testblk2 = new Block(2, "#f1c40f", 8, settings.startDist * settings.scale); + MainHex = new Hex(6); + waveone = new waveGen(MainHex); + + //block is falling + window.blocks.push(testblk1); + window.blocks.push(testblk2); + assert.equal(testblk1.settled, 0); + assert.equal(testblk2.settled, 0); + + // when + toggleDrop(blocks, MainHex); + // then + // Assert both testblk1 and testblk2 are settled on the center hex + assert.equal(testblk1.settled, 1); + assert.equal(testblk2.settled, 1); + }); + + QUnit.test( "Block Drop Test, scenario 3.3", function( assert ) { + initialize(1); + // given + window.gameState = 1; // game is starting + + //two falling blocks on the same lane, but at different distances from the center hex + //testblk 2 is closer to the center hex + var testblk1 = new Block(1, "#e74c3c", 8, settings.startDist * settings.scale); + var testblk2 = new Block(1, "#f1c40f", 8, (settings.startDist * settings.scale) - 16); + MainHex = new Hex(6); + waveone = new waveGen(MainHex); + + //both blocks are falling + window.blocks.push(testblk1); + window.blocks.push(testblk2); + assert.equal(testblk1.settled, 0); + assert.equal(testblk2.settled, 0); + + // when + toggleDrop(blocks, MainHex); + // then + // Assert that only testblk 2 has fell onto center hex; testblk 1 should still be falling and has not settled + assert.equal(testblk1.settled, 0); + assert.equal(testblk2.settled, 1); + }); + From 65fa3e994a05a9862167faa74d1b096fe4d5400c Mon Sep 17 00:00:00 2001 From: Bo Date: Mon, 30 Nov 2015 11:57:50 -0800 Subject: [PATCH 21/34] assert that blocks are added to Hex, rewrite some test cases to conform to Qunit standards --- qunit.htm | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/qunit.htm b/qunit.htm index 8d9059f9f..d0f93f15b 100644 --- a/qunit.htm +++ b/qunit.htm @@ -186,7 +186,7 @@ // when togglespeed(1, blocks, MainHex); // then - // Assert speed of generation has changed + // Assert speed of generation has not changed assert.equal(prevSpeed, window.speedscale); }); @@ -202,13 +202,16 @@ //block is falling window.blocks.push(testblk1); - assert.equal(testblk1.settled, 0); + assert.ok(testblk1.settled == 0, "test block 1 unsettled"); // when toggleDrop(blocks, MainHex); + MainHex.doesBlockCollide(testblk1, testblk1.fallingLane, window.blocks); // then + // assert block added to hex + assert.ok(MainHex.blocks[5].length == 1, "lane 5 has one block"); // Assert only testblk1 has fell immediately onto center hex - assert.equal(testblk1.settled, 1); + assert.ok(testblk1.settled == 1, "test block 1 settled"); }); QUnit.test( "Block Drop Test, scenario 3.2", function( assert ) { @@ -225,15 +228,21 @@ //block is falling window.blocks.push(testblk1); window.blocks.push(testblk2); - assert.equal(testblk1.settled, 0); - assert.equal(testblk2.settled, 0); + assert.ok(testblk1.settled == 0, "test block 1 not settled"); + assert.ok(testblk2.settled == 0, "test block 2 not settled"); // when toggleDrop(blocks, MainHex); // then + // add block to hex + MainHex.doesBlockCollide(testblk1, testblk1.fallinglane, window.blocks); + MainHex.doesBlockCollide(testblk2, testblk2.fallinglane, window.blocks); + // Assert both testblk1 and testblk2 are settled on the center hex - assert.equal(testblk1.settled, 1); - assert.equal(testblk2.settled, 1); + assert.ok(testblk1.settled == 1, "test block 1 settled"); + assert.ok(testblk2.settled == 1, "test block 2 settled"); + assert.ok(MainHex.blocks[4].length == 1, "lane 4 has one block"); + assert.ok(MainHex.blocks[5].length == 1, "lane 5 has one block"); }); QUnit.test( "Block Drop Test, scenario 3.3", function( assert ) { @@ -251,16 +260,23 @@ //both blocks are falling window.blocks.push(testblk1); window.blocks.push(testblk2); - assert.equal(testblk1.settled, 0); - assert.equal(testblk2.settled, 0); + assert.ok(testblk1.settled == 0, "test block 1 not settled"); + assert.ok(testblk2.settled == 0, "test block 2 not settled"); // when toggleDrop(blocks, MainHex); + // TODO: ensure blocks collide + MainHex.doesBlockCollide(testblk1, testblk1.fallingLane, window.blocks); + MainHex.doesBlockCollide(testblk2, testblk2.fallingLane, window.blocks); // then // Assert that only testblk 2 has fell onto center hex; testblk 1 should still be falling and has not settled - assert.equal(testblk1.settled, 0); - assert.equal(testblk2.settled, 1); - }); + + assert.ok(testblk1.settled == 0, "test block 1 not settled"); + assert.ok(testblk2.settled == 1, "test block 2 settled"); + // assert only one block is added to the hex + assert.ok(MainHex.blocks[4].length == 0, "lane 4 empty") + assert.ok(MainHex.blocks[5].length == 1, "lane 5 has one block"); + }); From d82febb45075dea80382399eedf96589346181f7 Mon Sep 17 00:00:00 2001 From: Bo Date: Mon, 30 Nov 2015 20:41:54 -0800 Subject: [PATCH 22/34] more formal qunit tests for speeds. --- qunit.htm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/qunit.htm b/qunit.htm index d0f93f15b..093d19df0 100644 --- a/qunit.htm +++ b/qunit.htm @@ -106,13 +106,15 @@ togglespeed(-1, blocks, MainHex); // then // Assert speed of generation has changed - assert.equal(prevSpeed-0.1, window.speedscale); + assert.ok(prevSpeed-0.1 == window.speedscale, "speed lowered"); }); QUnit.test( "Speed up test, scenario 1.2", function( assert ) { initialize(1); // given window.gameState = 1; // game is starting + //game currently runs at 20% of original speed + window.speedscale = 0.2; var testblk1 = new Block(1, "#e74c3c", 8, -1, 1); var testblk2 = new Block(2, "#f1c40f", 8, -1, 1); var testblk3 = new Block(3, "#3498db", 8, -1, 0); @@ -124,16 +126,14 @@ window.blocks.push(testblk3); window.blocks.push(testblk4); - - //game currently runs at 20% of original speed - window.speedscale = 0.2; var prevSpeed = window.speedscale; // when togglespeed(-1, blocks, MainHex); // then - // Assert speed of generation has changed - assert.equal(prevSpeed, window.speedscale); + assert.ok(testblk1.iter = 8, "block1 iter constant"); + assert.ok(testblk2.iter = 8, "block2 iter constant"); + assert.ok(prevSpeed == window.speedscale, "speed constant"); }); QUnit.test( "Speed up test, scenario 1.3", function( assert ) { @@ -160,7 +160,7 @@ togglespeed(1, blocks, MainHex); // then // Assert that gamespeed is increased by 0.1, since it has not reached the limit of 1.4 yet - assert.equal(prevSpeed + 0.1, window.speedscale); + assert.ok(prevSpeed + 0.1 == window.speedscale, "speed increased"); }); QUnit.test( "Speed up test, scenario 1.4", function( assert ) { @@ -187,7 +187,7 @@ togglespeed(1, blocks, MainHex); // then // Assert speed of generation has not changed - assert.equal(prevSpeed, window.speedscale); + assert.ok(prevSpeed == window.speedscale, "speed same"); }); QUnit.test( "Block Drop Test, scenario 3.1", function( assert ) { From b351c466db45a8496e648981a0c4d7446c2008eb Mon Sep 17 00:00:00 2001 From: Bo Date: Mon, 30 Nov 2015 22:38:12 -0800 Subject: [PATCH 23/34] removed unnecessary code --- qunit.htm | 3 --- 1 file changed, 3 deletions(-) diff --git a/qunit.htm b/qunit.htm index 093d19df0..2dabea2ce 100644 --- a/qunit.htm +++ b/qunit.htm @@ -5,9 +5,6 @@ Hetrix Acceptance Tests - - From f386edab19dc7b29cf4a275d363449612776c3af Mon Sep 17 00:00:00 2001 From: Patrick Tee Date: Tue, 1 Dec 2015 01:13:09 -0800 Subject: [PATCH 24/34] Fixing toggleSpeed issues, qunit tests has to be modified accordingly --- js/input.js | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/js/input.js b/js/input.js index e43757588..14a6a4210 100644 --- a/js/input.js +++ b/js/input.js @@ -221,26 +221,52 @@ function togglecolor(blocks, hex){ function togglespeed(increment, blocks, hex){ + + //iterfactor is used to modify block falling speeds + var iterfactor = window.speedscale; + // check if we are incrementing or decrementing the game speed if (increment < 0){ // if incrementing, adjust the speed accordingly - if (window.speedscale >= 0.3){ - window.speedscale -= 0.1; + // if (window.speedscale >= 0.4){ + // window.speedscale -= 0.1; + + // } + + // MODIFIED: + // Instead of modifying window.speedscale, we modify difficulty to ensure block generations are normal + + if (waveone.nextGen.diffculty > 0){ + waveone.nextGen.difficulty -= 1; } + iterfactor -= 0.1; + + } else { // increment is positive // if decrementing, adjust the speed accordingly - if (window.speedscale < 1.4){ - window.speedscale += 0.1; + + // if (window.speedscale < 1.4){ + // window.speedscale += 0.1; + // } + + // MODIFIED: + // Instead of modifying window.speedscale, we modify difficulty to ensure block generations are normal + + if (waveone.nextGen.diffculty < 35){ + waveone.nextGen.difficulty += 3; } + + iterfactor += 0.1; } // slow down the generation of the wave speeds - waveone.nextGen = waveone.nextGen*(1/window.speedscale)/(1/window.oldspeedscale); - var iterfactor = window.speedscale / window.oldspeedscale; + // waveone.nextGen = waveone.nextGen*(1/window.speedscale)/(1/window.oldspeedscale); + // var iterfactor = window.speedscale / window.oldspeedscale; + - // slow down speed of falling blocks + // adjust speed of falling blocks for (var k = 0; k < blocks.length; k++){ blocks[k].iter = blocks[k].iter * iterfactor; } From 1c268465af04ba8cf19b8e0efaacd9de8bbf69c3 Mon Sep 17 00:00:00 2001 From: Bo Date: Tue, 1 Dec 2015 19:23:10 -0800 Subject: [PATCH 25/34] Revert "Fixing toggleSpeed issues, qunit tests has to be modified accordingly" This reverts commit f386edab19dc7b29cf4a275d363449612776c3af. --- js/input.js | 40 +++++++--------------------------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/js/input.js b/js/input.js index 14a6a4210..e43757588 100644 --- a/js/input.js +++ b/js/input.js @@ -221,52 +221,26 @@ function togglecolor(blocks, hex){ function togglespeed(increment, blocks, hex){ - - //iterfactor is used to modify block falling speeds - var iterfactor = window.speedscale; - // check if we are incrementing or decrementing the game speed if (increment < 0){ // if incrementing, adjust the speed accordingly - // if (window.speedscale >= 0.4){ - // window.speedscale -= 0.1; - - // } - - // MODIFIED: - // Instead of modifying window.speedscale, we modify difficulty to ensure block generations are normal - - if (waveone.nextGen.diffculty > 0){ - waveone.nextGen.difficulty -= 1; + if (window.speedscale >= 0.3){ + window.speedscale -= 0.1; } - iterfactor -= 0.1; - - } else { // increment is positive // if decrementing, adjust the speed accordingly - - // if (window.speedscale < 1.4){ - // window.speedscale += 0.1; - // } - - // MODIFIED: - // Instead of modifying window.speedscale, we modify difficulty to ensure block generations are normal - - if (waveone.nextGen.diffculty < 35){ - waveone.nextGen.difficulty += 3; + if (window.speedscale < 1.4){ + window.speedscale += 0.1; } - - iterfactor += 0.1; } // slow down the generation of the wave speeds - // waveone.nextGen = waveone.nextGen*(1/window.speedscale)/(1/window.oldspeedscale); - // var iterfactor = window.speedscale / window.oldspeedscale; - + waveone.nextGen = waveone.nextGen*(1/window.speedscale)/(1/window.oldspeedscale); + var iterfactor = window.speedscale / window.oldspeedscale; - // adjust speed of falling blocks + // slow down speed of falling blocks for (var k = 0; k < blocks.length; k++){ blocks[k].iter = blocks[k].iter * iterfactor; } From c52d4c0a2b0d39a1a7164d4004bf94c8fb10bb88 Mon Sep 17 00:00:00 2001 From: Bo Date: Tue, 1 Dec 2015 19:46:17 -0800 Subject: [PATCH 26/34] Fix issue that prevents game from becoming too slow --- js/input.js | 17 ++++++++++------- js/wavegen.js | 24 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/js/input.js b/js/input.js index e43757588..2ebc0be60 100644 --- a/js/input.js +++ b/js/input.js @@ -219,25 +219,29 @@ function togglecolor(blocks, hex){ } } -function togglespeed(increment, blocks, hex){ +function togglespeed(increment, blocks, hex) { // check if we are incrementing or decrementing the game speed - if (increment < 0){ + if (increment < 0) { // if incrementing, adjust the speed accordingly - if (window.speedscale >= 0.3){ + if (window.speedscale >= 0.3) { window.speedscale -= 0.1; } } else { // increment is positive // if decrementing, adjust the speed accordingly - if (window.speedscale < 1.4){ + if (window.speedscale < 1.4) { window.speedscale += 0.1; } } - // slow down the generation of the wave speeds - waveone.nextGen = waveone.nextGen*(1/window.speedscale)/(1/window.oldspeedscale); + console.log(window.speedscale); + + // slow down the generation of the wave , if necessary. + //if (window.speedscale <= 1){ + // waveone.nextGen = waveone.nextGen * (1 / window.speedscale) / (1 / window.oldspeedscale); + //} var iterfactor = window.speedscale / window.oldspeedscale; // slow down speed of falling blocks @@ -265,7 +269,6 @@ function toggleDrop(blocks, hex){ // extract only the closest block to the var minDist = 999999; for (var i = 0; i < blocks.length; i++){ - console.log(blocks[i].distFromHex); if (blocks[i].distFromHex < minDist){ minDist = blocks[i].distFromHex; } diff --git a/js/wavegen.js b/js/wavegen.js index c01b7b66e..57deaba01 100644 --- a/js/wavegen.js +++ b/js/wavegen.js @@ -1,17 +1,26 @@ function blockDestroyed() { // PRJ: all * window.speedscale - if (waveone.nextGen*window.speedscale > 1350) { + + var wavescalespeed; + if (window.speedscale <= 1.2){ + wavescalespeed = window.speedscale; + } + else { + wavescalespeed = 1; + } + + if (waveone.nextGen*wavescalespeed > 1350) { waveone.nextGen -= 30 * settings.creationSpeedModifier; - } else if (waveone.nextGen*window.speedscale > 600) { + } else if (waveone.nextGen*wavescalespeed > 600) { waveone.nextGen -= 8 * settings.creationSpeedModifier; } else { waveone.nextGen = 600; } // PRJ: this function scales down nextGen - if (window.speedscale > 0.001) { - waveone.nextGen = waveone.nextGen / window.speedscale; + if (wavescalespeed > 0.001) { + waveone.nextGen = waveone.nextGen / wavescalespeed; } if (waveone.difficulty < 35) { @@ -19,6 +28,12 @@ function blockDestroyed() { } else { waveone.difficulty = 35; } + + if (waveone.nextGen > 5000){ + waveone.nextGen = 5000; + } + console.log("genspeed"); + console.log(waveone.nextGen); } function waveGen(hex) { @@ -44,6 +59,7 @@ function waveGen(hex) { // PRJ this.nextGen = this.nextGen/window.speedscale; + console.log("nextgen"); console.log(this.nextGen); } }; From 346de82df745c2824587755a304e4f88c820a23e Mon Sep 17 00:00:00 2001 From: Bo Date: Tue, 1 Dec 2015 20:30:00 -0800 Subject: [PATCH 27/34] fixed issues so game isnt too fast/slow --- js/input.js | 14 +++++++++----- js/wavegen.js | 6 +++--- qunit.htm | 17 +++++++++++++++-- qunit2.htm | 24 ------------------------ 4 files changed, 27 insertions(+), 34 deletions(-) delete mode 100644 qunit2.htm diff --git a/js/input.js b/js/input.js index 2ebc0be60..fbe63e75f 100644 --- a/js/input.js +++ b/js/input.js @@ -236,12 +236,16 @@ function togglespeed(increment, blocks, hex) { } } - console.log(window.speedscale); - // slow down the generation of the wave , if necessary. - //if (window.speedscale <= 1){ - // waveone.nextGen = waveone.nextGen * (1 / window.speedscale) / (1 / window.oldspeedscale); - //} + if (window.speedscale <= 1){ + waveone.nextGen = waveone.nextGen * (1 / window.speedscale) / (1 / window.oldspeedscale); + } + + if (waveone.nextGen > 3500){ + waveone.nextGen = 3500; + } + + console.log(waveone.nextGen); var iterfactor = window.speedscale / window.oldspeedscale; // slow down speed of falling blocks diff --git a/js/wavegen.js b/js/wavegen.js index 57deaba01..14d566116 100644 --- a/js/wavegen.js +++ b/js/wavegen.js @@ -3,7 +3,7 @@ function blockDestroyed() { // PRJ: all * window.speedscale var wavescalespeed; - if (window.speedscale <= 1.2){ + if (window.speedscale <= 1.3){ wavescalespeed = window.speedscale; } else { @@ -29,8 +29,8 @@ function blockDestroyed() { waveone.difficulty = 35; } - if (waveone.nextGen > 5000){ - waveone.nextGen = 5000; + if (waveone.nextGen > 3500){ + waveone.nextGen = 3500; } console.log("genspeed"); console.log(waveone.nextGen); diff --git a/qunit.htm b/qunit.htm index 2dabea2ce..a6cb13fd7 100644 --- a/qunit.htm +++ b/qunit.htm @@ -104,6 +104,8 @@ // then // Assert speed of generation has changed assert.ok(prevSpeed-0.1 == window.speedscale, "speed lowered"); + assert.ok(testblk1.iter = 7.2, "block1 iter lower"); + assert.ok(testblk2.iter = 7.2, "block2 iter lower"); }); QUnit.test( "Speed up test, scenario 1.2", function( assert ) { @@ -112,6 +114,7 @@ window.gameState = 1; // game is starting //game currently runs at 20% of original speed window.speedscale = 0.2; + window.nextGen = 2500; var testblk1 = new Block(1, "#e74c3c", 8, -1, 1); var testblk2 = new Block(2, "#f1c40f", 8, -1, 1); var testblk3 = new Block(3, "#3498db", 8, -1, 0); @@ -124,19 +127,22 @@ window.blocks.push(testblk4); var prevSpeed = window.speedscale; + var prevGen = window.nextGen; // when togglespeed(-1, blocks, MainHex); // then + assert.ok(prevGen == window.nextGen, "gen speed constant"); + assert.ok(prevSpeed == window.speedscale, "speed constant"); assert.ok(testblk1.iter = 8, "block1 iter constant"); assert.ok(testblk2.iter = 8, "block2 iter constant"); - assert.ok(prevSpeed == window.speedscale, "speed constant"); }); QUnit.test( "Speed up test, scenario 1.3", function( assert ) { initialize(1); // given window.gameState = 1; // game is starting + window.nextGen = 2500; var testblk1 = new Block(1, "#e74c3c", 8, -1, 1); var testblk2 = new Block(2, "#f1c40f", 8, -1, 1); var testblk3 = new Block(3, "#3498db", 8, -1, 0); @@ -158,12 +164,16 @@ // then // Assert that gamespeed is increased by 0.1, since it has not reached the limit of 1.4 yet assert.ok(prevSpeed + 0.1 == window.speedscale, "speed increased"); + assert.ok(testblk1.iter = 8.8, "block1 iter increased"); + assert.ok(testblk2.iter = 8.8, "block2 iter increased"); + assert.ok(waveone.nextGen > 2500, "gen speed decreased"); }); QUnit.test( "Speed up test, scenario 1.4", function( assert ) { initialize(1); // given window.gameState = 1; // game is starting + window.nextGen = 2500; var testblk1 = new Block(1, "#e74c3c", 8, -1, 1); var testblk2 = new Block(2, "#f1c40f", 8, -1, 1); var testblk3 = new Block(3, "#3498db", 8, -1, 0); @@ -179,11 +189,14 @@ //game currently runs at 180% of original speed window.speedscale = 1.8; var prevSpeed = window.speedscale; - + var prevGen = window.nextGen; // when togglespeed(1, blocks, MainHex); // then // Assert speed of generation has not changed + assert.ok(prevGen == window.nextGen, "gen speed constant"); + assert.ok(testblk1.iter = 8, "block1 iter constant"); + assert.ok(testblk2.iter = 8, "block2 iter constant"); assert.ok(prevSpeed == window.speedscale, "speed same"); }); diff --git a/qunit2.htm b/qunit2.htm deleted file mode 100644 index cc4538467..000000000 --- a/qunit2.htm +++ /dev/null @@ -1,24 +0,0 @@ - - - - - Hetrix Acceptance Tests - - - - - - - - - -
-
- - \ No newline at end of file From 4c97cde0f56ec7e2621a34b594651dddfe0814cc Mon Sep 17 00:00:00 2001 From: Bo Date: Tue, 1 Dec 2015 20:53:56 -0800 Subject: [PATCH 28/34] removed unnecessary code --- js/input.js | 3 +-- js/wavegen.js | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/js/input.js b/js/input.js index fbe63e75f..c3e629cb4 100644 --- a/js/input.js +++ b/js/input.js @@ -244,8 +244,7 @@ function togglespeed(increment, blocks, hex) { if (waveone.nextGen > 3500){ waveone.nextGen = 3500; } - - console.log(waveone.nextGen); + var iterfactor = window.speedscale / window.oldspeedscale; // slow down speed of falling blocks diff --git a/js/wavegen.js b/js/wavegen.js index 14d566116..0ea7f6deb 100644 --- a/js/wavegen.js +++ b/js/wavegen.js @@ -32,8 +32,6 @@ function blockDestroyed() { if (waveone.nextGen > 3500){ waveone.nextGen = 3500; } - console.log("genspeed"); - console.log(waveone.nextGen); } function waveGen(hex) { @@ -59,8 +57,6 @@ function waveGen(hex) { // PRJ this.nextGen = this.nextGen/window.speedscale; - console.log("nextgen"); - console.log(this.nextGen); } }; From e7794977629d88e0260c47f07b9d439c979ce484 Mon Sep 17 00:00:00 2001 From: Bo Date: Wed, 2 Dec 2015 09:03:43 -0800 Subject: [PATCH 29/34] fixed issue for game running too fast --- js/input.js | 5 ++++- js/wavegen.js | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/js/input.js b/js/input.js index c3e629cb4..db3c88e5e 100644 --- a/js/input.js +++ b/js/input.js @@ -244,7 +244,10 @@ function togglespeed(increment, blocks, hex) { if (waveone.nextGen > 3500){ waveone.nextGen = 3500; } - + else if (waveone.nextGen < 400){ + waveone.nextGen = 400; + } + var iterfactor = window.speedscale / window.oldspeedscale; // slow down speed of falling blocks diff --git a/js/wavegen.js b/js/wavegen.js index 0ea7f6deb..57c3224a9 100644 --- a/js/wavegen.js +++ b/js/wavegen.js @@ -32,6 +32,9 @@ function blockDestroyed() { if (waveone.nextGen > 3500){ waveone.nextGen = 3500; } + else if (waveone.nextGen < 400){ + waveone.nextGen = 400; + } } function waveGen(hex) { From 2dd1de72601a9385f0ca227bc81a1b96e8d4e014 Mon Sep 17 00:00:00 2001 From: Patrick Tee Date: Wed, 2 Dec 2015 10:03:40 -0800 Subject: [PATCH 30/34] Edit to toggleSpeed wavegen --- js/input.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/input.js b/js/input.js index db3c88e5e..1b027f24a 100644 --- a/js/input.js +++ b/js/input.js @@ -237,16 +237,16 @@ function togglespeed(increment, blocks, hex) { } // slow down the generation of the wave , if necessary. - if (window.speedscale <= 1){ + if (window.speedscale >= 1){ waveone.nextGen = waveone.nextGen * (1 / window.speedscale) / (1 / window.oldspeedscale); } if (waveone.nextGen > 3500){ waveone.nextGen = 3500; } - else if (waveone.nextGen < 400){ - waveone.nextGen = 400; - } + // else if (waveone.nextGen < 400){ + // waveone.nextGen = 400; + // } var iterfactor = window.speedscale / window.oldspeedscale; From e43d6d32b77a529efb1841b2b055a1a7307f6c05 Mon Sep 17 00:00:00 2001 From: Bo Date: Wed, 2 Dec 2015 11:12:19 -0800 Subject: [PATCH 31/34] remove unnecessary comments --- js/input.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/js/input.js b/js/input.js index 1b027f24a..f153e0e65 100644 --- a/js/input.js +++ b/js/input.js @@ -244,10 +244,7 @@ function togglespeed(increment, blocks, hex) { if (waveone.nextGen > 3500){ waveone.nextGen = 3500; } - // else if (waveone.nextGen < 400){ - // waveone.nextGen = 400; - // } - + var iterfactor = window.speedscale / window.oldspeedscale; // slow down speed of falling blocks From 761d802c8040be473665a4f596993504cbb90480 Mon Sep 17 00:00:00 2001 From: Bo Date: Wed, 2 Dec 2015 22:10:38 -0800 Subject: [PATCH 32/34] Fixed qunit tests --- qunit.htm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qunit.htm b/qunit.htm index a6cb13fd7..259d12f58 100644 --- a/qunit.htm +++ b/qunit.htm @@ -106,6 +106,8 @@ assert.ok(prevSpeed-0.1 == window.speedscale, "speed lowered"); assert.ok(testblk1.iter = 7.2, "block1 iter lower"); assert.ok(testblk2.iter = 7.2, "block2 iter lower"); + assert.ok(waveone.nextGen > 2500, "gen interval increased"); + }); QUnit.test( "Speed up test, scenario 1.2", function( assert ) { @@ -166,7 +168,7 @@ assert.ok(prevSpeed + 0.1 == window.speedscale, "speed increased"); assert.ok(testblk1.iter = 8.8, "block1 iter increased"); assert.ok(testblk2.iter = 8.8, "block2 iter increased"); - assert.ok(waveone.nextGen > 2500, "gen speed decreased"); + assert.ok(waveone.nextGen < 2500, "gen interval decreased"); }); QUnit.test( "Speed up test, scenario 1.4", function( assert ) { From d2ad50aa5ecee8454b53665025fa2a3a73afbd5e Mon Sep 17 00:00:00 2001 From: Patrick Tee Date: Sat, 5 Dec 2015 18:19:42 -0800 Subject: [PATCH 33/34] Added readme.txt explaining the team's contributions and implementations to Hextris --- team06_readme.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 team06_readme.txt diff --git a/team06_readme.txt b/team06_readme.txt new file mode 100644 index 000000000..88d5f243b --- /dev/null +++ b/team06_readme.txt @@ -0,0 +1,16 @@ +Team 06 Open-source Project + +Project Objective: +The team wants to resolve the issue of adding red/green colorblind-friendly colors and the issue of allowing more game-speed control. +The team also wants to add the instant block-drop feature as inspired by the original Tetris game. + +List of Implementations: +Implementation 1: toggleColor function + files: js/input.js, js/main.js + +Implementation 2: toggleSpeed function + files: js/input.js + +Implementation 3: toggleDrop function + files: js/input.js + From 14de33c5a415d563911a052dca85736ad4d75758 Mon Sep 17 00:00:00 2001 From: bohuce Date: Sat, 5 Dec 2015 20:18:43 -0800 Subject: [PATCH 34/34] Update team06_readme.txt --- team06_readme.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/team06_readme.txt b/team06_readme.txt index 88d5f243b..8dec5a28d 100644 --- a/team06_readme.txt +++ b/team06_readme.txt @@ -9,8 +9,11 @@ Implementation 1: toggleColor function files: js/input.js, js/main.js Implementation 2: toggleSpeed function - files: js/input.js + files: js/input.js, js/wavegen.js Implementation 3: toggleDrop function files: js/input.js + +Unit Tests: using qUnit Libary + files: qunit.htm, js/Hex_test.js, js/Block_test.js, js/initialization_test.js