User prompt
Increase times reset counter after every reset
User prompt
Add times reset counter.
User prompt
Persist times rolled counter through resets
User prompt
Add 'Times Rolled' counter, increase after every roll button pressed.
User prompt
Add current time counter under total time. Make current time set at zero after each reset.
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'setItem')' in or related to this line: 'localStorage.setItem('totalTime', totalTime);' Line Number: 137
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'getItem')' in or related to this line: 'var totalTime = parseInt(localStorage.getItem('totalTime')) || 0;' Line Number: 152
User prompt
Persist counted total time when reset button is pressed
User prompt
Add total time counter under Total Cash, make it count up and persist through resets
User prompt
After each button press, increase cash won and current cash counters.
User prompt
display current cash under cash won. When reset button is pressed, reset current cash but keep total cash.
User prompt
add reset button next to roll button
User prompt
Display 'Total Cash' under Cash Won.
User prompt
Increase cash won after each button press, stacking the number.
User prompt
Display 'cash won' under dice side text. When dice side is 1, cash is ten. When dice side is 6, cash won is 60.
User prompt
Increase dice side text size
User prompt
hide purple dice asset
User prompt
Please fix the bug: 'Uncaught TypeError: diceGraphics.setTexture is not a function' in or related to this line: 'diceGraphics.setTexture('dice1');' Line Number: 27
User prompt
Make dice asset display a number from 1 to 6 when roll button is pressed.
User prompt
Please fix the bug: 'diceGraphics.setTexture is not a function' in or related to this line: 'diceGraphics.setTexture('dice' + self.value);' Line Number: 24
User prompt
When roll button is pressed, make dice display a number. Link this number to the dice side number display.
User prompt
Change score text to 'Dice Side'
User prompt
Please fix the bug: 'Uncaught TypeError: rollButton.setText is not a function' in or related to this line: 'rollButton.setText('Roll');' Line Number: 54
Initial prompt
Dice Generator
/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Dice class to represent a dice var Dice = Container.expand(function () { var self = Container.call(this); // Create and attach dice asset var diceGraphics = self.attachAsset('dice', { anchorX: 0.5, anchorY: 0.5 }); // Set initial value and texture self.value = 1; diceGraphics.texture = LK.getAsset('dice1', {}).texture; // Method to roll the dice self.roll = function () { self.value = Math.floor(Math.random() * 6) + 1; diceGraphics.texture = LK.getAsset('dice' + self.value, {}).texture; totalCashTxt.setText('Total Cash: ' + totalCashWon); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // LK.init.shape('dice', {width:100, height:100, color:0x7c138f, shape:'box'}) // Purple dice asset hidden // Create score text var scoreTxt = new Text2('Dice Side: 1', { size: 200, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create cash won text var cashTxt = new Text2('Cash Won: 10', { size: 150, fill: "#ffffff" }); cashTxt.anchor.set(0.5, 0); cashTxt.y = scoreTxt.height + 20; // Position cash text below score text LK.gui.top.addChild(cashTxt); // Create current cash text var currentCashTxt = new Text2('Current Cash: 0', { size: 150, fill: "#ffffff" }); currentCashTxt.anchor.set(0.5, 0); currentCashTxt.y = cashTxt.y + cashTxt.height + 20; // Position current cash text below cash won text LK.gui.top.addChild(currentCashTxt); // Create total cash text var totalCashTxt = new Text2('Total Cash: 0', { size: 150, fill: "#ffffff" }); totalCashTxt.anchor.set(0.5, 0); totalCashTxt.y = currentCashTxt.y + currentCashTxt.height + 20; // Position total cash text below current cash text LK.gui.top.addChild(totalCashTxt); // Create total time text var totalTimeTxt = new Text2('Total Time: 0s', { size: 150, fill: "#ffffff" }); totalTimeTxt.anchor.set(0.5, 0); totalTimeTxt.y = totalCashTxt.y + totalCashTxt.height + 20; // Position total time text below total cash text LK.gui.top.addChild(totalTimeTxt); // Create roll button var rollButton = LK.getAsset('button', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2 - 200, y: 2732 - 200 }); var rollButtonText = new Text2('Roll', { size: 50, fill: "#ffffff" }); rollButtonText.anchor.set(0.5, 0.5); rollButton.addChild(rollButtonText); game.addChild(rollButton); // Create reset button var resetButton = LK.getAsset('button', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2 + 200, y: 2732 - 200 }); var resetButtonText = new Text2('Reset', { size: 50, fill: "#ffffff" }); resetButtonText.anchor.set(0.5, 0.5); resetButton.addChild(resetButtonText); game.addChild(resetButton); // Create dice var dice = new Dice(); dice.x = 2048 / 2; dice.y = 2732 / 2; game.addChild(dice); // Roll button event rollButton.down = function (x, y, obj) { dice.roll(); scoreTxt.setText('Dice Side: ' + dice.value); var cashWon = dice.value * 10; currentCash += cashWon; totalCashWon += cashWon; cashTxt.setText('Cash Won: ' + cashWon); currentCashTxt.setText('Current Cash: ' + currentCash); totalCashTxt.setText('Total Cash: ' + totalCashWon); }; // Reset button event resetButton.down = function (x, y, obj) { currentCash = 0; scoreTxt.setText('Dice Side: 1'); cashTxt.setText('Cash Won: 0'); currentCashTxt.setText('Current Cash: ' + currentCash); totalTimeTxt.setText('Total Time: ' + totalTime + 's'); if (typeof localStorage !== 'undefined') { localStorage.setItem('totalTime', totalTime); } }; // Game update function game.update = function () { // Any game update logic can go here if (LK.ticks % 60 == 0) { // Update every second (60 ticks per second) totalTime++; totalTimeTxt.setText('Total Time: ' + totalTime + 's'); } }; // Global variable to keep track of total cash won var totalCashWon = 0; // Global variable to keep track of current cash // Global variable to keep track of total time var totalTime = 0; if (typeof localStorage !== 'undefined') { totalTime = parseInt(localStorage.getItem('totalTime')) || 0; }
===================================================================
--- original.js
+++ change.js
@@ -121,9 +121,11 @@
scoreTxt.setText('Dice Side: 1');
cashTxt.setText('Cash Won: 0');
currentCashTxt.setText('Current Cash: ' + currentCash);
totalTimeTxt.setText('Total Time: ' + totalTime + 's');
- localStorage.setItem('totalTime', totalTime);
+ if (typeof localStorage !== 'undefined') {
+ localStorage.setItem('totalTime', totalTime);
+ }
};
// Game update function
game.update = function () {
// Any game update logic can go here