User prompt
Generate 'Bear Won' text when dice side is 1.
User prompt
Add 'Time Since Last Reset' duration counter text
User prompt
add 'Time Since Last Roll' duration counter text
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'getItem')' in or related to this line: 'timesRolled = parseInt(localStorage.getItem('timesRolled')) || 0;' Line Number: 188
User prompt
put prize box asset directly above roll and reset buttons
User prompt
Make Prize Box asset lower
User prompt
make prize box asset lower
User prompt
add Prize Box asset underneath times reset text
User prompt
Please fix the bug: 'Uncaught ReferenceError: prizesWonTxt is not defined' in or related to this line: 'var prizesWon = parseInt(prizesWonTxt.text.split(': ')[1]) + 1;' Line Number: 162
User prompt
delete prizes won and bear prize text.
User prompt
Increase Prizes Won counter by one digit each time Dice Side is 1.
User prompt
increase prizes won after each roll
User prompt
Change 'Bear Prize' text to 'Bear Prize: 0'
User prompt
Add text for '10 cash = Bear Prize'
User prompt
Add 'Prizes Won:' text underneath Times Rolled.
User prompt
Make screen briefly flash brown upon each reset
User prompt
Make times reset go from 0 to 1 when reset button is pressed
User prompt
Copy Times Rolled behavior into Times Reset text counter
User prompt
Please fix the bug: 'Uncaught ReferenceError: currentCash is not defined' in or related to this line: 'currentCash += cashWon;' Line Number: 140
User prompt
Increase text of roll and reset buttons
User prompt
decrease size of text
User prompt
Allow total time and current time to count into days.
User prompt
delete times reset text.
User prompt
After each reset, increase 'Times Reset' by 1.
User prompt
Increase times reset counter by 1 each time reset button is used.
/**** * 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: 100, 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: 75, 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: 75, 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: 75, 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: 75, 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 current time text var currentTimeTxt = new Text2('Current Time: 0s', { size: 75, fill: "#ffffff" }); currentTimeTxt.anchor.set(0.5, 0); currentTimeTxt.y = totalTimeTxt.y + totalTimeTxt.height + 20; // Position current time text below total time text LK.gui.top.addChild(currentTimeTxt); // Create times rolled text var timesRolledTxt = new Text2('Times Rolled: 0', { size: 75, fill: "#ffffff" }); timesRolledTxt.anchor.set(0.5, 0); timesRolledTxt.y = currentTimeTxt.y + currentTimeTxt.height + 20; // Position times rolled text below current time text LK.gui.top.addChild(timesRolledTxt); // 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: 25, 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: 25, 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); timesRolled++; timesRolledTxt.setText('Times Rolled: ' + timesRolled); if (typeof localStorage !== 'undefined') { localStorage.setItem('timesRolled', timesRolled); timesRolled = parseInt(localStorage.getItem('timesRolled')) || 0; timesRolledTxt.setText('Times Rolled: ' + timesRolled); } }; // 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'); currentTime = 0; currentTimeTxt.setText('Current Time: ' + currentTime + 's'); timesRolled = parseInt(localStorage.getItem('timesRolled')) || 0; timesRolledTxt.setText('Times Rolled: ' + timesRolled); timesReset++; if (typeof localStorage !== 'undefined') { localStorage.setItem('timesReset', timesReset); } if (typeof localStorage !== 'undefined') { localStorage.setItem('timesReset', timesReset); } if (typeof localStorage !== 'undefined') { localStorage.setItem('totalTime', totalTime); localStorage.setItem('timesRolled', timesRolled); localStorage.setItem('timesReset', timesReset); } }; // 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++; var totalDays = Math.floor(totalTime / 86400); var totalHours = Math.floor(totalTime % 86400 / 3600); var totalMinutes = Math.floor(totalTime % 3600 / 60); var totalSeconds = totalTime % 60; totalTimeTxt.setText("Total Time: ".concat(totalDays, "d ").concat(totalHours, "h ").concat(totalMinutes, "m ").concat(totalSeconds, "s")); currentTime++; var currentDays = Math.floor(currentTime / 86400); var currentHours = Math.floor(currentTime % 86400 / 3600); var currentMinutes = Math.floor(currentTime % 3600 / 60); var currentSeconds = currentTime % 60; currentTimeTxt.setText("Current Time: ".concat(currentDays, "d ").concat(currentHours, "h ").concat(currentMinutes, "m ").concat(currentSeconds, "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 times rolled var timesRolled = 0; // Global variable to keep track of current time var currentTime = 0; // Global variable to keep track of times reset var timesReset = 0; // Global variable to keep track of total time var totalTime = 0; if (typeof localStorage !== 'undefined') { totalTime = parseInt(localStorage.getItem('totalTime')) || 0; timesReset = parseInt(localStorage.getItem('timesReset')) || 0; }
===================================================================
--- original.js
+++ change.js
@@ -33,56 +33,56 @@
****/
// 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,
+ size: 100,
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,
+ size: 75,
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,
+ size: 75,
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,
+ size: 75,
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,
+ size: 75,
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 current time text
var currentTimeTxt = new Text2('Current Time: 0s', {
- size: 150,
+ size: 75,
fill: "#ffffff"
});
currentTimeTxt.anchor.set(0.5, 0);
currentTimeTxt.y = totalTimeTxt.y + totalTimeTxt.height + 20; // Position current time text below total time text
LK.gui.top.addChild(currentTimeTxt);
// Create times rolled text
var timesRolledTxt = new Text2('Times Rolled: 0', {
- size: 150,
+ size: 75,
fill: "#ffffff"
});
timesRolledTxt.anchor.set(0.5, 0);
timesRolledTxt.y = currentTimeTxt.y + currentTimeTxt.height + 20; // Position times rolled text below current time text
@@ -94,9 +94,9 @@
x: 2048 / 2 - 200,
y: 2732 - 200
});
var rollButtonText = new Text2('Roll', {
- size: 50,
+ size: 25,
fill: "#ffffff"
});
rollButtonText.anchor.set(0.5, 0.5);
rollButton.addChild(rollButtonText);
@@ -108,9 +108,9 @@
x: 2048 / 2 + 200,
y: 2732 - 200
});
var resetButtonText = new Text2('Reset', {
- size: 50,
+ size: 25,
fill: "#ffffff"
});
resetButtonText.anchor.set(0.5, 0.5);
resetButton.addChild(resetButtonText);