Initial prompt
MazZero
User prompt
Add these globals : // Game state variables var GAME_STATE = { INIT: 'INIT', MENU: 'MENU', NEW_ROUND: 'NEW_ROUND', PLAYING: 'PLAYING', SCORE: 'SCORE' }; var currentState = GAME_STATE.INIT;
User prompt
add initializeGame function and move all elements initialzation inside
User prompt
add initializeGame function and move all elements initialzation inside. all elements should be kept as global vairables. no locals in initializeGame
User prompt
remove duplicate
User prompt
move event handlers out of inifunction under a cmment /**** * Event Handlers ****/
User prompt
for each game state create 3 functions:initXXXState, handleXXXLoop and cleanXXXState
User prompt
add a new global debug = true and a new utility function function log() { if (debug) { console.log.apply(console, arguments); } }
User prompt
replace console.log by log() except in log() funciton ;)
User prompt
fix initXXXState, handleXXXLoop and cleanXXXState naming by using camel case (ie: initMenuState not initMENUState, ...)
Code edit (1 edits merged)
Please save this source code
User prompt
add and implement changeGameState(newState) (add detailed logs using log())
Code edit (1 edits merged)
Please save this source code
User prompt
in initializeGame call // Transition to menu state changeGameState(GAME_STATE.MENU);
Code edit (1 edits merged)
Please save this source code
User prompt
add global isPlaying = false
Code edit (1 edits merged)
Please save this source code
User prompt
add a new startButton asset and class; initialze it in game initialze and but show it only in menu state
User prompt
Please fix the bug: 'startButton is not defined' in or related to this line: 'startButton.visible = true;' Line Number: 146
Code edit (6 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
move puzzleManager.initPuzzle(); in initNewRound
User prompt
add 3 global containers layers
User prompt
add 3 global containers layers for background, middle and foreground
User prompt
Initialization of globals shoud come in initialzeGame
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,10 @@
/****
* Classes
****/
+/***********************************************************************************************/
+/******************************************* ASSETS CLASSES ************************************/
+/***********************************************************************************************/
// HexTile class to represent each tile on the board
var HexTile = Container.expand(function (value, col, row) {
var self = Container.call(this);
// Properties
@@ -82,200 +85,11 @@
/****
* Game Code
****/
-function changeGameState(newState) {
- log("Changing game state from", currentState, "to", newState);
- // Clean up the current state
- switch (currentState) {
- case GAME_STATE.INIT:
- // Do nothing
- break;
- case GAME_STATE.MENU:
- cleanMenuState();
- break;
- case GAME_STATE.NEW_ROUND:
- cleanNewRoundState();
- break;
- case GAME_STATE.PLAYING:
- cleanPlayingState();
- break;
- case GAME_STATE.SCORE:
- cleanScoreState();
- break;
- default:
- log("Unknown state:", currentState);
- }
- // Set the new state
- currentState = newState;
- // Initialize the new state
- switch (newState) {
- case GAME_STATE.MENU:
- initMenuState();
- break;
- case GAME_STATE.NEW_ROUND:
- initNewRoundState();
- break;
- case GAME_STATE.PLAYING:
- initPlayingState();
- break;
- case GAME_STATE.SCORE:
- initScoreState();
- break;
- default:
- log("Unknown state:", newState);
- }
-}
-// Utility log function
-function log() {
- if (debug) {
- console.log.apply(console, arguments);
- }
-}
-function initMenuState() {
- // Initialize the game state for MENU
- log("Initializing MENU State");
- startButton.visible = true;
-}
-function handleMenuLoop() {
- // Handle the game loop for MENU state
- log("Handling MENU Loop");
-}
-function cleanMenuState() {
- // Clean up the game state for MENU
- log("Cleaning MENU State");
-}
-function initNewRoundState() {
- // Initialize the game state for NEW_ROUND
- log("Initializing NEW_ROUND State");
-}
-function handleNewRoundLoop() {
- // Handle the game loop for NEW_ROUND state
- log("Handling NEW_ROUND Loop");
-}
-function cleanNewRoundState() {
- // Clean up the game state for NEW_ROUND
- log("Cleaning NEW_ROUND State");
-}
-function initPlayingState() {
- // Initialize the game state for PLAYING
- log("Initializing PLAYING State");
-}
-function handlePlayingLoop() {
- // Handle the game loop for PLAYING state
- log("Handling PLAYING Loop");
-}
-function cleanPlayingState() {
- // Clean up the game state for PLAYING
- log("Cleaning PLAYING State");
-}
-function initScoreState() {
- // Initialize the game state for SCORE
- log("Initializing SCORE State");
-}
-function handleScoreLoop() {
- // Handle the game loop for SCORE state
- log("Handling SCORE Loop");
-}
-function cleanScoreState() {
- // Clean up the game state for SCORE
- log("Cleaning SCORE State");
-}
-/****
-* Event Handlers
-****/
-game.down = function (x, y, obj) {
- // Handle operation button drag start
-};
-game.move = function (x, y, obj) {
- // Handle operation button drag movement
-};
-game.up = function (x, y, obj) {
- // Handle operation button drag end
-};
-// Initialize PuzzleManager
-//<Assets used in the game will automatically appear here>
-//<Write imports for supported plugins here>
-// PuzzleManager class to manage the game logic
-function _createForOfIteratorHelper(r, e) {
- var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
- if (!t) {
- if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
- t && (r = t);
- var _n = 0,
- F = function F() {};
- return {
- s: F,
- n: function n() {
- return _n >= r.length ? {
- done: !0
- } : {
- done: !1,
- value: r[_n++]
- };
- },
- e: function e(r) {
- throw r;
- },
- f: F
- };
- }
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
- }
- var o,
- a = !0,
- u = !1;
- return {
- s: function s() {
- t = t.call(r);
- },
- n: function n() {
- var r = t.next();
- return a = r.done, r;
- },
- e: function e(r) {
- u = !0, o = r;
- },
- f: function f() {
- try {
- a || null == t["return"] || t["return"]();
- } finally {
- if (u) {
- throw o;
- }
- }
- }
- };
-}
-function _unsupportedIterableToArray(r, a) {
- if (r) {
- if ("string" == typeof r) {
- return _arrayLikeToArray(r, a);
- }
- var t = {}.toString.call(r).slice(8, -1);
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
- }
-}
-function _arrayLikeToArray(r, a) {
- (null == a || a > r.length) && (a = r.length);
- for (var e = 0, n = Array(a); e < a; e++) {
- n[e] = r[e];
- }
- return n;
-}
/***********************************************************************************************/
-/****************************************** GLOBAL VARIABLES ***********************************/
+/************************************* GAME OBJECTS CLASSES ************************************/
/***********************************************************************************************/
-var debug = true;
-var isPlaying = false;
-var GAME_STATE = {
- INIT: 'INIT',
- MENU: 'MENU',
- NEW_ROUND: 'NEW_ROUND',
- PLAYING: 'PLAYING',
- SCORE: 'SCORE'
-};
-var currentState = GAME_STATE.INIT;
function PuzzleManager(game) {
var self = this;
// Properties
self.game = game;
@@ -398,11 +212,209 @@
self.playVictoryAnimation = function () {
// Play level complete animation
};
}
-// Global variables
+function changeGameState(newState) {
+ log("Changing game state from", currentState, "to", newState);
+ // Clean up the current state
+ switch (currentState) {
+ case GAME_STATE.INIT:
+ // Do nothing
+ break;
+ case GAME_STATE.MENU:
+ cleanMenuState();
+ break;
+ case GAME_STATE.NEW_ROUND:
+ cleanNewRoundState();
+ break;
+ case GAME_STATE.PLAYING:
+ cleanPlayingState();
+ break;
+ case GAME_STATE.SCORE:
+ cleanScoreState();
+ break;
+ default:
+ log("Unknown state:", currentState);
+ }
+ // Set the new state
+ currentState = newState;
+ // Initialize the new state
+ switch (newState) {
+ case GAME_STATE.MENU:
+ initMenuState();
+ break;
+ case GAME_STATE.NEW_ROUND:
+ initNewRoundState();
+ break;
+ case GAME_STATE.PLAYING:
+ initPlayingState();
+ break;
+ case GAME_STATE.SCORE:
+ initScoreState();
+ break;
+ default:
+ log("Unknown state:", newState);
+ }
+}
+/***********************************************************************************************/
+/************************************* UTILITY FUNCTIONS ************************************/
+/***********************************************************************************************/
+function log() {
+ if (debug) {
+ console.log.apply(console, arguments);
+ }
+}
+function _createForOfIteratorHelper(r, e) {
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
+ if (!t) {
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
+ t && (r = t);
+ var _n = 0,
+ F = function F() {};
+ return {
+ s: F,
+ n: function n() {
+ return _n >= r.length ? {
+ done: !0
+ } : {
+ done: !1,
+ value: r[_n++]
+ };
+ },
+ e: function e(r) {
+ throw r;
+ },
+ f: F
+ };
+ }
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
+ }
+ var o,
+ a = !0,
+ u = !1;
+ return {
+ s: function s() {
+ t = t.call(r);
+ },
+ n: function n() {
+ var r = t.next();
+ return a = r.done, r;
+ },
+ e: function e(r) {
+ u = !0, o = r;
+ },
+ f: function f() {
+ try {
+ a || null == t["return"] || t["return"]();
+ } finally {
+ if (u) {
+ throw o;
+ }
+ }
+ }
+ };
+}
+function _unsupportedIterableToArray(r, a) {
+ if (r) {
+ if ("string" == typeof r) {
+ return _arrayLikeToArray(r, a);
+ }
+ var t = {}.toString.call(r).slice(8, -1);
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
+ }
+}
+function _arrayLikeToArray(r, a) {
+ (null == a || a > r.length) && (a = r.length);
+ for (var e = 0, n = Array(a); e < a; e++) {
+ n[e] = r[e];
+ }
+ return n;
+}
+/***********************************************************************************************/
+/************************************* GAME STATE MANAGEMENT ************************************/
+/***********************************************************************************************/
+function initMenuState() {
+ // Initialize the game state for MENU
+ log("Initializing MENU State");
+ startButton.visible = true;
+}
+function handleMenuLoop() {
+ // Handle the game loop for MENU state
+ log("Handling MENU Loop");
+}
+function cleanMenuState() {
+ // Clean up the game state for MENU
+ log("Cleaning MENU State");
+}
+function initNewRoundState() {
+ // Initialize the game state for NEW_ROUND
+ log("Initializing NEW_ROUND State");
+}
+function handleNewRoundLoop() {
+ // Handle the game loop for NEW_ROUND state
+ log("Handling NEW_ROUND Loop");
+}
+function cleanNewRoundState() {
+ // Clean up the game state for NEW_ROUND
+ log("Cleaning NEW_ROUND State");
+}
+function initPlayingState() {
+ // Initialize the game state for PLAYING
+ log("Initializing PLAYING State");
+}
+function handlePlayingLoop() {
+ // Handle the game loop for PLAYING state
+ log("Handling PLAYING Loop");
+}
+function cleanPlayingState() {
+ // Clean up the game state for PLAYING
+ log("Cleaning PLAYING State");
+}
+function initScoreState() {
+ // Initialize the game state for SCORE
+ log("Initializing SCORE State");
+}
+function handleScoreLoop() {
+ // Handle the game loop for SCORE state
+ log("Handling SCORE Loop");
+}
+function cleanScoreState() {
+ // Clean up the game state for SCORE
+ log("Cleaning SCORE State");
+}
+/***********************************************************************************************/
+/****************************************** EVENT HANDLERS *************************************/
+/***********************************************************************************************/
+game.down = function (x, y, obj) {
+ // Handle operation button drag start
+};
+game.move = function (x, y, obj) {
+ // Handle operation button drag movement
+};
+game.up = function (x, y, obj) {
+ // Handle operation button drag end
+};
+// Initialize PuzzleManager
+//<Assets used in the game will automatically appear here>
+//<Write imports for supported plugins here>
+/***********************************************************************************************/
+/****************************************** GLOBAL VARIABLES ***********************************/
+/***********************************************************************************************/
+var debug = true;
+var isPlaying = false;
+var GAME_STATE = {
+ INIT: 'INIT',
+ MENU: 'MENU',
+ NEW_ROUND: 'NEW_ROUND',
+ PLAYING: 'PLAYING',
+ SCORE: 'SCORE'
+};
+var currentState = GAME_STATE.INIT;
var puzzleManager;
var startButton;
+/***********************************************************************************************/
+/***************************************** GAME INITIALISATION *********************************/
+/***********************************************************************************************/
function initializeGame() {
puzzleManager = new PuzzleManager(game);
puzzleManager.initPuzzle();
startButton = new StartButton();
tick
Sound effect
tileEntrance
Sound effect
tileRemove
Sound effect
operationSelect
Sound effect
operationCancel
Sound effect
tileChangeValue
Sound effect
resetSound
Sound effect
levelFailed
Sound effect
menuLevelSelect
Sound effect
menuCellEnter
Sound effect
applause
Sound effect
bgMusic
Music
tada
Sound effect