Look I can OO.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 30 Apr 2013 11:04:34 +0000 (13:04 +0200)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 30 Apr 2013 11:04:34 +0000 (13:04 +0200)
game.js

diff --git a/game.js b/game.js
index 27a89ab78441c71d9ffbe7d1888133ae62107681..ac5b69f80d0ad3cc9d313bec457f800c2d34c37d 100644 (file)
--- a/game.js
+++ b/game.js
@@ -34,7 +34,7 @@ var state = LEVEL_SELECT;
 \r
 var max_level = 1;\r
 var current_level = 1;\r
-var count = 0;\r
+var current_level_inst = null;\r
 \r
 function QueueChange(bead, sound) {\r
     if (sound == null)\r
@@ -70,83 +70,86 @@ function CheckExact(pos) {
     return true;\r
 };\r
 \r
-function FollowMeStart(x, y) {\r
-    count = 0;\r
+function FollowMe () {\r
+    var count = 0;\r
     PS.BeadColor(PS.Random(3) - 1, PS.Random(3) - 1, PS.COLOR_BLACK);\r
-};\r
 \r
-function FollowMePress(x, y) {\r
-    if (PS.BeadColor(x, y) == PS.COLOR_BLACK) {\r
-        PS.BeadColor(x, y, PS.COLOR_WHITE);\r
-        count++;\r
-        if (count >= 4) {\r
-            Win();\r
+    this.Press = function (x, y) {\r
+        if (PS.BeadColor(x, y) == PS.COLOR_BLACK) {\r
+            PS.BeadColor(x, y, PS.COLOR_WHITE);\r
+            count++;\r
+            if (count >= 4) {\r
+                Win();\r
+            } else {\r
+                PS.BeadColor(PS.Random(3) - 1, PS.Random(3) - 1,\r
+                             PS.COLOR_BLACK);\r
+                PS.AudioPlay(PS.Xylophone(count == 3 ? 14 : 13), 0.5);\r
+            }\r
         } else {\r
-            PS.BeadColor(PS.Random(3) - 1, PS.Random(3) - 1, PS.COLOR_BLACK);\r
-            PS.AudioPlay(PS.Xylophone(count == 3 ? 14 : 13), 0.5);\r
+            Mistake();\r
+            count = 0;\r
         }\r
-    } else {\r
-        Mistake();\r
-        count = 0;\r
-    }\r
-};\r
-\r
-function EnumerateStart() {\r
+    };\r
 };\r
 \r
-function EnumeratePress(x, y) {\r
-    for (var n = 1; n < LEVEL_IDX[y][x]; ++n) {\r
-        if (PS.BeadColor(LEVEL_POS[n][0], LEVEL_POS[n][1]) != PS.COLOR_BLACK) {\r
+function Enumerate () {\r
+    this.Press = function (x, y) {\r
+        for (var n = 1; n < LEVEL_IDX[y][x]; ++n) {\r
+            if (PS.BeadColor(LEVEL_POS[n][0], LEVEL_POS[n][1])\r
+                != PS.COLOR_BLACK) {\r
+                Mistake();\r
+                return;\r
+            }\r
+        }\r
+        if (PS.BeadColor(x, y) == PS.COLOR_BLACK) {\r
             Mistake();\r
-            return;\r
+        } else {\r
+            PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+            if (LEVEL_IDX[y][x] == 9)\r
+                Win();\r
+            else if (LEVEL_IDX[y][x] == 3)\r
+                PS.AudioPlay(PS.Xylophone(15), 0.5);\r
+            else if (LEVEL_IDX[y][x] == 6)\r
+                PS.AudioPlay(PS.Xylophone(16), 0.5);\r
+            else if (LEVEL_IDX[y][x] > 6)\r
+                PS.AudioPlay(PS.Xylophone(15), 0.5);\r
+            else if (LEVEL_IDX[y][x] > 3)\r
+                PS.AudioPlay(PS.Xylophone(14), 0.5);\r
+            else\r
+                PS.AudioPlay(PS.Xylophone(13), 0.5);\r
         }\r
-    }\r
-    if (PS.BeadColor(x, y) == PS.COLOR_BLACK) {\r
-        Mistake();\r
-    } else {\r
-        PS.BeadColor(x, y, PS.COLOR_BLACK);\r
-        if (LEVEL_IDX[y][x] == 9)\r
-            Win();\r
-        else if (LEVEL_IDX[y][x] == 3)\r
-            PS.AudioPlay(PS.Xylophone(15), 0.5);\r
-        else if (LEVEL_IDX[y][x] == 6)\r
-            PS.AudioPlay(PS.Xylophone(16), 0.5);\r
-        else if (LEVEL_IDX[y][x] > 6)\r
-            PS.AudioPlay(PS.Xylophone(15), 0.5);\r
-        else if (LEVEL_IDX[y][x] > 3)\r
-            PS.AudioPlay(PS.Xylophone(14), 0.5);\r
-        else\r
-            PS.AudioPlay(PS.Xylophone(13), 0.5);\r
-    }\r
+    };\r
 };\r
 \r
-var repeatorder = [];\r
-function RepeatStart() {\r
+function Repeat() {\r
+    var repeatorder = Shuffle([1, 2, 3, 4, 5, 6, 7, 8, 9]).slice(0, 6);\r
     PS.Clock(45);\r
-    repeatorder = Shuffle([1, 2, 3, 4, 5, 6, 7, 8, 9]).slice(0, 6);\r
     for (var n = 0; n < repeatorder.length; ++n) {\r
         QueueChange([[PS.COLOR_BLACK, repeatorder[n]]],\r
-                   [PS.Xylophone(2 + n)]);\r
-    }\r
-};\r
+                    [PS.Xylophone(2 + n)]);\r
+\r
+        this.Press = function Press (x, y) {\r
+            var n = repeatorder.shift();\r
+            if (LEVEL_IDX[y][x] == n) {\r
+                PS.BeadColor(x, y, PS.COLOR_GREEN);\r
+                if (repeatorder.length == 0) {\r
+                    Win();\r
+                } else {\r
+                    PS.AudioPlay(PS.Xylophone(9 + repeatorder.length), 0.5);\r
+                    PS.AudioPlay(PS.Xylophone(9 + repeatorder.length), 0.5);\r
+                }\r
+            } else {\r
+                Mistake();\r
+            }\r
+        };\r
+    };\r
+};\r
+\r
+function TickMissing() {\r
+    var repeatorder;\r
+    var missing_valid;\r
+    var count = 0;\r
 \r
-function RepeatPress(x, y) {\r
-    var n = repeatorder.shift();\r
-    if (LEVEL_IDX[y][x] == n) {\r
-        PS.BeadColor(x, y, PS.COLOR_GREEN);\r
-        if (repeatorder.length == 0) {\r
-            Win();\r
-        } else {\r
-            PS.AudioPlay(PS.Xylophone(9 + repeatorder.length), 0.5);\r
-            PS.AudioPlay(PS.Xylophone(9 + repeatorder.length), 0.5);\r
-        }\r
-    } else {\r
-        Mistake();\r
-    }\r
-};\r
-\r
-var missing_valid = [];\r
-function TickMissingStart() {\r
     PS.Clock(45);\r
     var d = {};\r
     missing_valid = [];\r
@@ -162,107 +165,106 @@ function TickMissingStart() {
                         [PS.Xylophone(13 + n)]);\r
         }\r
     }\r
+\r
     for (var n = 1; n <= 9; ++n)\r
         if (repeatorder.indexOf(n) < 0)\r
             missing_valid.push(n);\r
-    count = 0;\r
-};\r
 \r
-function TickMissingPress(x, y) {\r
-    if (missing_valid.indexOf(LEVEL_IDX[y][x]) < 0) {\r
-        Mistake();\r
-    } else {\r
-        PS.BeadColor(x, y, PS.COLOR_BLACK);\r
-        if (CheckExact(missing_valid)) {\r
-            Win();\r
+    this.Press = function (x, y) {\r
+        if (missing_valid.indexOf(LEVEL_IDX[y][x]) < 0) {\r
+            Mistake();\r
         } else {\r
-            count++;\r
-            PS.AudioPlay(PS.Xylophone(count == 2 ? 14 : 13), 0.5);\r
+            PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+            if (CheckExact(missing_valid)) {\r
+                Win();\r
+            } else {\r
+                count++;\r
+                PS.AudioPlay(PS.Xylophone(count == 2 ? 14 : 13), 0.5);\r
+            }\r
         }\r
-    }\r
+    };\r
 };\r
 \r
-var third_row;\r
-\r
-function ThreeRowGenerate() {\r
-    third_row = Shuffle(Choose([\r
-        [1, 2, 3], [4, 5, 6], [7, 8, 9],\r
-        [1, 4, 7], [2, 5, 8], [3, 6, 9],\r
-        [1, 5, 9], [3, 5, 7]]));\r
-    QueueChange([[PS.COLOR_BLACK, third_row[0]]], [PS.Xylophone(13)]);\r
-    QueueChange([[PS.COLOR_BLACK, third_row[1]]], [PS.Xylophone(13)]);\r
-}\r
-\r
-function ThreeRowStart() {\r
-    count = 0;\r
+function ThreeRow () {\r
+    var third_row;\r
+    var count = 0;\r
     PS.Clock(45);\r
-    ThreeRowGenerate();\r
-};\r
-\r
-function ThreeRowPress(x, y) {\r
-    if (LEVEL_IDX[y][x] == third_row[2]) {\r
-        count++;\r
-        PS.BeadColor(x, y, PS.COLOR_BLACK);\r
-        PS.Clock(PS.Clock());\r
-        if (count >= 3) {\r
-            Win();\r
+    Generate();\r
+    \r
+    function Generate() {\r
+        third_row = Shuffle(Choose([\r
+            [1, 2, 3], [4, 5, 6], [7, 8, 9],\r
+            [1, 4, 7], [2, 5, 8], [3, 6, 9],\r
+            [1, 5, 9], [3, 5, 7]]));\r
+        QueueChange([[PS.COLOR_BLACK, third_row[0]]], [PS.Xylophone(13)]);\r
+        QueueChange([[PS.COLOR_BLACK, third_row[1]]], [PS.Xylophone(13)]);\r
+    };\r
+\r
+    this.Press = function (x, y) {\r
+        if (LEVEL_IDX[y][x] == third_row[2]) {\r
+            count++;\r
+            PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+            PS.Clock(PS.Clock());\r
+            if (count >= 3) {\r
+                Win();\r
+            } else {\r
+                PS.AudioPlay(PS.Xylophone(14), 0.5);\r
+                QueueChange([[PS.COLOR_GREEN, third_row[2]],\r
+                             [PS.COLOR_GREEN, third_row[1]],\r
+                             [PS.COLOR_GREEN, third_row[0]]],\r
+                            [PS.Xylophone(34)]);\r
+                QueueChange([[PS.COLOR_WHITE, third_row[2]],\r
+                             [PS.COLOR_WHITE, third_row[1]],\r
+                             [PS.COLOR_WHITE, third_row[0]]]);\r
+                Generate();\r
+            }\r
         } else {\r
-            PS.AudioPlay(PS.Xylophone(14), 0.5);\r
-            QueueChange([[PS.COLOR_GREEN, third_row[2]],\r
-                         [PS.COLOR_GREEN, third_row[1]],\r
-                         [PS.COLOR_GREEN, third_row[0]]],\r
-                        [PS.Xylophone(34)]);\r
-            QueueChange([[PS.COLOR_WHITE, third_row[2]],\r
-                         [PS.COLOR_WHITE, third_row[1]],\r
-                         [PS.COLOR_WHITE, third_row[0]]]);\r
-            ThreeRowGenerate();\r
+            count = 0;\r
+            Mistake();\r
         }\r
-    } else {\r
-        count = 0;\r
-        Mistake();\r
-    }\r
-};\r
-\r
-var sudoku_row;\r
-function SudokuRowGenerate() {\r
-    sudoku_row = Shuffle(Choose([[1, 8, 6], [4, 8, 3], [4, 2, 9], [7, 2, 6]]));\r
-    QueueChange([[PS.COLOR_RED, sudoku_row[0]]],\r
-                [PS.Xylophone(3)]);\r
-    QueueChange([[PS.COLOR_RED, sudoku_row[1]]],\r
-                [PS.Xylophone(2)]);\r
+    };\r
 };\r
 \r
-function SudokuStart() {\r
-    count = 0;\r
+function SudokuRow () {\r
+    var sudoku_row;\r
+    var count = 0;\r
     PS.Clock(45);\r
-    SudokuRowGenerate();\r
-}\r
-\r
-function SudokuPress(x, y) {\r
-    if (LEVEL_IDX[y][x] == sudoku_row[2]) {\r
-        count++;\r
-        PS.BeadColor(x, y, PS.COLOR_BLACK);\r
-        if (count >= 3) {\r
-            Win();\r
+    Generate();\r
+\r
+    function Generate() {\r
+        sudoku_row = Shuffle(\r
+            Choose([[1, 8, 6], [4, 8, 3], [4, 2, 9], [7, 2, 6]]));\r
+        QueueChange([[PS.COLOR_RED, sudoku_row[0]]],\r
+                    [PS.Xylophone(3)]);\r
+        QueueChange([[PS.COLOR_RED, sudoku_row[1]]],\r
+                    [PS.Xylophone(2)]);\r
+    };\r
+\r
+    this.Press = function (x, y) {\r
+        if (LEVEL_IDX[y][x] == sudoku_row[2]) {\r
+            count++;\r
+            PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+            if (count >= 3) {\r
+                Win();\r
+            } else {\r
+                PS.AudioPlay(PS.Xylophone(13), 0.5);\r
+                QueueChange([[PS.COLOR_GREEN, sudoku_row[2]],\r
+                             [PS.COLOR_GREEN, sudoku_row[1]],\r
+                             [PS.COLOR_GREEN, sudoku_row[0]]],\r
+                            [PS.Xylophone(14)]);\r
+                QueueChange([[PS.COLOR_WHITE, sudoku_row[2]],\r
+                             [PS.COLOR_WHITE, sudoku_row[1]],\r
+                             [PS.COLOR_WHITE, sudoku_row[0]]]);\r
+                Generate();\r
+            }\r
         } else {\r
-            PS.AudioPlay(PS.Xylophone(13), 0.5);\r
-            QueueChange([[PS.COLOR_GREEN, sudoku_row[2]],\r
-                         [PS.COLOR_GREEN, sudoku_row[1]],\r
-                         [PS.COLOR_GREEN, sudoku_row[0]]],\r
-                        [PS.Xylophone(14)]);\r
-            QueueChange([[PS.COLOR_WHITE, sudoku_row[2]],\r
-                         [PS.COLOR_WHITE, sudoku_row[1]],\r
-                         [PS.COLOR_WHITE, sudoku_row[0]]]);\r
-            SudokuRowGenerate();\r
+            count = 0;\r
+            Mistake();\r
         }\r
-    } else {\r
-        count = 0;\r
-        Mistake();\r
-    }\r
+    };\r
 };\r
 \r
-function DigitsStart() {\r
-    PS.Clock(40);\r
+function Digits () {\r
     QueueChange([[PS.COLOR_BLACK, 1]], ["perc_hihat_closed"]);\r
     QueueChange([[PS.COLOR_WHITE, 1],\r
                  [PS.COLOR_BLACK, 4]], ["perc_hihat_closed"]);\r
@@ -281,33 +283,32 @@ function DigitsStart() {
     QueueChange([[PS.COLOR_WHITE, 2],\r
                  [PS.COLOR_WHITE, 5],\r
                  [PS.COLOR_WHITE, 8]]);\r
-    count = 4;\r
-};\r
+    var count = 4;\r
 \r
-function DigitsPress(x, y) {\r
-    if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
-        PS.BeadColor(x, y, PS.COLOR_BLACK);\r
-    } else {\r
-        PS.BeadColor(x, y, PS.COLOR_WHITE);\r
-    }\r
-\r
-    if (count == 4 && ApproveIfExact([7, 9, 4, 5, 6, 3]))\r
-        count = 7;\r
-    if (count == 7 && (CheckExact([7, 8, 9, 6, 3])\r
-                       || CheckExact([7, 8, 9, 6, 2]))) {\r
-        Win();\r
-        return;\r
-    }\r
+    this.Press = function (x, y) {\r
+        if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
+            PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+        } else {\r
+            PS.BeadColor(x, y, PS.COLOR_WHITE);\r
+        }\r
 \r
-    if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
-        PS.AudioPlay(PS.Xylophone(10), 0.5);\r
-    } else {\r
-        PS.AudioPlay(PS.Xylophone(13), 0.3);\r
-    }\r
+        if (count == 4 && ApproveIfExact([7, 9, 4, 5, 6, 3]))\r
+            count = 7;\r
+        if (count == 7 && (CheckExact([7, 8, 9, 6, 3])\r
+                           || CheckExact([7, 8, 9, 6, 2]))) {\r
+            Win();\r
+            return;\r
+        }\r
 \r
+        if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
+            PS.AudioPlay(PS.Xylophone(10), 0.5);\r
+        } else {\r
+            PS.AudioPlay(PS.Xylophone(13), 0.3);\r
+        }\r
+    };\r
 };\r
 \r
-function ShapesStart() {\r
+function Shapes() {\r
     PS.Clock(40);\r
     QueueChange([[PS.COLOR_BLACK, 1]], [PS.Xylophone(13)]);\r
     QueueChange([[PS.COLOR_GREEN, 1]], [PS.Xylophone(14)]);\r
@@ -322,45 +323,32 @@ function ShapesStart() {
     QueueChange([[PS.COLOR_BLACK, 1],\r
                  [PS.COLOR_BLACK, 4],\r
                  [PS.COLOR_BLACK, 7]]);\r
-    count = 3;\r
-};\r
+    var count = 3;\r
 \r
-function ShapesPress(x, y) {\r
-    if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
-        PS.BeadColor(x, y, PS.COLOR_BLACK);\r
-    } else {\r
-        PS.BeadColor(x, y, PS.COLOR_WHITE);\r
-    }\r
-\r
-    if (count == 3 && (ApproveIfExact([1, 4, 7, 2, 5, 3], PS.COLOR_BLACK)\r
-                       || ApproveIfExact([1, 4, 7, 8, 5, 3], PS.COLOR_BLACK))) {\r
-        count = 4;\r
-        if (PS.BeadColor(x, y) == PS.COLOR_WHITE)\r
-            PS.AudioPlay(PS.Xylophone(10), 0.3);\r
-        else\r
-            PS.AudioPlay(PS.Xylophone(13), 0.5);\r
-    } else if (count == 4 && CheckExact([1, 2, 3, 4, 5, 6, 7, 8, 9]))\r
-        Win();\r
-    else {\r
-        if (PS.BeadColor(x, y) == PS.COLOR_WHITE)\r
-            PS.AudioPlay(PS.Xylophone(10), 0.3);\r
-        else\r
-            PS.AudioPlay(PS.Xylophone(13), 0.5);\r
-    }\r
-};\r
+    this.Press = function (x, y) {\r
+        if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
+            PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+        } else {\r
+            PS.BeadColor(x, y, PS.COLOR_WHITE);\r
+        }\r
 \r
-function DieStart() {\r
-    PS.Clock(40);\r
-    QueueChange([[PS.COLOR_BLACK, 5]], [PS.Xylophone(13)]);\r
-    QueueChange([[PS.COLOR_GREEN, 5]], [PS.Xylophone(14)]);\r
-    QueueChange([[PS.COLOR_WHITE, 5]]);\r
-    QueueChange([[PS.COLOR_BLACK, 1]], [PS.Xylophone(13)]);\r
-    QueueChange([[PS.COLOR_BLACK, 9]], [PS.Xylophone(13)]);\r
-    QueueChange([[PS.COLOR_GREEN, 1],\r
-                 [PS.COLOR_GREEN, 9]], [PS.Xylophone(14)]);\r
-    QueueChange([[PS.COLOR_WHITE, 1],\r
-                 [PS.COLOR_WHITE, 9]]);\r
-    count = 3;\r
+        if (count == 3\r
+            && (ApproveIfExact([1, 4, 7, 2, 5, 3], PS.COLOR_BLACK)\r
+                || ApproveIfExact([1, 4, 7, 8, 5, 3], PS.COLOR_BLACK))) {\r
+            count = 4;\r
+            if (PS.BeadColor(x, y) == PS.COLOR_WHITE)\r
+                PS.AudioPlay(PS.Xylophone(10), 0.3);\r
+            else\r
+                PS.AudioPlay(PS.Xylophone(13), 0.5);\r
+        } else if (count == 4 && CheckExact([1, 2, 3, 4, 5, 6, 7, 8, 9])) {\r
+            Win();\r
+        } else {\r
+            if (PS.BeadColor(x, y) == PS.COLOR_WHITE)\r
+                PS.AudioPlay(PS.Xylophone(10), 0.3);\r
+            else\r
+                PS.AudioPlay(PS.Xylophone(13), 0.5);\r
+        }\r
+    };\r
 };\r
 \r
 function ApproveIfExact(a, color) {\r
@@ -384,51 +372,65 @@ function ApproveIfExact(a, color) {
     }\r
 };\r
 \r
-function DiePress(x, y) {\r
-    if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
-        PS.BeadColor(x, y, PS.COLOR_BLACK);\r
-    } else {\r
-        PS.BeadColor(x, y, PS.COLOR_WHITE);\r
-    }\r
-    switch (count) {\r
-    case 3:\r
-        if (ApproveIfExact([1, 5, 9]) || ApproveIfExact([7, 5, 3]))\r
-            count = 4;\r
-        break;\r
-    case 4:\r
-        if (ApproveIfExact([1, 3, 7, 9]))\r
-            count = 5;\r
-        break;\r
-    case 5:\r
-        if (ApproveIfExact([1, 3, 5, 7, 9]))\r
-            count = 6;\r
-        break;\r
-    case 6:\r
-        if (CheckExact([1, 2, 3, 7, 8, 9])\r
-            || CheckExact([1, 4, 7, 3, 6, 9])) {\r
-            Win();\r
-            return;\r
+function Die () {\r
+    PS.Clock(40);\r
+    QueueChange([[PS.COLOR_BLACK, 5]], [PS.Xylophone(13)]);\r
+    QueueChange([[PS.COLOR_GREEN, 5]], [PS.Xylophone(14)]);\r
+    QueueChange([[PS.COLOR_WHITE, 5]]);\r
+    QueueChange([[PS.COLOR_BLACK, 1]], [PS.Xylophone(13)]);\r
+    QueueChange([[PS.COLOR_BLACK, 9]], [PS.Xylophone(13)]);\r
+    QueueChange([[PS.COLOR_GREEN, 1],\r
+                 [PS.COLOR_GREEN, 9]], [PS.Xylophone(14)]);\r
+    QueueChange([[PS.COLOR_WHITE, 1],\r
+                 [PS.COLOR_WHITE, 9]]);\r
+    var count = 3;\r
+\r
+    this.Press = function (x, y) {\r
+        if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
+            PS.BeadColor(x, y, PS.COLOR_BLACK);\r
+        } else {\r
+            PS.BeadColor(x, y, PS.COLOR_WHITE);\r
+        }\r
+        switch (count) {\r
+        case 3:\r
+            if (ApproveIfExact([1, 5, 9]) || ApproveIfExact([7, 5, 3]))\r
+                count = 4;\r
+            break;\r
+        case 4:\r
+            if (ApproveIfExact([1, 3, 7, 9]))\r
+                count = 5;\r
+            break;\r
+        case 5:\r
+            if (ApproveIfExact([1, 3, 5, 7, 9]))\r
+                count = 6;\r
+            break;\r
+        case 6:\r
+            if (CheckExact([1, 2, 3, 7, 8, 9])\r
+                || CheckExact([1, 4, 7, 3, 6, 9])) {\r
+                Win();\r
+                return;\r
+            }\r
         }\r
-    }\r
 \r
-    if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
-        PS.AudioPlay(PS.Xylophone(14), 0.5);\r
-    } else {\r
-        PS.AudioPlay(PS.Xylophone(13), 0.3);\r
-    }\r
+        if (PS.BeadColor(x, y) == PS.COLOR_WHITE) {\r
+            PS.AudioPlay(PS.Xylophone(14), 0.5);\r
+        } else {\r
+            PS.AudioPlay(PS.Xylophone(13), 0.3);\r
+        }\r
+    };\r
 };\r
 \r
 var LEVELS = [\r
     null,\r
-    [FollowMeStart, FollowMePress],\r
-    [ThreeRowStart, ThreeRowPress],\r
-    [EnumerateStart, EnumeratePress],\r
-    [RepeatStart, RepeatPress],\r
-    [TickMissingStart, TickMissingPress],\r
-    [SudokuStart, SudokuPress],\r
-    [ShapesStart, ShapesPress],\r
-    [DieStart, DiePress],\r
-    [DigitsStart, DigitsPress],\r
+    FollowMe,\r
+    ThreeRow,\r
+    Enumerate,\r
+    Repeat,\r
+    TickMissing,\r
+    SudokuRow,\r
+    Shapes,\r
+    Die,\r
+    Digits,\r
 ];\r
 \r
 function Reset(color) {\r
@@ -502,7 +504,7 @@ function StartLevel(level) {
     PS.AudioPlay(PS.Xylophone(1), 0.5);\r
     Reset(PS.COLOR_WHITE);\r
     current_level = level;\r
-    LEVELS[current_level][0]();\r
+    current_level_inst = new LEVELS[current_level]();\r
     state = LEVEL_IN;\r
 };\r
 \r
@@ -529,7 +531,7 @@ PS.Click = function (x, y, data, options) {
         StartLevel(LEVEL_IDX[y][x]);\r
         break;\r
     case LEVEL_IN:\r
-        LEVELS[current_level][1](x, y);\r
+        current_level_inst.Press(x, y);\r
         break;\r
     case LEVEL_WON:\r
         LevelSelect();\r