User prompt
Please fix the bug: 'Script error.' in or related to this line: 'candy2.moveTo(tempGridX1, tempGridY1, 200);' Line Number: 2288 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Şeker patlama sesi çalışmıyor
User prompt
Settings den çıkınca arka planda gözüküyor
User prompt
Settings den çıkınca oyuna girmiyor
User prompt
Menu start basınca oyun geçsin
User prompt
Menuye ayarlar ekle ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Menuyu güzelleştir ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Oyuna menu ekle
User prompt
Kırmızı şeker ekle
User prompt
Sadece yeşil mavi turuncu yeşil sarı şekerler olsun diğerlerini sil
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'candy1.moveTo(tempGridX2, tempGridY2, 200);' Line Number: 1425 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Yer değiştirsiğinde diğer şekerde yer değişsin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Timeout.tick error: grid[writeY][x].moveTo is not a function. (In 'grid[writeY][x].moveTo(x, writeY, animDuration)', 'grid[writeY][x].moveTo' is undefined)' in or related to this line: 'grid[writeY][x].moveTo(x, writeY, animDuration);' Line Number: 1348 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Seviyeleri zorlaştır
User prompt
Seviyeyi zorlaştır
User prompt
Turuncu sarı mavi yeşil kırmızı şekerleri olsun diğer şekerleri kaldır
User prompt
Şekerler turuncu mavi mor yeşil kırmızı olsun
User prompt
Oyunu candy crush saga oynanış tarzına çevir ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Şekerin yeri sadece patlıyacağı zaman değişsin
User prompt
Şekerler sadece 3 yan yana gelirse yeri değişsin
User prompt
Please fix the bug: 'Timeout.tick error: null is not an object (evaluating 'candy1.gridY')' in or related to this line: 'grid[candy1.gridY][candy1.gridX] = candy2;' Line Number: 861
User prompt
Şekerlere şeker resmi koy
User prompt
Patlama sesi çıkmıyor
User prompt
Bölümleri zorlaştır
User prompt
Şekerler patlayınca patlama sesi versin
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Candy = Container.expand(function (type, gridX, gridY, isFrozen) {
var self = Container.call(this);
self.candyType = type;
self.gridX = gridX;
self.gridY = gridY;
self.isMoving = false;
self.isMarkedForDestroy = false;
self.isFrozen = isFrozen || false;
self.frozenHits = self.isFrozen ? 2 : 0; // Frozen candies need 2 hits to break
var candyGraphics = self.attachAsset('candy_' + type, {
anchorX: 0.5,
anchorY: 0.5
});
// Add frozen overlay if candy is frozen
if (self.isFrozen) {
var frozenOverlay = self.attachAsset('frozen_overlay', {
anchorX: 0.5,
anchorY: 0.5
});
frozenOverlay.alpha = 0.6;
// Add ice crystals for visual effect
for (var i = 0; i < 3; i++) {
var crystal = self.attachAsset('ice_crystal', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 80,
y: (Math.random() - 0.5) * 80
});
crystal.alpha = 0.8;
}
}
self.moveTo = function (newGridX, newGridY, duration) {
self.gridX = newGridX;
self.gridY = newGridY;
self.isMoving = true;
var targetX = GRID_START_X + newGridX * CELL_SIZE + CELL_SIZE / 2;
var targetY = GRID_START_Y + newGridY * CELL_SIZE + CELL_SIZE / 2;
tween(self, {
x: targetX,
y: targetY
}, {
duration: duration || 300,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isMoving = false;
}
});
};
self.hitFrozen = function () {
if (!self.isFrozen) return false;
self.frozenHits--;
LK.getSound('ice_break').play();
// Visual feedback for hit
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
// If all hits used, unfreeze the candy
if (self.frozenHits <= 0) {
self.isFrozen = false;
// Remove frozen overlay (assuming it's the last child)
var childrenToRemove = [];
for (var i = 1; i < self.children.length; i++) {
childrenToRemove.push(self.children[i]);
}
for (var j = 0; j < childrenToRemove.length; j++) {
self.removeChild(childrenToRemove[j]);
}
return true; // Candy is now unfrozen and can be matched
}
return false; // Still frozen
};
self.destroy = function () {
self.isMarkedForDestroy = true;
tween(self, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 200,
easing: tween.easeIn,
onFinish: function onFinish() {
if (self.parent) {
self.parent.removeChild(self);
}
}
});
};
return self;
});
var GridCell = Container.expand(function (gridX, gridY) {
var self = Container.call(this);
self.gridX = gridX;
self.gridY = gridY;
var cellGraphics = self.attachAsset('grid_cell', {
anchorX: 0.5,
anchorY: 0.5
});
cellGraphics.alpha = 0.3;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2a1810
});
/****
* Game Code
****/
// Decorative elements
// Beautiful gradient background layers
// Create beautiful gradient background
var backgroundContainer = new Container();
game.addChild(backgroundContainer);
// Create multiple layers for depth
var bgLayer1 = LK.getAsset('bg_gradient1', {
width: 2048,
height: 2732,
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
var bgLayer2 = LK.getAsset('bg_gradient2', {
width: 2048,
height: 2732,
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
var bgLayer3 = LK.getAsset('bg_pattern', {
width: 2048,
height: 2732,
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
backgroundContainer.addChild(bgLayer1);
backgroundContainer.addChild(bgLayer2);
backgroundContainer.addChild(bgLayer3);
// Set transparency for layering effect
bgLayer2.alpha = 0.7;
bgLayer3.alpha = 0.3;
var GRID_WIDTH = 10;
var GRID_HEIGHT = 10;
var CELL_SIZE = 150;
var GRID_START_X = (2048 - GRID_WIDTH * CELL_SIZE) / 2;
var GRID_START_Y = 650;
var CANDY_TYPES = ['red', 'blue', 'green', 'yellow', 'purple', 'orange'];
var grid = [];
var candies = [];
var selectedCandy = null;
var draggedCandy = null;
var isDragging = false;
var dragStartX = 0;
var dragStartY = 0;
var movesLeft = 20;
var currentScore = 0;
var targetScore = 1000;
var isProcessing = false;
var currentLevel = 1;
var maxLevel = 1;
var frozenCandies = []; // Track frozen candies that need multiple hits
// Level configurations - significantly more challenging
var levelConfigs = [{
level: 1,
targetScore: 1200,
moves: 18,
gridSize: 10
}, {
level: 2,
targetScore: 1800,
moves: 16,
gridSize: 10
}, {
level: 3,
targetScore: 2500,
moves: 14,
gridSize: 10
}, {
level: 4,
targetScore: 3200,
moves: 13,
gridSize: 10
}, {
level: 5,
targetScore: 4000,
moves: 12,
gridSize: 10
}, {
level: 6,
targetScore: 4800,
moves: 11,
gridSize: 10
}, {
level: 7,
targetScore: 5600,
moves: 10,
gridSize: 10
}, {
level: 8,
targetScore: 6500,
moves: 9,
gridSize: 10
}, {
level: 9,
targetScore: 7500,
moves: 8,
gridSize: 10
}, {
level: 10,
targetScore: 8500,
moves: 8,
gridSize: 10
}];
// Initialize grid cells
for (var y = 0; y < GRID_HEIGHT; y++) {
grid[y] = [];
for (var x = 0; x < GRID_WIDTH; x++) {
var cell = new GridCell(x, y);
cell.x = GRID_START_X + x * CELL_SIZE + CELL_SIZE / 2;
cell.y = GRID_START_Y + y * CELL_SIZE + CELL_SIZE / 2;
game.addChild(cell);
grid[y][x] = null;
}
}
// UI Elements - Score with button background
var scoreButtonBorder = LK.getAsset('score_button_border', {
anchorX: 0.5,
anchorY: 0.5
});
var scoreButtonBg = LK.getAsset('score_button_bg', {
anchorX: 0.5,
anchorY: 0.5
});
var scoreButtonHighlight = LK.getAsset('score_button_highlight', {
anchorX: 0.5,
anchorY: 0.5
});
// Create score button container
var scoreButtonContainer = new Container();
scoreButtonContainer.addChild(scoreButtonBorder);
scoreButtonContainer.addChild(scoreButtonBg);
scoreButtonContainer.addChild(scoreButtonHighlight);
// Position button elements
scoreButtonBorder.y = 0;
scoreButtonBg.y = -2;
scoreButtonHighlight.y = -5;
scoreButtonHighlight.alpha = 0.6;
// Add gradient effect with tween
tween(scoreButtonHighlight, {
alpha: 0.3
}, {
duration: 2000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(scoreButtonHighlight, {
alpha: 0.6
}, {
duration: 2000,
easing: tween.easeInOut
});
}
});
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0.5);
scoreButtonContainer.addChild(scoreText);
LK.gui.top.addChild(scoreButtonContainer);
scoreButtonContainer.y = 90;
// UI Elements - Moves with button background
var movesButtonBorder = LK.getAsset('score_button_border', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
var movesButtonBg = LK.getAsset('score_button_bg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
var movesButtonHighlight = LK.getAsset('score_button_highlight', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
// Create moves button container
var movesButtonContainer = new Container();
movesButtonContainer.addChild(movesButtonBorder);
movesButtonContainer.addChild(movesButtonBg);
movesButtonContainer.addChild(movesButtonHighlight);
// Position button elements
movesButtonBorder.y = 0;
movesButtonBg.y = -2;
movesButtonHighlight.y = -5;
movesButtonHighlight.alpha = 0.6;
// Add gradient effect with tween
tween(movesButtonHighlight, {
alpha: 0.3
}, {
duration: 2200,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(movesButtonHighlight, {
alpha: 0.6
}, {
duration: 2200,
easing: tween.easeInOut
});
}
});
var movesText = new Text2('Moves: ' + movesLeft, {
size: 50,
fill: 0xFFFFFF
});
movesText.anchor.set(0.5, 0.5);
movesButtonContainer.addChild(movesText);
LK.gui.top.addChild(movesButtonContainer);
movesButtonContainer.y = 180;
// UI Elements - Target with button background
var targetButtonBorder = LK.getAsset('score_button_border', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
var targetButtonBg = LK.getAsset('score_button_bg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
var targetButtonHighlight = LK.getAsset('score_button_highlight', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
// Create target button container
var targetButtonContainer = new Container();
targetButtonContainer.addChild(targetButtonBorder);
targetButtonContainer.addChild(targetButtonBg);
targetButtonContainer.addChild(targetButtonHighlight);
// Position button elements
targetButtonBorder.y = 0;
targetButtonBg.y = -2;
targetButtonHighlight.y = -5;
targetButtonHighlight.alpha = 0.6;
// Add gradient effect with tween
tween(targetButtonHighlight, {
alpha: 0.3
}, {
duration: 2400,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(targetButtonHighlight, {
alpha: 0.6
}, {
duration: 2400,
easing: tween.easeInOut
});
}
});
var targetText = new Text2('Target: ' + targetScore, {
size: 40,
fill: 0xFFDD44
});
targetText.anchor.set(0.5, 0.5);
targetButtonContainer.addChild(targetText);
LK.gui.top.addChild(targetButtonContainer);
targetButtonContainer.y = 260;
// UI Elements - Level with button background
var levelButtonBorder = LK.getAsset('score_button_border', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
var levelButtonBg = LK.getAsset('score_button_bg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
var levelButtonHighlight = LK.getAsset('score_button_highlight', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
// Create level button container
var levelButtonContainer = new Container();
levelButtonContainer.addChild(levelButtonBorder);
levelButtonContainer.addChild(levelButtonBg);
levelButtonContainer.addChild(levelButtonHighlight);
// Position button elements
levelButtonBorder.y = 0;
levelButtonBg.y = -2;
levelButtonHighlight.y = -5;
levelButtonHighlight.alpha = 0.6;
// Add gradient effect with tween
tween(levelButtonHighlight, {
alpha: 0.3
}, {
duration: 2600,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(levelButtonHighlight, {
alpha: 0.6
}, {
duration: 2600,
easing: tween.easeInOut
});
}
});
var levelText = new Text2('Level: ' + currentLevel, {
size: 50,
fill: 0x00FF00
});
levelText.anchor.set(0.5, 0.5);
levelButtonContainer.addChild(levelText);
LK.gui.top.addChild(levelButtonContainer);
levelButtonContainer.y = 330;
function getRandomCandyType() {
return CANDY_TYPES[Math.floor(Math.random() * CANDY_TYPES.length)];
}
function getAvailableCandyTypes(level) {
// Progressively reduce available candy types to increase difficulty
switch (level) {
case 1:
case 2:
return CANDY_TYPES;
// All 6 types available
case 3:
case 4:
return CANDY_TYPES.slice(0, 5);
// 5 types available
case 5:
case 6:
return CANDY_TYPES.slice(0, 4);
// 4 types available
case 7:
case 8:
return CANDY_TYPES.slice(0, 3);
// 3 types available
case 9:
case 10:
return CANDY_TYPES.slice(0, 3);
// 3 types available
default:
// For higher levels, alternate between 3 and 4 types
return level % 2 === 0 ? CANDY_TYPES.slice(0, 3) : CANDY_TYPES.slice(0, 4);
}
}
function loadProgress() {
var savedLevel = storage.currentLevel;
var savedMaxLevel = storage.maxLevel;
if (savedLevel) {
currentLevel = parseInt(savedLevel);
}
if (savedMaxLevel) {
maxLevel = parseInt(savedMaxLevel);
}
}
function saveProgress() {
storage.currentLevel = currentLevel.toString();
storage.maxLevel = maxLevel.toString();
}
function getCurrentLevelConfig() {
if (currentLevel <= levelConfigs.length) {
return levelConfigs[currentLevel - 1];
}
// For levels beyond predefined configs, generate exponentially harder difficulty
var baseScore = 8500;
var levelMultiplier = currentLevel - 10;
var exponentialIncrease = Math.pow(1.3, levelMultiplier); // 30% increase per level
var targetScore = Math.floor(baseScore * exponentialIncrease);
var moves = Math.max(6, 8 - Math.floor(levelMultiplier / 3)); // Reduce moves more aggressively
return {
level: currentLevel,
targetScore: targetScore,
moves: moves,
gridSize: 10
};
}
function initializeLevel() {
var config = getCurrentLevelConfig();
targetScore = config.targetScore;
movesLeft = config.moves;
currentScore = 0;
// Update UI
levelText.setText('Level: ' + currentLevel);
scoreText.setText('Score: 0');
movesText.setText('Moves: ' + movesLeft);
targetText.setText('Target: ' + targetScore);
// Clear existing candies
for (var i = candies.length - 1; i >= 0; i--) {
var candy = candies[i];
if (candy.parent) {
candy.parent.removeChild(candy);
}
}
candies = [];
// Reset grid
for (var y = 0; y < GRID_HEIGHT; y++) {
for (var x = 0; x < GRID_WIDTH; x++) {
grid[y][x] = null;
}
}
// Initialize new grid
initializeGrid();
}
function completeLevel() {
if (currentLevel >= maxLevel) {
maxLevel = currentLevel + 1;
}
currentLevel++;
saveProgress();
// Show level complete message briefly before starting next level
var levelCompleteText = new Text2('Level Complete!', {
size: 80,
fill: 0x00FF00
});
levelCompleteText.anchor.set(0.5, 0.5);
levelCompleteText.x = 2048 / 2;
levelCompleteText.y = 2732 / 2;
game.addChild(levelCompleteText);
// Animate text
levelCompleteText.scaleX = 0;
levelCompleteText.scaleY = 0;
tween(levelCompleteText, {
scaleX: 1,
scaleY: 1,
alpha: 1
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(levelCompleteText, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 500,
delay: 1000,
easing: tween.easeIn,
onFinish: function onFinish() {
if (levelCompleteText.parent) {
levelCompleteText.parent.removeChild(levelCompleteText);
}
initializeLevel();
}
});
}
});
}
function createCandy(x, y, type, isFrozen) {
type = type || getRandomCandyType();
var candy = new Candy(type, x, y, isFrozen);
candy.x = GRID_START_X + x * CELL_SIZE + CELL_SIZE / 2;
candy.y = GRID_START_Y + y * CELL_SIZE + CELL_SIZE / 2;
game.addChild(candy);
candies.push(candy);
grid[y][x] = candy;
if (isFrozen) {
frozenCandies.push(candy);
}
return candy;
}
function getLevelSpecificCandyType(x, y, level) {
// Get available candy types based on level - fewer types = harder
var availableTypes = getAvailableCandyTypes(level);
function getRandomFromAvailable() {
return availableTypes[Math.floor(Math.random() * availableTypes.length)];
}
// Define specific patterns for each level with increased difficulty
switch (level) {
case 1:
// Level 1: More red and blue candies in corners
if (x < 3 && y < 3 || x > 6 && y > 6) {
return Math.random() < 0.6 ? Math.random() < 0.5 ? 'red' : 'blue' : getRandomFromAvailable();
}
break;
case 2:
// Level 2: Checkerboard pattern influence with green and yellow
if ((x + y) % 2 === 0) {
return Math.random() < 0.6 ? Math.random() < 0.5 ? 'green' : 'yellow' : getRandomFromAvailable();
}
break;
case 3:
// Level 3: Center focus with purple and orange (fewer types available)
var centerDistance = Math.abs(x - 4.5) + Math.abs(y - 4.5);
if (centerDistance < 4) {
return Math.random() < 0.8 ? Math.random() < 0.5 ? 'purple' : 'orange' : getRandomFromAvailable();
}
break;
case 4:
// Level 4: Diagonal pattern with red and green (more concentrated)
if (Math.abs(x - y) < 2 || Math.abs(x + y - 9) < 2) {
return Math.random() < 0.8 ? Math.random() < 0.5 ? 'red' : 'green' : getRandomFromAvailable();
}
break;
case 5:
// Level 5: Border emphasis with blue and yellow (very concentrated)
if (x < 2 || x > 7 || y < 2 || y > 7) {
return Math.random() < 0.9 ? Math.random() < 0.5 ? 'blue' : 'yellow' : getRandomFromAvailable();
}
break;
case 6:
// Level 6: Cross pattern with purple and red (extremely concentrated)
if (x === 4 || x === 5 || y === 4 || y === 5) {
return Math.random() < 0.95 ? Math.random() < 0.5 ? 'purple' : 'red' : getRandomFromAvailable();
}
break;
case 7:
// Level 7: Ring pattern with orange and green (max concentration)
var ringDistance = Math.max(Math.abs(x - 4.5), Math.abs(y - 4.5));
if (ringDistance > 2 && ringDistance < 5) {
return Math.random() < 0.95 ? Math.random() < 0.5 ? 'orange' : 'green' : getRandomFromAvailable();
}
break;
case 8:
// Level 8: Spiral influence with blue and purple (only 3 types available)
var spiralValue = (x * 3 + y * 2) % 7;
if (spiralValue < 3) {
return Math.random() < 0.9 ? Math.random() < 0.5 ? 'blue' : 'purple' : getRandomFromAvailable();
}
break;
case 9:
// Level 9: Scattered clusters with yellow and red (only 3 types available)
if (x % 3 === 0 && y % 3 === 0 || x % 3 === 2 && y % 3 === 2) {
return Math.random() < 0.95 ? Math.random() < 0.5 ? 'yellow' : 'red' : getRandomFromAvailable();
}
break;
case 10:
// Level 10: Complex pattern (only 3 types available, maximum difficulty)
if ((x + y) % 4 < 2) {
return Math.random() < 0.98 ? Math.random() < 0.5 ? 'green' : 'orange' : getRandomFromAvailable();
}
break;
default:
// For levels beyond 10, create dynamic patterns with maximum difficulty
var patternType = level % 5;
var restrictedTypes = availableTypes.slice(0, Math.max(2, 4 - Math.floor(level / 15))); // Even fewer types for higher levels
switch (patternType) {
case 0:
// Diagonal emphasis
if (Math.abs(x - y) < 3) {
return Math.random() < 0.95 ? restrictedTypes[level % restrictedTypes.length] : getRandomFromAvailable();
}
break;
case 1:
// Corner concentration
if (x < 3 && y < 3 || x > 6 && y > 6 || x < 3 && y > 6 || x > 6 && y < 3) {
return Math.random() < 0.95 ? restrictedTypes[(level + 1) % restrictedTypes.length] : getRandomFromAvailable();
}
break;
case 2:
// Center ring
var centerDist = Math.max(Math.abs(x - 4.5), Math.abs(y - 4.5));
if (centerDist > 1 && centerDist < 4) {
return Math.random() < 0.95 ? restrictedTypes[(level + 2) % restrictedTypes.length] : getRandomFromAvailable();
}
break;
case 3:
// Checkerboard influence
if ((x + y + level) % 3 === 0) {
return Math.random() < 0.95 ? restrictedTypes[(level + 3) % restrictedTypes.length] : getRandomFromAvailable();
}
break;
case 4:
// Random clusters
if ((x * y + level) % 11 < 4) {
return Math.random() < 0.95 ? restrictedTypes[(level + 4) % restrictedTypes.length] : getRandomFromAvailable();
}
break;
}
break;
}
return getRandomFromAvailable();
}
function initializeGrid() {
// Clear frozen candies array
frozenCandies = [];
for (var y = 0; y < GRID_HEIGHT; y++) {
for (var x = 0; x < GRID_WIDTH; x++) {
var type;
var attempts = 0;
do {
// Use level-specific candy type generation
type = getLevelSpecificCandyType(x, y, currentLevel);
attempts++;
if (attempts > 10) {
// Fallback to completely random if level pattern is too restrictive
type = getRandomCandyType();
break;
}
} while (wouldCreateMatch(x, y, type));
// Determine if this candy should be frozen based on level
var shouldBeFrozen = shouldCandyBeFrozen(x, y, currentLevel);
createCandy(x, y, type, shouldBeFrozen);
}
}
}
function shouldCandyBeFrozen(x, y, level) {
// Start adding frozen candies from level 4
if (level < 4) return false;
// Increase frozen candy probability with level
var frozenProbability = Math.min(0.15, (level - 3) * 0.02); // Max 15% frozen
// Add specific frozen patterns for higher levels
if (level >= 6) {
// Corners are more likely to be frozen
if (x < 2 && y < 2 || x > 7 && y < 2 || x < 2 && y > 7 || x > 7 && y > 7) {
frozenProbability += 0.3;
}
}
if (level >= 8) {
// Center cross pattern more likely to be frozen
if ((x === 4 || x === 5) && (y === 4 || y === 5)) {
frozenProbability += 0.4;
}
}
return Math.random() < frozenProbability;
}
function wouldCreateMatch(x, y, type) {
var horizontalCount = 1;
var verticalCount = 1;
// Check horizontal
var i = x - 1;
while (i >= 0 && grid[y][i] && grid[y][i].candyType === type) {
horizontalCount++;
i--;
}
i = x + 1;
while (i < GRID_WIDTH && grid[y][i] && grid[y][i].candyType === type) {
horizontalCount++;
i++;
}
// Check vertical
i = y - 1;
while (i >= 0 && grid[i][x] && grid[i][x].candyType === type) {
verticalCount++;
i--;
}
i = y + 1;
while (i < GRID_HEIGHT && grid[i][x] && grid[i][x].candyType === type) {
verticalCount++;
i++;
}
return horizontalCount >= 3 || verticalCount >= 3;
}
function findMatches() {
var matches = [];
var processed = [];
for (var y = 0; y < GRID_HEIGHT; y++) {
processed[y] = [];
for (var x = 0; x < GRID_WIDTH; x++) {
processed[y][x] = false;
}
}
// Find horizontal matches
for (var y = 0; y < GRID_HEIGHT; y++) {
for (var x = 0; x < GRID_WIDTH - 2; x++) {
if (!grid[y][x] || processed[y][x]) continue;
var type = grid[y][x].candyType;
var matchLength = 1;
var startX = x;
while (x + matchLength < GRID_WIDTH && grid[y][x + matchLength] && grid[y][x + matchLength].candyType === type) {
matchLength++;
}
if (matchLength >= 3) {
for (var i = 0; i < matchLength; i++) {
if (!processed[y][startX + i]) {
var candy = grid[y][startX + i];
// Handle frozen candies - they need to be hit but may not be destroyed
if (candy.isFrozen) {
if (candy.hitFrozen()) {
// Candy is now unfrozen and can be matched
matches.push(candy);
processed[y][startX + i] = true;
}
// If still frozen, don't add to matches but mark as processed
processed[y][startX + i] = true;
} else {
matches.push(candy);
processed[y][startX + i] = true;
}
}
}
}
}
}
// Find vertical matches
for (var x = 0; x < GRID_WIDTH; x++) {
for (var y = 0; y < GRID_HEIGHT - 2; y++) {
if (!grid[y][x] || processed[y][x]) continue;
var type = grid[y][x].candyType;
var matchLength = 1;
var startY = y;
while (y + matchLength < GRID_HEIGHT && grid[y + matchLength][x] && grid[y + matchLength][x].candyType === type) {
matchLength++;
}
if (matchLength >= 3) {
for (var i = 0; i < matchLength; i++) {
if (!processed[startY + i][x]) {
var candy = grid[startY + i][x];
// Handle frozen candies - they need to be hit but may not be destroyed
if (candy.isFrozen) {
if (candy.hitFrozen()) {
// Candy is now unfrozen and can be matched
matches.push(candy);
processed[startY + i][x] = true;
}
// If still frozen, don't add to matches but mark as processed
processed[startY + i][x] = true;
} else {
matches.push(candy);
processed[startY + i][x] = true;
}
}
}
}
}
}
return matches;
}
function createExplosionEffect(x, y) {
// Create multiple particles for explosion effect
var particleCount = 8 + Math.floor(Math.random() * 4);
for (var i = 0; i < particleCount; i++) {
var particle = LK.getAsset('explosion_particle', {
anchorX: 0.5,
anchorY: 0.5,
x: x,
y: y,
scaleX: 0.8 + Math.random() * 0.4,
scaleY: 0.8 + Math.random() * 0.4
});
game.addChild(particle);
// Random direction and distance
var angle = Math.PI * 2 * i / particleCount + (Math.random() - 0.5) * 0.5;
var distance = 60 + Math.random() * 40;
var targetX = x + Math.cos(angle) * distance;
var targetY = y + Math.sin(angle) * distance;
// Animate particle explosion
tween(particle, {
x: targetX,
y: targetY,
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 400 + Math.random() * 200,
easing: tween.easeOut,
onFinish: function onFinish() {
if (particle.parent) {
particle.parent.removeChild(particle);
}
}
});
}
// Create star particles for extra sparkle
var starCount = 4 + Math.floor(Math.random() * 3);
for (var j = 0; j < starCount; j++) {
var star = LK.getAsset('explosion_star', {
anchorX: 0.5,
anchorY: 0.5,
x: x + (Math.random() - 0.5) * 40,
y: y + (Math.random() - 0.5) * 40,
rotation: Math.random() * Math.PI * 2
});
game.addChild(star);
// Animate star particles
tween(star, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0,
rotation: star.rotation + Math.PI * 2
}, {
duration: 600,
easing: tween.easeOut,
onFinish: function onFinish() {
if (star.parent) {
star.parent.removeChild(star);
}
}
});
}
}
function clearMatches(matches) {
if (matches.length === 0) return;
// Play explosion sound when candies are cleared
LK.getSound('explosion').play();
LK.getSound('match').play();
// Handle matches
currentScore += matches.length * 50;
scoreText.setText('Score: ' + currentScore);
for (var i = 0; i < matches.length; i++) {
var candy = matches[i];
// Create explosion effect at candy position
createExplosionEffect(candy.x, candy.y);
grid[candy.gridY][candy.gridX] = null;
candy.destroy();
// Remove from candies array
var index = candies.indexOf(candy);
if (index > -1) {
candies.splice(index, 1);
}
}
}
function applyGravity() {
var moved = false;
for (var x = 0; x < GRID_WIDTH; x++) {
var writeY = GRID_HEIGHT - 1;
for (var y = GRID_HEIGHT - 1; y >= 0; y--) {
if (grid[y][x] && !grid[y][x].isMarkedForDestroy) {
if (y !== writeY) {
grid[writeY][x] = grid[y][x];
grid[y][x] = null;
grid[writeY][x].moveTo(x, writeY, 200);
moved = true;
}
writeY--;
}
}
// Fill empty spaces at top
for (var emptyY = writeY; emptyY >= 0; emptyY--) {
var newCandy = createCandy(x, emptyY, getRandomCandyType());
newCandy.y = GRID_START_Y - (writeY - emptyY + 1) * CELL_SIZE + CELL_SIZE / 2;
newCandy.moveTo(x, emptyY, 300);
moved = true;
}
}
return moved;
}
function areAdjacent(candy1, candy2) {
var dx = Math.abs(candy1.gridX - candy2.gridX);
var dy = Math.abs(candy1.gridY - candy2.gridY);
return dx === 1 && dy === 0 || dx === 0 && dy === 1;
}
function swapCandies(candy1, candy2) {
// Swap in grid
grid[candy1.gridY][candy1.gridX] = candy2;
grid[candy2.gridY][candy2.gridX] = candy1;
// Swap positions
var tempX = candy1.gridX;
var tempY = candy1.gridY;
candy1.moveTo(candy2.gridX, candy2.gridY, 200);
candy2.moveTo(tempX, tempY, 200);
}
function processMatches() {
if (isProcessing) return;
isProcessing = true;
LK.setTimeout(function () {
var matches = findMatches();
if (matches.length > 0) {
clearMatches(matches);
LK.setTimeout(function () {
if (applyGravity()) {
LK.setTimeout(function () {
isProcessing = false;
processMatches(); // Check for cascading matches
}, 400);
} else {
isProcessing = false;
checkGameState();
}
}, 300);
} else {
isProcessing = false;
checkGameState();
}
}, 100);
}
function checkGameState() {
if (currentScore >= targetScore) {
completeLevel();
return;
}
if (movesLeft <= 0) {
LK.showGameOver();
return;
}
}
game.down = function (x, y, obj) {
if (isProcessing) return;
var gridX = Math.floor((x - GRID_START_X) / CELL_SIZE);
var gridY = Math.floor((y - GRID_START_Y) / CELL_SIZE);
if (gridX < 0 || gridX >= GRID_WIDTH || gridY < 0 || gridY >= GRID_HEIGHT) {
selectedCandy = null;
return;
}
var clickedCandy = grid[gridY][gridX];
if (!clickedCandy || clickedCandy.isMoving) {
selectedCandy = null;
return;
}
// Start drag functionality
draggedCandy = clickedCandy;
isDragging = false;
dragStartX = x;
dragStartY = y;
if (selectedCandy === null) {
selectedCandy = clickedCandy;
selectedCandy.scaleX = 1.1;
selectedCandy.scaleY = 1.1;
} else if (selectedCandy === clickedCandy) {
selectedCandy.scaleX = 1.0;
selectedCandy.scaleY = 1.0;
selectedCandy = null;
} else if (areAdjacent(selectedCandy, clickedCandy)) {
selectedCandy.scaleX = 1.0;
selectedCandy.scaleY = 1.0;
// Try swap
swapCandies(selectedCandy, clickedCandy);
LK.getSound('swap').play();
LK.setTimeout(function () {
var matches = findMatches();
if (matches.length > 0) {
movesLeft--;
movesText.setText('Moves: ' + movesLeft);
processMatches();
} else {
// Swap back if no matches
swapCandies(selectedCandy, clickedCandy);
}
selectedCandy = null;
}, 250);
} else {
selectedCandy.scaleX = 1.0;
selectedCandy.scaleY = 1.0;
selectedCandy = clickedCandy;
selectedCandy.scaleX = 1.1;
selectedCandy.scaleY = 1.1;
}
};
game.move = function (x, y, obj) {
if (!draggedCandy || isProcessing) return;
var dragDistance = Math.sqrt((x - dragStartX) * (x - dragStartX) + (y - dragStartY) * (y - dragStartY));
if (dragDistance > 30 && !isDragging) {
isDragging = true;
// Scale up dragged candy for visual feedback
tween(draggedCandy, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 150,
easing: tween.easeOut
});
}
if (isDragging) {
// Move candy with finger/mouse
draggedCandy.x = GRID_START_X + draggedCandy.gridX * CELL_SIZE + CELL_SIZE / 2 + (x - dragStartX);
draggedCandy.y = GRID_START_Y + draggedCandy.gridY * CELL_SIZE + CELL_SIZE / 2 + (y - dragStartY);
}
};
game.up = function (x, y, obj) {
if (!draggedCandy) return;
if (isDragging) {
// Reset candy visual state
tween(draggedCandy, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 150,
easing: tween.easeOut
});
// Determine target grid position based on drag direction
var deltaX = x - dragStartX;
var deltaY = y - dragStartY;
var targetGridX = draggedCandy.gridX;
var targetGridY = draggedCandy.gridY;
// Check drag direction and distance
if (Math.abs(deltaX) > Math.abs(deltaY)) {
// Horizontal drag
if (Math.abs(deltaX) > 50) {
if (deltaX > 0 && draggedCandy.gridX < GRID_WIDTH - 1) {
targetGridX = draggedCandy.gridX + 1;
} else if (deltaX < 0 && draggedCandy.gridX > 0) {
targetGridX = draggedCandy.gridX - 1;
}
}
} else {
// Vertical drag
if (Math.abs(deltaY) > 50) {
if (deltaY > 0 && draggedCandy.gridY < GRID_HEIGHT - 1) {
targetGridY = draggedCandy.gridY + 1;
} else if (deltaY < 0 && draggedCandy.gridY > 0) {
targetGridY = draggedCandy.gridY - 1;
}
}
}
// Reset candy position
draggedCandy.x = GRID_START_X + draggedCandy.gridX * CELL_SIZE + CELL_SIZE / 2;
draggedCandy.y = GRID_START_Y + draggedCandy.gridY * CELL_SIZE + CELL_SIZE / 2;
// Perform swap if valid target
if ((targetGridX !== draggedCandy.gridX || targetGridY !== draggedCandy.gridY) && targetGridX >= 0 && targetGridX < GRID_WIDTH && targetGridY >= 0 && targetGridY < GRID_HEIGHT) {
var targetCandy = grid[targetGridY][targetGridX];
if (targetCandy && !targetCandy.isMoving) {
// Clear any previous selection
if (selectedCandy) {
selectedCandy.scaleX = 1.0;
selectedCandy.scaleY = 1.0;
}
// Perform swap
swapCandies(draggedCandy, targetCandy);
LK.getSound('swap').play();
LK.setTimeout(function () {
var matches = findMatches();
if (matches.length > 0) {
movesLeft--;
movesText.setText('Moves: ' + movesLeft);
processMatches();
} else {
// Swap back if no matches
swapCandies(draggedCandy, targetCandy);
}
}, 250);
}
}
}
// Reset drag state
draggedCandy = null;
isDragging = false;
selectedCandy = null;
};
// Add decorative candy elements floating in background
var decorations = [];
for (var i = 0; i < 8; i++) {
var decoration = LK.getAsset('candy_decoration', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * 2048,
y: Math.random() * 2732,
scaleX: 0.5 + Math.random() * 0.5,
scaleY: 0.5 + Math.random() * 0.5
});
decoration.alpha = 0.2 + Math.random() * 0.3;
game.addChild(decoration);
decorations.push(decoration);
// Animate floating motion
var animDuration = 3000 + Math.random() * 2000;
var targetY = decoration.y + (Math.random() - 0.5) * 400;
tween(decoration, {
y: targetY,
rotation: Math.random() * Math.PI * 2
}, {
duration: animDuration,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Restart animation
var newTargetY = decoration.y + (Math.random() - 0.5) * 400;
tween(decoration, {
y: newTargetY,
rotation: decoration.rotation + Math.PI * 2
}, {
duration: animDuration,
easing: tween.easeInOut
});
}
});
}
// Add sparkle effects
var sparkles = [];
for (var j = 0; j < 15; j++) {
var sparkle = LK.getAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * 2048,
y: Math.random() * 2732,
scaleX: 0.3 + Math.random() * 0.4,
scaleY: 0.3 + Math.random() * 0.4
});
sparkle.alpha = 0.4 + Math.random() * 0.6;
game.addChild(sparkle);
sparkles.push(sparkle);
// Twinkling animation
var twinkleDuration = 1000 + Math.random() * 1500;
tween(sparkle, {
alpha: 0.1,
scaleX: sparkle.scaleX * 0.5,
scaleY: sparkle.scaleY * 0.5
}, {
duration: twinkleDuration,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(sparkle, {
alpha: 0.4 + Math.random() * 0.6,
scaleX: 0.3 + Math.random() * 0.4,
scaleY: 0.3 + Math.random() * 0.4
}, {
duration: twinkleDuration,
easing: tween.easeInOut
});
}
});
}
// Initialize the game
loadProgress();
initializeLevel(); ===================================================================
--- original.js
+++ change.js
@@ -6,19 +6,39 @@
/****
* Classes
****/
-var Candy = Container.expand(function (type, gridX, gridY) {
+var Candy = Container.expand(function (type, gridX, gridY, isFrozen) {
var self = Container.call(this);
self.candyType = type;
self.gridX = gridX;
self.gridY = gridY;
self.isMoving = false;
self.isMarkedForDestroy = false;
+ self.isFrozen = isFrozen || false;
+ self.frozenHits = self.isFrozen ? 2 : 0; // Frozen candies need 2 hits to break
var candyGraphics = self.attachAsset('candy_' + type, {
anchorX: 0.5,
anchorY: 0.5
});
+ // Add frozen overlay if candy is frozen
+ if (self.isFrozen) {
+ var frozenOverlay = self.attachAsset('frozen_overlay', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ frozenOverlay.alpha = 0.6;
+ // Add ice crystals for visual effect
+ for (var i = 0; i < 3; i++) {
+ var crystal = self.attachAsset('ice_crystal', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: (Math.random() - 0.5) * 80,
+ y: (Math.random() - 0.5) * 80
+ });
+ crystal.alpha = 0.8;
+ }
+ }
self.moveTo = function (newGridX, newGridY, duration) {
self.gridX = newGridX;
self.gridY = newGridY;
self.isMoving = true;
@@ -34,8 +54,44 @@
self.isMoving = false;
}
});
};
+ self.hitFrozen = function () {
+ if (!self.isFrozen) return false;
+ self.frozenHits--;
+ LK.getSound('ice_break').play();
+ // Visual feedback for hit
+ tween(self, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 100,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(self, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 100,
+ easing: tween.easeIn
+ });
+ }
+ });
+ // If all hits used, unfreeze the candy
+ if (self.frozenHits <= 0) {
+ self.isFrozen = false;
+ // Remove frozen overlay (assuming it's the last child)
+ var childrenToRemove = [];
+ for (var i = 1; i < self.children.length; i++) {
+ childrenToRemove.push(self.children[i]);
+ }
+ for (var j = 0; j < childrenToRemove.length; j++) {
+ self.removeChild(childrenToRemove[j]);
+ }
+ return true; // Candy is now unfrozen and can be matched
+ }
+ return false; // Still frozen
+ };
self.destroy = function () {
self.isMarkedForDestroy = true;
tween(self, {
scaleX: 0,
@@ -74,11 +130,11 @@
/****
* Game Code
****/
-// Create beautiful gradient background
-// Beautiful gradient background layers
// Decorative elements
+// Beautiful gradient background layers
+// Create beautiful gradient background
var backgroundContainer = new Container();
game.addChild(backgroundContainer);
// Create multiple layers for depth
var bgLayer1 = LK.getAsset('bg_gradient1', {
@@ -129,58 +185,59 @@
var targetScore = 1000;
var isProcessing = false;
var currentLevel = 1;
var maxLevel = 1;
-// Level configurations
+var frozenCandies = []; // Track frozen candies that need multiple hits
+// Level configurations - significantly more challenging
var levelConfigs = [{
level: 1,
- targetScore: 1000,
- moves: 20,
+ targetScore: 1200,
+ moves: 18,
gridSize: 10
}, {
level: 2,
- targetScore: 1500,
- moves: 18,
+ targetScore: 1800,
+ moves: 16,
gridSize: 10
}, {
level: 3,
- targetScore: 2000,
- moves: 16,
+ targetScore: 2500,
+ moves: 14,
gridSize: 10
}, {
level: 4,
- targetScore: 2500,
- moves: 15,
+ targetScore: 3200,
+ moves: 13,
gridSize: 10
}, {
level: 5,
- targetScore: 3000,
- moves: 14,
+ targetScore: 4000,
+ moves: 12,
gridSize: 10
}, {
level: 6,
- targetScore: 3500,
- moves: 13,
+ targetScore: 4800,
+ moves: 11,
gridSize: 10
}, {
level: 7,
- targetScore: 4000,
- moves: 12,
+ targetScore: 5600,
+ moves: 10,
gridSize: 10
}, {
level: 8,
- targetScore: 4500,
- moves: 11,
+ targetScore: 6500,
+ moves: 9,
gridSize: 10
}, {
level: 9,
- targetScore: 5000,
- moves: 10,
+ targetScore: 7500,
+ moves: 8,
gridSize: 10
}, {
level: 10,
- targetScore: 6000,
- moves: 10,
+ targetScore: 8500,
+ moves: 8,
gridSize: 10
}];
// Initialize grid cells
for (var y = 0; y < GRID_HEIGHT; y++) {
@@ -397,8 +454,36 @@
levelButtonContainer.y = 330;
function getRandomCandyType() {
return CANDY_TYPES[Math.floor(Math.random() * CANDY_TYPES.length)];
}
+function getAvailableCandyTypes(level) {
+ // Progressively reduce available candy types to increase difficulty
+ switch (level) {
+ case 1:
+ case 2:
+ return CANDY_TYPES;
+ // All 6 types available
+ case 3:
+ case 4:
+ return CANDY_TYPES.slice(0, 5);
+ // 5 types available
+ case 5:
+ case 6:
+ return CANDY_TYPES.slice(0, 4);
+ // 4 types available
+ case 7:
+ case 8:
+ return CANDY_TYPES.slice(0, 3);
+ // 3 types available
+ case 9:
+ case 10:
+ return CANDY_TYPES.slice(0, 3);
+ // 3 types available
+ default:
+ // For higher levels, alternate between 3 and 4 types
+ return level % 2 === 0 ? CANDY_TYPES.slice(0, 3) : CANDY_TYPES.slice(0, 4);
+ }
+}
function loadProgress() {
var savedLevel = storage.currentLevel;
var savedMaxLevel = storage.maxLevel;
if (savedLevel) {
@@ -415,13 +500,18 @@
function getCurrentLevelConfig() {
if (currentLevel <= levelConfigs.length) {
return levelConfigs[currentLevel - 1];
}
- // For levels beyond predefined configs, generate dynamic difficulty
+ // For levels beyond predefined configs, generate exponentially harder difficulty
+ var baseScore = 8500;
+ var levelMultiplier = currentLevel - 10;
+ var exponentialIncrease = Math.pow(1.3, levelMultiplier); // 30% increase per level
+ var targetScore = Math.floor(baseScore * exponentialIncrease);
+ var moves = Math.max(6, 8 - Math.floor(levelMultiplier / 3)); // Reduce moves more aggressively
return {
level: currentLevel,
- targetScore: 1000 + (currentLevel - 1) * 750,
- moves: Math.max(8, 20 - Math.floor(currentLevel / 2)),
+ targetScore: targetScore,
+ moves: moves,
gridSize: 10
};
}
function initializeLevel() {
@@ -494,125 +584,136 @@
});
}
});
}
-function createCandy(x, y, type) {
+function createCandy(x, y, type, isFrozen) {
type = type || getRandomCandyType();
- var candy = new Candy(type, x, y);
+ var candy = new Candy(type, x, y, isFrozen);
candy.x = GRID_START_X + x * CELL_SIZE + CELL_SIZE / 2;
candy.y = GRID_START_Y + y * CELL_SIZE + CELL_SIZE / 2;
game.addChild(candy);
candies.push(candy);
grid[y][x] = candy;
+ if (isFrozen) {
+ frozenCandies.push(candy);
+ }
return candy;
}
function getLevelSpecificCandyType(x, y, level) {
- // Define specific patterns for each level
+ // Get available candy types based on level - fewer types = harder
+ var availableTypes = getAvailableCandyTypes(level);
+ function getRandomFromAvailable() {
+ return availableTypes[Math.floor(Math.random() * availableTypes.length)];
+ }
+ // Define specific patterns for each level with increased difficulty
switch (level) {
case 1:
// Level 1: More red and blue candies in corners
if (x < 3 && y < 3 || x > 6 && y > 6) {
- return Math.random() < 0.6 ? Math.random() < 0.5 ? 'red' : 'blue' : getRandomCandyType();
+ return Math.random() < 0.6 ? Math.random() < 0.5 ? 'red' : 'blue' : getRandomFromAvailable();
}
break;
case 2:
// Level 2: Checkerboard pattern influence with green and yellow
if ((x + y) % 2 === 0) {
- return Math.random() < 0.5 ? Math.random() < 0.5 ? 'green' : 'yellow' : getRandomCandyType();
+ return Math.random() < 0.6 ? Math.random() < 0.5 ? 'green' : 'yellow' : getRandomFromAvailable();
}
break;
case 3:
- // Level 3: Center focus with purple and orange
+ // Level 3: Center focus with purple and orange (fewer types available)
var centerDistance = Math.abs(x - 4.5) + Math.abs(y - 4.5);
if (centerDistance < 4) {
- return Math.random() < 0.7 ? Math.random() < 0.5 ? 'purple' : 'orange' : getRandomCandyType();
+ return Math.random() < 0.8 ? Math.random() < 0.5 ? 'purple' : 'orange' : getRandomFromAvailable();
}
break;
case 4:
- // Level 4: Diagonal pattern with red and green
+ // Level 4: Diagonal pattern with red and green (more concentrated)
if (Math.abs(x - y) < 2 || Math.abs(x + y - 9) < 2) {
- return Math.random() < 0.6 ? Math.random() < 0.5 ? 'red' : 'green' : getRandomCandyType();
+ return Math.random() < 0.8 ? Math.random() < 0.5 ? 'red' : 'green' : getRandomFromAvailable();
}
break;
case 5:
- // Level 5: Border emphasis with blue and yellow
+ // Level 5: Border emphasis with blue and yellow (very concentrated)
if (x < 2 || x > 7 || y < 2 || y > 7) {
- return Math.random() < 0.7 ? Math.random() < 0.5 ? 'blue' : 'yellow' : getRandomCandyType();
+ return Math.random() < 0.9 ? Math.random() < 0.5 ? 'blue' : 'yellow' : getRandomFromAvailable();
}
break;
case 6:
- // Level 6: Cross pattern with purple and red
+ // Level 6: Cross pattern with purple and red (extremely concentrated)
if (x === 4 || x === 5 || y === 4 || y === 5) {
- return Math.random() < 0.8 ? Math.random() < 0.5 ? 'purple' : 'red' : getRandomCandyType();
+ return Math.random() < 0.95 ? Math.random() < 0.5 ? 'purple' : 'red' : getRandomFromAvailable();
}
break;
case 7:
- // Level 7: Ring pattern with orange and green
+ // Level 7: Ring pattern with orange and green (max concentration)
var ringDistance = Math.max(Math.abs(x - 4.5), Math.abs(y - 4.5));
if (ringDistance > 2 && ringDistance < 5) {
- return Math.random() < 0.6 ? Math.random() < 0.5 ? 'orange' : 'green' : getRandomCandyType();
+ return Math.random() < 0.95 ? Math.random() < 0.5 ? 'orange' : 'green' : getRandomFromAvailable();
}
break;
case 8:
- // Level 8: Spiral influence with blue and purple
+ // Level 8: Spiral influence with blue and purple (only 3 types available)
var spiralValue = (x * 3 + y * 2) % 7;
if (spiralValue < 3) {
- return Math.random() < 0.7 ? Math.random() < 0.5 ? 'blue' : 'purple' : getRandomCandyType();
+ return Math.random() < 0.9 ? Math.random() < 0.5 ? 'blue' : 'purple' : getRandomFromAvailable();
}
break;
case 9:
- // Level 9: Scattered clusters with yellow and red
+ // Level 9: Scattered clusters with yellow and red (only 3 types available)
if (x % 3 === 0 && y % 3 === 0 || x % 3 === 2 && y % 3 === 2) {
- return Math.random() < 0.8 ? Math.random() < 0.5 ? 'yellow' : 'red' : getRandomCandyType();
+ return Math.random() < 0.95 ? Math.random() < 0.5 ? 'yellow' : 'red' : getRandomFromAvailable();
}
break;
case 10:
- // Level 10: Complex pattern with all colors but emphasis on green and orange
+ // Level 10: Complex pattern (only 3 types available, maximum difficulty)
if ((x + y) % 4 < 2) {
- return Math.random() < 0.5 ? Math.random() < 0.5 ? 'green' : 'orange' : getRandomCandyType();
+ return Math.random() < 0.98 ? Math.random() < 0.5 ? 'green' : 'orange' : getRandomFromAvailable();
}
break;
default:
- // For levels beyond 10, create dynamic patterns based on level number
+ // For levels beyond 10, create dynamic patterns with maximum difficulty
var patternType = level % 5;
+ var restrictedTypes = availableTypes.slice(0, Math.max(2, 4 - Math.floor(level / 15))); // Even fewer types for higher levels
switch (patternType) {
case 0:
// Diagonal emphasis
if (Math.abs(x - y) < 3) {
- return Math.random() < 0.6 ? CANDY_TYPES[level % CANDY_TYPES.length] : getRandomCandyType();
+ return Math.random() < 0.95 ? restrictedTypes[level % restrictedTypes.length] : getRandomFromAvailable();
}
break;
case 1:
// Corner concentration
if (x < 3 && y < 3 || x > 6 && y > 6 || x < 3 && y > 6 || x > 6 && y < 3) {
- return Math.random() < 0.7 ? CANDY_TYPES[(level + 1) % CANDY_TYPES.length] : getRandomCandyType();
+ return Math.random() < 0.95 ? restrictedTypes[(level + 1) % restrictedTypes.length] : getRandomFromAvailable();
}
break;
case 2:
// Center ring
var centerDist = Math.max(Math.abs(x - 4.5), Math.abs(y - 4.5));
if (centerDist > 1 && centerDist < 4) {
- return Math.random() < 0.6 ? CANDY_TYPES[(level + 2) % CANDY_TYPES.length] : getRandomCandyType();
+ return Math.random() < 0.95 ? restrictedTypes[(level + 2) % restrictedTypes.length] : getRandomFromAvailable();
}
break;
case 3:
// Checkerboard influence
if ((x + y + level) % 3 === 0) {
- return Math.random() < 0.7 ? CANDY_TYPES[(level + 3) % CANDY_TYPES.length] : getRandomCandyType();
+ return Math.random() < 0.95 ? restrictedTypes[(level + 3) % restrictedTypes.length] : getRandomFromAvailable();
}
break;
case 4:
// Random clusters
if ((x * y + level) % 11 < 4) {
- return Math.random() < 0.6 ? CANDY_TYPES[(level + 4) % CANDY_TYPES.length] : getRandomCandyType();
+ return Math.random() < 0.95 ? restrictedTypes[(level + 4) % restrictedTypes.length] : getRandomFromAvailable();
}
break;
}
break;
}
- return getRandomCandyType();
+ return getRandomFromAvailable();
}
function initializeGrid() {
+ // Clear frozen candies array
+ frozenCandies = [];
for (var y = 0; y < GRID_HEIGHT; y++) {
for (var x = 0; x < GRID_WIDTH; x++) {
var type;
var attempts = 0;
@@ -625,12 +726,34 @@
type = getRandomCandyType();
break;
}
} while (wouldCreateMatch(x, y, type));
- createCandy(x, y, type);
+ // Determine if this candy should be frozen based on level
+ var shouldBeFrozen = shouldCandyBeFrozen(x, y, currentLevel);
+ createCandy(x, y, type, shouldBeFrozen);
}
}
}
+function shouldCandyBeFrozen(x, y, level) {
+ // Start adding frozen candies from level 4
+ if (level < 4) return false;
+ // Increase frozen candy probability with level
+ var frozenProbability = Math.min(0.15, (level - 3) * 0.02); // Max 15% frozen
+ // Add specific frozen patterns for higher levels
+ if (level >= 6) {
+ // Corners are more likely to be frozen
+ if (x < 2 && y < 2 || x > 7 && y < 2 || x < 2 && y > 7 || x > 7 && y > 7) {
+ frozenProbability += 0.3;
+ }
+ }
+ if (level >= 8) {
+ // Center cross pattern more likely to be frozen
+ if ((x === 4 || x === 5) && (y === 4 || y === 5)) {
+ frozenProbability += 0.4;
+ }
+ }
+ return Math.random() < frozenProbability;
+}
function wouldCreateMatch(x, y, type) {
var horizontalCount = 1;
var verticalCount = 1;
// Check horizontal
@@ -678,10 +801,22 @@
}
if (matchLength >= 3) {
for (var i = 0; i < matchLength; i++) {
if (!processed[y][startX + i]) {
- matches.push(grid[y][startX + i]);
- processed[y][startX + i] = true;
+ var candy = grid[y][startX + i];
+ // Handle frozen candies - they need to be hit but may not be destroyed
+ if (candy.isFrozen) {
+ if (candy.hitFrozen()) {
+ // Candy is now unfrozen and can be matched
+ matches.push(candy);
+ processed[y][startX + i] = true;
+ }
+ // If still frozen, don't add to matches but mark as processed
+ processed[y][startX + i] = true;
+ } else {
+ matches.push(candy);
+ processed[y][startX + i] = true;
+ }
}
}
}
}
@@ -698,10 +833,22 @@
}
if (matchLength >= 3) {
for (var i = 0; i < matchLength; i++) {
if (!processed[startY + i][x]) {
- matches.push(grid[startY + i][x]);
- processed[startY + i][x] = true;
+ var candy = grid[startY + i][x];
+ // Handle frozen candies - they need to be hit but may not be destroyed
+ if (candy.isFrozen) {
+ if (candy.hitFrozen()) {
+ // Candy is now unfrozen and can be matched
+ matches.push(candy);
+ processed[startY + i][x] = true;
+ }
+ // If still frozen, don't add to matches but mark as processed
+ processed[startY + i][x] = true;
+ } else {
+ matches.push(candy);
+ processed[startY + i][x] = true;
+ }
}
}
}
}
Modern App Store icon, high definition, square with rounded corners, for a game titled "Candy Match Saga" and with the description "A match-3 puzzle game where players swap candies to create matching lines, clear objectives, and progress through challenging levels.". No text on icon!
Mavi şeker resmi. In-Game asset. 2d. High contrast. No shadows
Sarı şeker. In-Game asset. 2d. High contrast. No shadows
Kırmızı şeker. In-Game asset. 2d. High contrast. No shadows
Yeşil şeker. In-Game asset. 2d. High contrast. No shadows
Turuncu şeker. In-Game asset. 2d. High contrast. No shadows