User prompt
Arregla el bug que el tiempo empieza a subir cuando se tiran los dados y no como un proceso secundario
User prompt
Haz que el tiempo suba desde que se ejecuta el juego y no desde que se toca la pantalla ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Agrega un texto arriba del todo mostrando el tiempo jugado, que se actualice cada segundo(guarda el valor) ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Agrega un texto arriba del todo como de cronómetro: 000:00:00. Que se actualice cada segundo y guarda el valor ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Utiliza la fórmula: "P(\text{exactamente } k) = \frac{1}{6^8} \cdot \sum_{\substack{n_1 + \cdots + n_6 = 8 \\ \max(n_i) = k}} \binom{8}{n_1, ..., n_6}" para la posibilidad de coincidir los dados
User prompt
Agrega más partículas ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Agrega partículas, cuando finaliza el tiro, al grupo más grande ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Agrega partículas, cuando finaliza el tiro, al grupo más grande ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Cambia los textos a inglés
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'probabilityNumberText.style.fill = redColor;' Line Number: 256
User prompt
Arregla el error que hace que todo el texto tenga el mismo color
User prompt
Cambia los colores de la posibilidad así: posibilidad(negro): 1 (amarillo) en (negro) N (rojo pastel, mientras más difícil más rojo será)
User prompt
Agrega una fuente más Soft y dale colores a los textos
User prompt
Agranda el texto y replaza la manera de mostrar como posibilidad:
User prompt
Please fix the bug: 'Uncaught RangeError: Maximum call stack size exceeded' in or related to this line: 'var matchingCount = countMatchingDice();' Line Number: 214
User prompt
Agrega un texto abajo de la pantalla que diga la posibilidad de que haya tocado dicho cantidad de dados iguales en los 8 dados
User prompt
Agrega un texto abajo que pone la posibilidad que de que haya tocado dicho grupo de dados (en: 1(color amarillo) en xxxx (color rojo)
User prompt
Haz que los valores mejor, anterior y actual se guarden y carguen ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Haz que anterior copie el valor de actual cuando se toca para cambiar los dados, y haz que actual vuelva a 0/8 hasta que finalice el cambio de dados y tome el nuevo valor
User prompt
Haz que siempre que cambie actual, ese valor pase a ser valor del anterior
User prompt
Modifica el texto de 0/8 de la siguiente forma: Best: 0/8
User prompt
Agrega al texto de 0/8 el mejor y el actual, los dos en la misma fila tipo actual: 0/8 - mejor: 0/8
Code edit (1 edits merged)
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Dice = Container.expand(function () { var self = Container.call(this); // Add numeric variable valor self.valor = 1; // Add rolling animation variables self.isRolling = false; self.rollCount = 0; self.rollTarget = 0; self.rollTimer = 0; var diceGraphics = self.attachAsset('Dice' + self.valor, { anchorX: 0.5, anchorY: 0.5 }); // Method to update dice visual based on valor self.updateVisual = function () { // Create new graphics based on valor first var newGraphics = self.attachAsset('Dice' + self.valor, { anchorX: 0.5, anchorY: 0.5 }); // Remove old graphics after new one is created self.removeChild(diceGraphics); // Update reference to new graphics diceGraphics = newGraphics; // Add bounce effect when value changes during rolling if (self.isRolling) { self.playDiceSound(); diceGraphics.scaleX = 1; diceGraphics.scaleY = 1; tween(diceGraphics, { scaleX: 1.2, scaleY: 1.2 }, { duration: 100, easing: tween.bounceOut, onFinish: function onFinish() { tween(diceGraphics, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.bounceOut }); } }); } }; // Method to play dice sound self.playDiceSound = function () { LK.getSound('Roll').play(); }; // Method to start rolling animation self.startRoll = function () { self.isRolling = true; self.rollCount = 0; self.rollTarget = Math.floor(Math.random() * 7) + 6; // 6 to 12 rolls self.rollTimer = 0; }; // Update method for rolling animation self.update = function () { if (self.isRolling) { var rollSpeed = Math.floor(self.rollCount * 1.5) + 3; // Start fast, get slower if (self.rollTimer >= rollSpeed) { self.valor = Math.floor(Math.random() * 6) + 1; self.updateVisual(); self.rollCount++; self.rollTimer = 0; if (self.rollCount >= self.rollTarget) { self.isRolling = false; } } else { self.rollTimer++; } } }; return self; }); /**** * Initialize Game ****/ // Create array to hold all dice var game = new LK.Game({ backgroundColor: 0xFFFFFF }); /**** * Game Code ****/ // Create array to hold all dice var diceArray = []; // Add lanzamiento boolean variable var lanzamiento = false; // Add timer to enforce minimum 1 second wait between rolls var lastRollFinishTime = 0; var minimumWaitTime = 1000; // 1 second in milliseconds // Calculate center positions for two columns var centerX = 2048 / 2; var centerY = 2732 / 2; var columnSpacing = 330; // Space between columns var rowSpacing = 300; // Space between rows // Create matching dice counter text var counterText = new Text2('0/8', { size: 80, fill: 0x000000 }); counterText.anchor.set(0.5, 0); counterText.y = 100; // Move down to make space for status text LK.gui.top.addChild(counterText); // Create status text above dice var statusText = new Text2('Toca para lanzar', { size: 60, fill: 0x333333 }); statusText.anchor.set(0.5, 0.5); statusText.x = centerX; statusText.y = centerY - 100; // Position above dice grid game.addChild(statusText); // Create countdown text var countdownText = new Text2('', { size: 50, fill: 0x666666 }); countdownText.anchor.set(0.5, 0.5); countdownText.x = centerX; countdownText.y = centerY - 100; // Position below status text game.addChild(countdownText); // Function to count matching dice function countMatchingDice() { var counts = {}; // Count occurrences of each dice value for (var i = 0; i < diceArray.length; i++) { var value = diceArray[i].valor; counts[value] = (counts[value] || 0) + 1; } // Find the highest count var maxCount = 0; for (var value in counts) { if (counts[value] > maxCount) { maxCount = counts[value]; } } return maxCount; } // Function to apply tint colors to dice based on matching groups function applyDiceTints() { var counts = {}; // Count occurrences of each dice value for (var i = 0; i < diceArray.length; i++) { var value = diceArray[i].valor; counts[value] = (counts[value] || 0) + 1; } // Find the highest count and value var maxCount = 0; var maxValue = 0; for (var value in counts) { if (counts[value] > maxCount) { maxCount = counts[value]; maxValue = parseInt(value); } } // Generate random colors for smaller groups var randomColors = [0xFF6B6B, 0x4ECDC4, 0x45B7D1, 0x96CEB4, 0xFECE00, 0xF38BA8]; var colorIndex = 0; var usedColors = {}; // Apply tints to all dice for (var i = 0; i < diceArray.length; i++) { var dice = diceArray[i]; var value = dice.valor; if (value == maxValue && counts[value] == maxCount) { // Largest group gets soft yellow tint dice.children[0].tint = 0xFFFF99; // Soft yellow } else if (counts[value] > 1) { // Smaller matching groups get random colors if (!usedColors[value]) { usedColors[value] = randomColors[colorIndex % randomColors.length]; colorIndex++; } dice.children[0].tint = usedColors[value]; } else { // Single dice get no tint (white) dice.children[0].tint = 0xFFFFFF; } } } // Create 8 dice in two columns (4 rows each) for (var col = 0; col < 2; col++) { for (var row = 0; row < 4; row++) { var dice = new Dice(); // Assign random valor from 1 to 6 dice.valor = Math.floor(Math.random() * 6) + 1; // Update visual based on valor dice.updateVisual(); // Position dice in grid dice.x = centerX + (col - 0.5) * columnSpacing; dice.y = centerY + (row - 1.5) * rowSpacing; // Add to game and array game.addChild(dice); diceArray.push(dice); } // Game update method to handle dice rolling game.update = function () { // Update status and countdown text based on current state var currentTime = Date.now(); var timeSinceLastRoll = currentTime - lastRollFinishTime; var timeRemaining = minimumWaitTime - timeSinceLastRoll; if (lanzamiento) { // Currently rolling statusText.setText('Cambiando dados...'); countdownText.setText(''); } else if (timeRemaining > 0) { // Waiting period - show countdown statusText.setText('Espera para lanzar'); var secondsRemaining = timeRemaining / 1000; countdownText.setText(secondsRemaining.toFixed(2) + 's'); } else { // Ready to roll statusText.setText('Toca para lanzar'); countdownText.setText(''); } // Check if all dice have finished rolling if (lanzamiento) { var allFinished = true; for (var i = 0; i < diceArray.length; i++) { if (diceArray[i].isRolling) { allFinished = false; break; } } // Reset lanzamiento when all dice are done if (allFinished) { lanzamiento = false; // Record the time when rolling finished lastRollFinishTime = Date.now(); // Update counter text with matching dice count var matchingCount = countMatchingDice(); counterText.setText(matchingCount + '/8'); // Apply tint colors to dice based on matching groups applyDiceTints(); } } }; // Add screen tap handler for lanzamiento event game.down = function (x, y, obj) { // Check if enough time has passed since last roll finished var currentTime = Date.now(); var timeSinceLastRoll = currentTime - lastRollFinishTime; // Only allow new roll if not currently rolling AND minimum wait time has passed if (!lanzamiento && timeSinceLastRoll >= minimumWaitTime) { lanzamiento = true; // Start rolling animation for all dice for (var i = 0; i < diceArray.length; i++) { diceArray[i].startRoll(); } } }; }
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Dice = Container.expand(function () {
var self = Container.call(this);
// Add numeric variable valor
self.valor = 1;
// Add rolling animation variables
self.isRolling = false;
self.rollCount = 0;
self.rollTarget = 0;
self.rollTimer = 0;
var diceGraphics = self.attachAsset('Dice' + self.valor, {
anchorX: 0.5,
anchorY: 0.5
});
// Method to update dice visual based on valor
self.updateVisual = function () {
// Create new graphics based on valor first
var newGraphics = self.attachAsset('Dice' + self.valor, {
anchorX: 0.5,
anchorY: 0.5
});
// Remove old graphics after new one is created
self.removeChild(diceGraphics);
// Update reference to new graphics
diceGraphics = newGraphics;
// Add bounce effect when value changes during rolling
if (self.isRolling) {
self.playDiceSound();
diceGraphics.scaleX = 1;
diceGraphics.scaleY = 1;
tween(diceGraphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100,
easing: tween.bounceOut,
onFinish: function onFinish() {
tween(diceGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.bounceOut
});
}
});
}
};
// Method to play dice sound
self.playDiceSound = function () {
LK.getSound('Roll').play();
};
// Method to start rolling animation
self.startRoll = function () {
self.isRolling = true;
self.rollCount = 0;
self.rollTarget = Math.floor(Math.random() * 7) + 6; // 6 to 12 rolls
self.rollTimer = 0;
};
// Update method for rolling animation
self.update = function () {
if (self.isRolling) {
var rollSpeed = Math.floor(self.rollCount * 1.5) + 3; // Start fast, get slower
if (self.rollTimer >= rollSpeed) {
self.valor = Math.floor(Math.random() * 6) + 1;
self.updateVisual();
self.rollCount++;
self.rollTimer = 0;
if (self.rollCount >= self.rollTarget) {
self.isRolling = false;
}
} else {
self.rollTimer++;
}
}
};
return self;
});
/****
* Initialize Game
****/
// Create array to hold all dice
var game = new LK.Game({
backgroundColor: 0xFFFFFF
});
/****
* Game Code
****/
// Create array to hold all dice
var diceArray = [];
// Add lanzamiento boolean variable
var lanzamiento = false;
// Add timer to enforce minimum 1 second wait between rolls
var lastRollFinishTime = 0;
var minimumWaitTime = 1000; // 1 second in milliseconds
// Calculate center positions for two columns
var centerX = 2048 / 2;
var centerY = 2732 / 2;
var columnSpacing = 330; // Space between columns
var rowSpacing = 300; // Space between rows
// Create matching dice counter text
var counterText = new Text2('0/8', {
size: 80,
fill: 0x000000
});
counterText.anchor.set(0.5, 0);
counterText.y = 100; // Move down to make space for status text
LK.gui.top.addChild(counterText);
// Create status text above dice
var statusText = new Text2('Toca para lanzar', {
size: 60,
fill: 0x333333
});
statusText.anchor.set(0.5, 0.5);
statusText.x = centerX;
statusText.y = centerY - 100; // Position above dice grid
game.addChild(statusText);
// Create countdown text
var countdownText = new Text2('', {
size: 50,
fill: 0x666666
});
countdownText.anchor.set(0.5, 0.5);
countdownText.x = centerX;
countdownText.y = centerY - 100; // Position below status text
game.addChild(countdownText);
// Function to count matching dice
function countMatchingDice() {
var counts = {};
// Count occurrences of each dice value
for (var i = 0; i < diceArray.length; i++) {
var value = diceArray[i].valor;
counts[value] = (counts[value] || 0) + 1;
}
// Find the highest count
var maxCount = 0;
for (var value in counts) {
if (counts[value] > maxCount) {
maxCount = counts[value];
}
}
return maxCount;
}
// Function to apply tint colors to dice based on matching groups
function applyDiceTints() {
var counts = {};
// Count occurrences of each dice value
for (var i = 0; i < diceArray.length; i++) {
var value = diceArray[i].valor;
counts[value] = (counts[value] || 0) + 1;
}
// Find the highest count and value
var maxCount = 0;
var maxValue = 0;
for (var value in counts) {
if (counts[value] > maxCount) {
maxCount = counts[value];
maxValue = parseInt(value);
}
}
// Generate random colors for smaller groups
var randomColors = [0xFF6B6B, 0x4ECDC4, 0x45B7D1, 0x96CEB4, 0xFECE00, 0xF38BA8];
var colorIndex = 0;
var usedColors = {};
// Apply tints to all dice
for (var i = 0; i < diceArray.length; i++) {
var dice = diceArray[i];
var value = dice.valor;
if (value == maxValue && counts[value] == maxCount) {
// Largest group gets soft yellow tint
dice.children[0].tint = 0xFFFF99; // Soft yellow
} else if (counts[value] > 1) {
// Smaller matching groups get random colors
if (!usedColors[value]) {
usedColors[value] = randomColors[colorIndex % randomColors.length];
colorIndex++;
}
dice.children[0].tint = usedColors[value];
} else {
// Single dice get no tint (white)
dice.children[0].tint = 0xFFFFFF;
}
}
}
// Create 8 dice in two columns (4 rows each)
for (var col = 0; col < 2; col++) {
for (var row = 0; row < 4; row++) {
var dice = new Dice();
// Assign random valor from 1 to 6
dice.valor = Math.floor(Math.random() * 6) + 1;
// Update visual based on valor
dice.updateVisual();
// Position dice in grid
dice.x = centerX + (col - 0.5) * columnSpacing;
dice.y = centerY + (row - 1.5) * rowSpacing;
// Add to game and array
game.addChild(dice);
diceArray.push(dice);
}
// Game update method to handle dice rolling
game.update = function () {
// Update status and countdown text based on current state
var currentTime = Date.now();
var timeSinceLastRoll = currentTime - lastRollFinishTime;
var timeRemaining = minimumWaitTime - timeSinceLastRoll;
if (lanzamiento) {
// Currently rolling
statusText.setText('Cambiando dados...');
countdownText.setText('');
} else if (timeRemaining > 0) {
// Waiting period - show countdown
statusText.setText('Espera para lanzar');
var secondsRemaining = timeRemaining / 1000;
countdownText.setText(secondsRemaining.toFixed(2) + 's');
} else {
// Ready to roll
statusText.setText('Toca para lanzar');
countdownText.setText('');
}
// Check if all dice have finished rolling
if (lanzamiento) {
var allFinished = true;
for (var i = 0; i < diceArray.length; i++) {
if (diceArray[i].isRolling) {
allFinished = false;
break;
}
}
// Reset lanzamiento when all dice are done
if (allFinished) {
lanzamiento = false;
// Record the time when rolling finished
lastRollFinishTime = Date.now();
// Update counter text with matching dice count
var matchingCount = countMatchingDice();
counterText.setText(matchingCount + '/8');
// Apply tint colors to dice based on matching groups
applyDiceTints();
}
}
};
// Add screen tap handler for lanzamiento event
game.down = function (x, y, obj) {
// Check if enough time has passed since last roll finished
var currentTime = Date.now();
var timeSinceLastRoll = currentTime - lastRollFinishTime;
// Only allow new roll if not currently rolling AND minimum wait time has passed
if (!lanzamiento && timeSinceLastRoll >= minimumWaitTime) {
lanzamiento = true;
// Start rolling animation for all dice
for (var i = 0; i < diceArray.length; i++) {
diceArray[i].startRoll();
}
}
};
}