From 218e866079542791bac01f978921b70410f54b75 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Sun, 14 Dec 2014 08:51:19 -0600 Subject: [PATCH] Added difficulty option, score-keeping, and better levels. --- snake/snake-levels.js | 278 ++++++++++++++++++++++++++++++++++++++ snake/snake-redesign.html | 49 ++++--- snake/snake.js | 70 +++++----- snake/snake.scss | 131 ++++-------------- 4 files changed, 365 insertions(+), 163 deletions(-) create mode 100644 snake/snake-levels.js diff --git a/snake/snake-levels.js b/snake/snake-levels.js new file mode 100644 index 0000000..c7cd20f --- /dev/null +++ b/snake/snake-levels.js @@ -0,0 +1,278 @@ +(function(){ + + var small = { "boardSize": "standard", levels: [] }; + var mazes = { "boardSize": "standard", levels: [] }; + var large = { "boardSize": "large", levels: [] }; + var nibbles = { "boardSize": "large", levels: [] }; + + + // Level 1: Hello Snake! + small.push({ + "name": "Hello Snake!", "rows":10, "cols":10, + "easy": { "fps": 2, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "medium": { "fps": 4, "targetScore": 7, "growthFactor": 2, "growthFactorIncrease": 1}, + "hard": { "fps": 8, "targetScore": 8, "growthFactor": 2, "growthFactorIncrease": 1}, + "insane": { "fps": 12, "targetScore": 10, "growthFactor": 2, "growthFactorIncrease": 1}, + "board":[ + 1,1,1,1,1,1,1,1,1,1, + 1,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,1, + 1,0,0,0,2,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,1, + 1,1,1,1,1,1,1,1,1,1]}); + + // Level 2: Room to Grow + small.push({ + "name": "Room to Grow", "rows":16, "cols":16, + "easy": { "fps":3, "targetScore": 7, "growthFactor": 2, "growthFactorIncrease": 1}, + "medium": { "fps":3, "targetScore": 7, "growthFactor": 2, "growthFactorIncrease": 1}, + "hard": { "fps":3, "targetScore": 7, "growthFactor": 2, "growthFactorIncrease": 1}, + "insane": { "fps":3, "targetScore": 7, "growthFactor": 2, "growthFactorIncrease": 1}, + "board":[ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,2,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}); + + // Level 3: North and South + small.push({ + "name": "North and South", "rows":15, "cols":15, + "easy": { "fps":3, "targetScore": 6, "growthFactor": 2, "growthFactorIncrease": 1}, + "medium": { "fps":3, "targetScore": 6, "growthFactor": 2, "growthFactorIncrease": 1}, + "hard": { "fps":3, "targetScore": 6, "growthFactor": 2, "growthFactorIncrease": 1}, + "insane": { "fps":3, "targetScore": 6, "growthFactor": 2, "growthFactorIncrease": 1}, + "board":[ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,2,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,1,1,1,1,1,1,1,1,1,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}); + + // Level 4: Four Small Rooms + small.push({ + "name": "Four Small Rooms","rows":15,"cols":15, + "easy": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "medium": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "hard": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "insane": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "board": [ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,0,2,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,1,1,1,0,1,1,1,1,1,1,1,0,1,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}); + + // Level 5: Polka Dots + small.push({ + "name": "Polka Dots" ,"rows":15,"cols":15, + "easy": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "medium": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "hard": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "insane": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "board":[ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,0,0,0,1,0,0,0,1,0,0,0,1,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,1,0,0,0,1,0,0,0,1,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,0,0,0,1,0,0,0,1,0,0,0,1,1, + 1,0,0,0,0,2,0,0,0,0,0,0,0,0,1, + 1,0,0,1,0,0,0,1,0,0,0,1,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,0,0,0,1,0,0,0,1,0,0,0,1,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,1,0,3,0,1,0,0,0,1,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,0,0,0,1,0,0,0,1,0,0,0,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}); + + // Level 6: Toaster Face + small.push({ + "name": "Toaster Face","rows":15,"cols":15, + "easy": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "medium": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "hard": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "insane": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "board":[ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,0,0,0,0,0,1,0,0,0,0,0,1,1, + 1,0,0,1,0,1,0,0,0,1,0,1,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,1,0,0,1,0,0,0,0,0,1,0,0,1,1, + 1,0,0,1,1,1,1,1,1,1,1,1,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,1,0,0,1,2,0,0,0,0,1,0,0,1,1, + 1,0,0,1,1,1,0,0,0,1,1,1,0,0,1, + 1,0,0,0,1,0,0,0,0,0,1,0,0,0,1, + 1,1,0,0,0,0,0,1,0,0,0,0,0,1,1, + 1,0,0,1,0,1,1,1,1,1,0,1,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,0,0,1,0,0,1,0,0,1,0,0,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}); + + // Level 7: Wierd Walls + small.push({ + "name": "Wierd Walls","rows":15,"cols":15, + "easy": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "medium": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "hard": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "insane": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "board":[ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,0,2,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,1,0,0,0,1,1,1,1,1,1,1,0,1, + 1,0,1,0,1,0,0,0,0,0,0,0,0,0,1, + 1,0,1,0,1,0,1,0,0,0,1,1,1,0,1, + 1,0,1,0,1,0,1,0,1,0,0,0,0,0,1, + 1,0,1,0,1,0,1,0,1,0,1,0,0,0,1, + 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, + 1,0,0,0,1,0,1,0,1,0,1,0,1,0,1, + 1,0,0,0,0,0,1,0,1,0,1,0,1,0,1, + 1,0,1,1,1,0,0,0,1,0,1,0,1,0,1, + 1,0,0,0,0,0,0,0,0,0,1,0,1,0,1, + 1,0,1,1,1,1,1,1,1,0,0,0,1,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}); + + // Level 8: Feast and Famine + small.push({ + "name": "Feast and Famine","rows":15,"cols":15, + "easy": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "medium": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "hard": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "insane": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "board":[ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,2,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1,0,3,0,3,0,3,1, + 1,0,0,0,0,0,0,1,0,0,3,0,3,0,1, + 1,0,0,0,0,0,0,1,0,3,0,3,0,3,1, + 1,0,0,0,0,0,0,1,0,0,3,0,3,0,1, + 1,0,0,0,0,0,0,0,0,3,0,3,0,3,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}); + + // Level 1: Maze 1 + mazes.push({ + "name": "Maze 1","rows":15,"cols":15, + "easy": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "medium": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "hard": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "insane": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "board":[ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1, + 1,0,1,1,1,1,0,1,0,1,1,0,1,0,1, + 1,0,0,0,0,0,0,1,0,0,0,0,1,0,1, + 1,0,1,1,0,1,1,1,1,1,0,1,1,0,1, + 1,0,1,2,0,0,0,0,0,0,0,0,1,0,1, + 1,0,1,0,1,1,1,0,1,1,1,0,1,0,1, + 1,0,1,0,0,1,0,0,0,0,1,0,0,0,1, + 1,0,1,1,0,1,0,1,1,0,0,0,1,0,1, + 1,0,0,0,0,0,0,1,1,0,1,0,0,0,1, + 1,0,1,1,1,1,0,0,0,0,0,0,0,1,1, + 1,0,0,0,0,0,0,1,1,1,1,1,0,0,1, + 1,0,1,1,1,0,1,1,0,0,0,1,1,0,1, + 1,0,0,0,0,0,0,0,0,1,0,0,0,0,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}); + + // Level 2: Spiral + mazes.push({ + "name": "Spiral","rows":15,"cols":15, + "easy": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "medium": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "hard": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "insane": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "board":[ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,2,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,1,1,1,1,1,1,1,1,1,1,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,1,0,0,1, + 1,0,1,1,1,1,1,1,1,1,0,1,0,0,1, + 1,0,1,0,0,0,0,0,0,1,0,1,0,0,1, + 1,0,1,0,1,1,1,1,0,1,0,1,0,0,1, + 1,0,1,0,1,3,0,1,0,1,0,1,0,0,1, + 1,0,1,0,1,0,0,0,0,1,0,1,0,0,1, + 1,0,1,0,1,0,0,0,0,0,0,1,0,0,1, + 1,0,1,0,1,1,1,1,1,1,1,1,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,1,1,1,1,1,1,1,1,1,1,1,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}); + + + // Level 3: Maze 2 + mazes.push({ + "name": "Maze 2","rows":17,"cols":17, + "easy": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "medium": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "hard": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "insane": { "fps":3, "targetScore": 5, "growthFactor": 2, "growthFactorIncrease": 1}, + "board":[ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1, + 1,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1, + 1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1, + 1,0,1,0,0,1,1,0,1,1,1,0,1,1,1,0,1, + 1,0,1,1,0,1,1,0,0,0,1,0,0,1,0,0,1, + 1,0,1,0,0,0,1,1,1,0,0,1,0,1,0,1,1, + 1,0,0,0,1,0,0,1,1,1,0,0,0,1,0,0,1, + 1,0,1,0,0,1,0,0,0,0,1,1,1,1,1,0,1, + 1,0,0,1,0,0,0,1,1,0,1,0,0,0,0,0,1, + 1,1,0,1,1,1,1,1,1,0,1,0,1,1,1,1,1, + 1,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,1, + 1,0,1,1,1,1,0,0,0,0,1,1,1,1,1,0,1, + 1,0,1,0,0,0,1,1,1,1,0,0,0,1,0,0,1, + 1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]} + ]); + + window.SnakeLevels = { + "Small Rooms": small, + "Large Rooms": large, + "Classic Nibbles": nibbles, + "Mazes": mazes } +})(); diff --git a/snake/snake-redesign.html b/snake/snake-redesign.html index 0aaac85..289138c 100644 --- a/snake/snake-redesign.html +++ b/snake/snake-redesign.html @@ -2,9 +2,10 @@ - + +
@@ -70,6 +71,10 @@ +
+

Score

@@ -88,39 +93,31 @@