Commit 4b85df29 authored by Nguyễn Quang Sáng's avatar Nguyễn Quang Sáng

05/10/23 commit

parent 630b55b0
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
"__id__": 55 "__id__": 55
}, },
{ {
"__id__": 72 "__id__": 70
}, },
{ {
"__id__": 8 "__id__": 8
...@@ -93,16 +93,16 @@ ...@@ -93,16 +93,16 @@
"__id__": 41 "__id__": 41
}, },
{ {
"__id__": 84 "__id__": 82
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 86 "__id__": 84
}, },
{ {
"__id__": 87 "__id__": 85
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -3053,9 +3053,6 @@ ...@@ -3053,9 +3053,6 @@
}, },
{ {
"__id__": 68 "__id__": 68
},
{
"__id__": 70
} }
], ],
"_active": true, "_active": true,
...@@ -3145,8 +3142,8 @@ ...@@ -3145,8 +3142,8 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
-252.763, 233.01,
481.844, 477.674,
0, 0,
0, 0,
0, 0,
...@@ -3239,8 +3236,8 @@ ...@@ -3239,8 +3236,8 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
-252.763, 233.01,
481.844, 477.674,
0, 0,
0, 0,
0, 0,
...@@ -3298,7 +3295,7 @@ ...@@ -3298,7 +3295,7 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "ScoreBar", "_name": "HighestBar",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 55 "__id__": 55
...@@ -3321,7 +3318,7 @@ ...@@ -3321,7 +3318,7 @@
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 254, "width": 166,
"height": 61 "height": 61
}, },
"_anchorPoint": { "_anchorPoint": {
...@@ -3333,8 +3330,8 @@ ...@@ -3333,8 +3330,8 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
-48, -150,
482, 464,
0, 0,
0, 0,
0, 0,
...@@ -3390,101 +3387,6 @@ ...@@ -3390,101 +3387,6 @@
"_atlas": null, "_atlas": null,
"_id": "4ex7zTzH9Jg499AeMFtfUh" "_id": "4ex7zTzH9Jg499AeMFtfUh"
}, },
{
"__type__": "cc.Node",
"_name": "ScoreLabel",
"_objFlags": 0,
"_parent": {
"__id__": 55
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 63
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 33.37,
"height": 37.8
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-123.698,
482,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "8e/mLYQXZAW6DXSVWU3acw"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 62
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "25",
"_N$string": "25",
"_fontSize": 30,
"_lineHeight": 30,
"_enableWrapText": true,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_batchAsBitmap": false,
"_styleFlags": 0,
"_underlineHeight": 0,
"_N$horizontalAlign": 0,
"_N$verticalAlign": 0,
"_N$fontFamily": "Arial",
"_N$overflow": 0,
"_N$cacheMode": 0,
"_id": "53i2qrGphPgIb8LaN6GGkC"
},
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "Couronne", "_name": "Couronne",
...@@ -3496,7 +3398,7 @@ ...@@ -3496,7 +3398,7 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 65 "__id__": 63
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -3522,15 +3424,15 @@ ...@@ -3522,15 +3424,15 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
-48, -147.243,
482, 518,
0, 0,
0, 0,
0, 0,
0.2523395837907841, 0.2523395837907841,
0.9676387417069936, 0.9676387417069936,
1, 1.5,
1, 1.5,
1 1
] ]
}, },
...@@ -3552,7 +3454,7 @@ ...@@ -3552,7 +3454,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 64 "__id__": 62
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -3590,7 +3492,7 @@ ...@@ -3590,7 +3492,7 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 67 "__id__": 65
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -3604,7 +3506,7 @@ ...@@ -3604,7 +3506,7 @@
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 55.62, "width": 64.55,
"height": 31.5 "height": 31.5
}, },
"_anchorPoint": { "_anchorPoint": {
...@@ -3616,8 +3518,8 @@ ...@@ -3616,8 +3518,8 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
19.38, -150.932,
482, 464,
0, 0,
0, 0,
0, 0,
...@@ -3646,7 +3548,7 @@ ...@@ -3646,7 +3548,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 66 "__id__": 64
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -3661,8 +3563,10 @@ ...@@ -3661,8 +3563,10 @@
"_fontSize": 25, "_fontSize": 25,
"_lineHeight": 25, "_lineHeight": 25,
"_enableWrapText": true, "_enableWrapText": true,
"_N$file": null, "_N$file": {
"_isSystemFontUsed": true, "__uuid__": "9bde507c-0766-4844-ae73-02962a0559d3"
},
"_isSystemFontUsed": false,
"_spacingX": 0, "_spacingX": 0,
"_batchAsBitmap": false, "_batchAsBitmap": false,
"_styleFlags": 0, "_styleFlags": 0,
...@@ -3676,7 +3580,7 @@ ...@@ -3676,7 +3580,7 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "CoinBar", "_name": "ScoreBar",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 55 "__id__": 55
...@@ -3685,7 +3589,7 @@ ...@@ -3685,7 +3589,7 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 69 "__id__": 67
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -3699,8 +3603,8 @@ ...@@ -3699,8 +3603,8 @@
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 179, "width": 267,
"height": 61 "height": 72
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
...@@ -3711,8 +3615,8 @@ ...@@ -3711,8 +3615,8 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
185.222, -141,
482, 385,
0, 0,
0, 0,
0, 0,
...@@ -3741,7 +3645,7 @@ ...@@ -3741,7 +3645,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 68 "__id__": 66
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -3770,7 +3674,7 @@ ...@@ -3770,7 +3674,7 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "CoinLabel", "_name": "ScoreLabel",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 55 "__id__": 55
...@@ -3779,21 +3683,21 @@ ...@@ -3779,21 +3683,21 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 71 "__id__": 69
} }
], ],
"_prefab": null, "_prefab": null,
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
"__type__": "cc.Color", "__type__": "cc.Color",
"r": 139, "r": 255,
"g": 148, "g": 255,
"b": 200, "b": 255,
"a": 255 "a": 255
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 34.25, "width": 45.66,
"height": 37.8 "height": 37.8
}, },
"_anchorPoint": { "_anchorPoint": {
...@@ -3805,8 +3709,8 @@ ...@@ -3805,8 +3709,8 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
195.222, -144.306,
482, 387.822,
0, 0,
0, 0,
0, 0,
...@@ -3828,14 +3732,14 @@ ...@@ -3828,14 +3732,14 @@
"_is3DNode": false, "_is3DNode": false,
"_groupIndex": 0, "_groupIndex": 0,
"groupIndex": 0, "groupIndex": 0,
"_id": "f2qNuXKCdKkb5Qf2GU73aA" "_id": "8e/mLYQXZAW6DXSVWU3acw"
}, },
{ {
"__type__": "cc.Label", "__type__": "cc.Label",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 70 "__id__": 68
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -3845,9 +3749,9 @@ ...@@ -3845,9 +3749,9 @@
], ],
"_srcBlendFactor": 770, "_srcBlendFactor": 770,
"_dstBlendFactor": 771, "_dstBlendFactor": 771,
"_string": "20", "_string": "25",
"_N$string": "20", "_N$string": "25",
"_fontSize": 30, "_fontSize": 40,
"_lineHeight": 30, "_lineHeight": 30,
"_enableWrapText": true, "_enableWrapText": true,
"_N$file": { "_N$file": {
...@@ -3863,7 +3767,7 @@ ...@@ -3863,7 +3767,7 @@
"_N$fontFamily": "Arial", "_N$fontFamily": "Arial",
"_N$overflow": 0, "_N$overflow": 0,
"_N$cacheMode": 0, "_N$cacheMode": 0,
"_id": "6cWiJoWiJIpo8mOSt5AQIK" "_id": "53i2qrGphPgIb8LaN6GGkC"
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
...@@ -3873,6 +3777,9 @@ ...@@ -3873,6 +3777,9 @@
"__id__": 2 "__id__": 2
}, },
"_children": [ "_children": [
{
"__id__": 71
},
{ {
"__id__": 73 "__id__": 73
}, },
...@@ -3884,15 +3791,12 @@ ...@@ -3884,15 +3791,12 @@
}, },
{ {
"__id__": 79 "__id__": 79
},
{
"__id__": 81
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 83 "__id__": 81
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -3948,13 +3852,13 @@ ...@@ -3948,13 +3852,13 @@
"_name": "StartPoint", "_name": "StartPoint",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 72 "__id__": 70
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 74 "__id__": 72
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -4010,7 +3914,7 @@ ...@@ -4010,7 +3914,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 73 "__id__": 71
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -4042,13 +3946,13 @@ ...@@ -4042,13 +3946,13 @@
"_name": "StartPoint", "_name": "StartPoint",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 72 "__id__": 70
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 76 "__id__": 74
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -4104,7 +4008,7 @@ ...@@ -4104,7 +4008,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 75 "__id__": 73
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -4136,13 +4040,13 @@ ...@@ -4136,13 +4040,13 @@
"_name": "StartPoint", "_name": "StartPoint",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 72 "__id__": 70
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 78 "__id__": 76
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -4198,7 +4102,7 @@ ...@@ -4198,7 +4102,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 77 "__id__": 75
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -4230,13 +4134,13 @@ ...@@ -4230,13 +4134,13 @@
"_name": "StartPoint", "_name": "StartPoint",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 72 "__id__": 70
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 80 "__id__": 78
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -4292,7 +4196,7 @@ ...@@ -4292,7 +4196,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 79 "__id__": 77
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -4324,13 +4228,13 @@ ...@@ -4324,13 +4228,13 @@
"_name": "StartPoint", "_name": "StartPoint",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 72 "__id__": 70
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 82 "__id__": 80
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -4386,7 +4290,7 @@ ...@@ -4386,7 +4290,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 81 "__id__": 79
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -4418,7 +4322,7 @@ ...@@ -4418,7 +4322,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 72 "__id__": 70
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -4456,7 +4360,7 @@ ...@@ -4456,7 +4360,7 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 85 "__id__": 83
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -4512,7 +4416,7 @@ ...@@ -4512,7 +4416,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 84 "__id__": 82
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
......
...@@ -269,6 +269,7 @@ export default class GameController extends cc.Component { ...@@ -269,6 +269,7 @@ export default class GameController extends cc.Component {
this.currentBlock.setPosition(cc.Vec2.ZERO); this.currentBlock.setPosition(cc.Vec2.ZERO);
cellToMerge.removeAllChildren(); cellToMerge.removeAllChildren();
cellToMerge.addChild(this.currentBlock); cellToMerge.addChild(this.currentBlock);
this.currentBlock.getComponent(Block).isPlace = true;
this.blocksData.setBlockValue( this.blocksData.setBlockValue(
this.currentBlockRow, this.currentBlockRow,
...@@ -306,7 +307,7 @@ export default class GameController extends cc.Component { ...@@ -306,7 +307,7 @@ export default class GameController extends cc.Component {
.call(() => { .call(() => {
nodeClone.destroy(); nodeClone.destroy();
nodeClone.parent.removeAllChildren(); nodeClone.parent.removeAllChildren();
cellToMerge.children[0].getComponent(Block).setSpriteBlock(index); this.currentBlock.getComponent(Block).setSpriteBlock(index);
this.cachedBlocksToMerge.length = 0; this.cachedBlocksToMerge.length = 0;
if (!hasCheckedEmptyCell) { if (!hasCheckedEmptyCell) {
...@@ -340,7 +341,7 @@ export default class GameController extends cc.Component { ...@@ -340,7 +341,7 @@ export default class GameController extends cc.Component {
newRow = currentRow; newRow = currentRow;
newCol = col; newCol = col;
return this.updateBoardChildren(newRow, newCol); return this.checkMergeability(newRow, newCol);
} else { } else {
break; break;
} }
...@@ -355,39 +356,35 @@ export default class GameController extends cc.Component { ...@@ -355,39 +356,35 @@ export default class GameController extends cc.Component {
} }
} }
updateBoardChildren(row: number, col: number) { // updateBoardChildren() {
const data = this.blocksData.blockData; // const data = this.blocksData.blockData;
const numRows = data.length; // const childrens = this.board.children;
const numCols = data[0].length;
const children = this.board.children; // for (let row = 0; row < 6; row++) {
// for (let col = 0; col < 5; col++) {
for (let row = 0; row < numRows; row++) { // const index = row * 5 + col;
for (let col = 0; col < numCols; col++) { // const cell = childrens[index];
const index = row * numCols + col; // const value = data[row][col];
const cell = children[index];
const value = data[row][col]; // cell.removeAllChildren();
cell.removeAllChildren(); // if (value !== 0) {
// const newValueNode = this.createValueNode(value);
if (value !== 0) { // cell.addChild(newValueNode);
const newValueNode = this.createValueNode(value); // if (cell.children.length > 1) cell.children.shift();
cell.addChild(newValueNode); // }
if (cell.children.length > 1) cell.children.shift(); // }
} // }
} // }
}
// createValueNode(value: number) {
this.checkMergeability(row, col); // const newNode = new cc.Node();
}
// newNode.addComponent(cc.Sprite).spriteFrame =
createValueNode(value: number) { // this.blockPrefab.data.getComponent(Block).listSpriteBlocks[
const newNode = new cc.Node(); // Math.log(value) / Math.log(2) - 1
// ];
newNode.addComponent(cc.Sprite).spriteFrame =
this.blockPrefab.data.getComponent(Block).listSpriteBlocks[ // return newNode;
Math.log(value) / Math.log(2) - 1 // }
];
return newNode;
}
} }
import Utils from "../Tools/Utils";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
...@@ -39,27 +37,35 @@ export default class BlockData extends cc.Component { ...@@ -39,27 +37,35 @@ export default class BlockData extends cc.Component {
} }
generateNumber(): number { generateNumber(): number {
if (this.blockData.length == 0) return Utils.random(0, 4); if (this.blockData.length == 0) return 0;
const allValues: number[] = [];
for (let row = 0; row < 6; row++) {
for (let col = 0; col < 5; col++) {
allValues.push(this.blockData[row][col]);
}
}
const smallNumberProbability = 0.7; const higherValueCount = allValues.filter((value) => value >= 32).length;
const largeNumberProbability = 0.3; const totalValueCount = allValues.length;
const higherValueProbability = higherValueCount / totalValueCount;
let randomNumber = 0; const random = Math.random();
const randomValue = Math.random();
if (randomValue < smallNumberProbability) { if (random < higherValueProbability) {
const smallNumbers = [2, 4, 8, 16, 32]; const minExponent = 5;
const randomIndex = Math.floor(Math.random() * smallNumbers.length); const maxExponent = 9;
randomNumber = smallNumbers[randomIndex];
} else if (randomValue < smallNumberProbability + largeNumberProbability) { const exponent =
const largeNumbers = [64, 128, 256, 512]; Math.floor(Math.random() * (maxExponent - minExponent + 1)) +
const randomIndex = Math.floor(Math.random() * largeNumbers.length); minExponent;
randomNumber = largeNumbers[randomIndex]; const randomValue = Math.pow(2, exponent);
return Math.log(randomValue) / Math.log(2) - 1;
} else { } else {
const averageNumbers = [16, 32, 64]; const possibleValues = [2, 4, 8, 16];
const randomIndex = Math.floor(Math.random() * averageNumbers.length); const randomValue =
randomNumber = averageNumbers[randomIndex]; possibleValues[Math.floor(Math.random() * possibleValues.length)];
return Math.log(randomValue) / Math.log(2) - 1;
} }
return Math.log(randomNumber) / Math.log(2) - 1;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment