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