Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
DropAndMergeTheNumber
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nguyễn Quang Sáng
DropAndMergeTheNumber
Commits
4b85df29
Commit
4b85df29
authored
Oct 05, 2023
by
Nguyễn Quang Sáng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
05/10/23 commit
parent
630b55b0
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
223 deletions
+130
-223
gameplay.fire
assets/Scenes/gameplay.fire
+70
-166
GameController.ts
assets/Scripts/Controllers/GameController.ts
+34
-37
BlockData.ts
assets/Scripts/Data/BlockData.ts
+26
-20
No files found.
assets/Scenes/gameplay.fire
View file @
4b85df29
This diff is collapsed.
Click to expand it.
assets/Scripts/Controllers/GameController.ts
View file @
4b85df29
...
@@ -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
;
}
}
}
assets/Scripts/Data/BlockData.ts
View file @
4b85df29
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
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment