Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
l2_boardgame4_double
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
template admin
l2_boardgame4_double
Commits
66b3465f
Commit
66b3465f
authored
Jul 25, 2022
by
yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
b3ec34b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
163 additions
and
198 deletions
+163
-198
l2_boardgame4_double.ts
assets/l2_boardgame4_double/scene/l2_boardgame4_double.ts
+161
-196
AI.ts
assets/l2_boardgame4_double/script/AI.ts
+2
-2
No files found.
assets/l2_boardgame4_double/scene/l2_boardgame4_double.ts
View file @
66b3465f
...
...
@@ -323,143 +323,143 @@ export default class SceneComponent extends MyCocosSceneComponent {
private
audioId
:
any
;
addPieceTouchEventListener
(
node
:
cc
.
Node
,
color
)
{
node
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
(
event
:
cc
.
Event
.
EventTouch
)
=>
{
const
playerMe
=
this
.
allPlayerList
.
find
(
(
player
)
=>
player
.
uuid
==
this
.
playerId
);
if
(
playerMe
.
color
!=
this
.
_status
.
current
)
{
this
.
blinkPiece
(
node
);
return
;
}
if
(
this
.
_status
.
current
!=
color
)
{
this
.
blinkPiece
(
node
);
return
;
}
if
(
this
.
_status
.
letter
==
""
)
{
this
.
blinkPiece
(
node
);
return
;
}
if
(
node
[
"
cantMove
"
])
{
this
.
blinkPiece
(
node
);
return
;
}
this
.
stopRollPiece
(
node
);
node
[
"
touchStartPos
"
]
=
{
nodeX
:
node
.
x
,
nodeY
:
node
.
y
,
touchX
:
event
.
getLocation
().
x
,
touchY
:
event
.
getLocation
().
y
,
};
node
.
zIndex
=
1
;
this
.
showStars
(
node
);
});
node
.
on
(
cc
.
Node
.
EventType
.
TOUCH_MOVE
,
(
event
:
cc
.
Event
.
EventTouch
)
=>
{
const
playerMe
=
this
.
allPlayerList
.
find
(
(
player
)
=>
player
.
uuid
==
this
.
playerId
);
if
(
playerMe
.
color
!=
this
.
_status
.
current
)
{
return
;
}
if
(
this
.
_status
.
current
!=
color
)
{
return
;
}
if
(
this
.
_status
.
letter
==
""
)
{
return
;
}
if
(
node
[
"
cantMove
"
])
{
return
;
}
const
pos
=
event
.
getLocation
();
const
touchStartPos
=
node
[
"
touchStartPos
"
];
const
worldNodePos
=
node
.
parent
.
convertToWorldSpaceAR
(
cc
.
v2
(
touchStartPos
.
nodeX
,
touchStartPos
.
nodeY
)
);
const
nodePos
=
node
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldNodePos
.
x
+
pos
.
x
-
touchStartPos
.
touchX
,
worldNodePos
.
y
+
pos
.
y
-
touchStartPos
.
touchY
)
);
node
.
setPosition
(
nodePos
);
});
node
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
async
(
event
:
cc
.
Event
.
EventTouch
)
=>
{
const
playerMe
=
this
.
allPlayerList
.
find
(
(
player
)
=>
player
.
uuid
==
this
.
playerId
);
if
(
playerMe
.
color
!=
this
.
_status
.
current
)
{
return
;
}
if
(
this
.
_status
.
current
!=
color
)
{
return
;
}
if
(
this
.
_status
.
letter
==
""
)
{
return
;
}
if
(
node
[
"
cantMove
"
])
{
return
;
}
node
[
"
cantMove
"
]
=
true
;
if
(
this
.
checkNodeInRightBlock
(
node
,
color
))
{
const
idx
=
this
.
getNextRightIdx
();
const
playerMe
=
this
.
allPlayerList
.
find
(
(
player
)
=>
player
.
uuid
==
this
.
playerId
);
this
.
networkHelper
.
sendFrame
({
type
:
"
right
"
,
idx
:
idx
,
uuid
:
playerMe
.
uuid
,
color
:
playerMe
.
color
,
});
}
else
{
const
playerMe
=
this
.
allPlayerList
.
find
(
(
player
)
=>
player
.
uuid
==
this
.
playerId
);
this
.
networkHelper
.
sendFrame
({
type
:
"
wrong
"
,
uuid
:
playerMe
.
uuid
,
color
:
playerMe
.
color
,
});
}
});
node
.
on
(
cc
.
Node
.
EventType
.
TOUCH_CANCEL
,
async
(
event
:
cc
.
Event
.
EventTouch
)
=>
{
const
playerMe
=
this
.
allPlayerList
.
find
(
(
player
)
=>
player
.
uuid
==
this
.
playerId
);
if
(
playerMe
.
color
!=
this
.
_status
.
current
)
{
return
;
}
if
(
this
.
_status
.
current
!=
color
)
{
return
;
}
if
(
this
.
_status
.
letter
==
""
)
{
return
;
}
if
(
node
[
"
cantMove
"
])
{
return
;
}
node
[
"
cantMove
"
]
=
true
;
if
(
this
.
checkNodeInRightBlock
(
node
,
color
))
{
const
idx
=
this
.
getNextRightIdx
();
const
playerMe
=
this
.
allPlayerList
.
find
(
(
player
)
=>
player
.
uuid
==
this
.
playerId
);
this
.
networkHelper
.
sendFrame
({
type
:
"
right
"
,
idx
:
idx
,
uuid
:
playerMe
.
uuid
,
color
:
playerMe
.
color
,
});
}
else
{
const
playerMe
=
this
.
allPlayerList
.
find
(
(
player
)
=>
player
.
uuid
==
this
.
playerId
);
this
.
networkHelper
.
sendFrame
({
type
:
"
wrong
"
,
uuid
:
playerMe
.
uuid
,
color
:
playerMe
.
color
,
});
}
});
//
node.on(cc.Node.EventType.TOUCH_START, (event: cc.Event.EventTouch) => {
//
const playerMe = this.allPlayerList.find(
//
(player) => player.uuid == this.playerId
//
);
//
if (playerMe.color != this._status.current) {
//
this.blinkPiece(node);
//
return;
//
}
//
if (this._status.current != color) {
//
this.blinkPiece(node);
//
return;
//
}
//
if (this._status.letter == "") {
//
this.blinkPiece(node);
//
return;
//
}
//
if (node["cantMove"]) {
//
this.blinkPiece(node);
//
return;
//
}
//
this.stopRollPiece(node);
//
node["touchStartPos"] = {
//
nodeX: node.x,
//
nodeY: node.y,
//
touchX: event.getLocation().x,
//
touchY: event.getLocation().y,
//
};
//
node.zIndex = 1;
//
this.showStars(node);
//
});
//
node.on(cc.Node.EventType.TOUCH_MOVE, (event: cc.Event.EventTouch) => {
//
const playerMe = this.allPlayerList.find(
//
(player) => player.uuid == this.playerId
//
);
//
if (playerMe.color != this._status.current) {
//
return;
//
}
//
if (this._status.current != color) {
//
return;
//
}
//
if (this._status.letter == "") {
//
return;
//
}
//
if (node["cantMove"]) {
//
return;
//
}
//
const pos = event.getLocation();
//
const touchStartPos = node["touchStartPos"];
//
const worldNodePos = node.parent.convertToWorldSpaceAR(
//
cc.v2(touchStartPos.nodeX, touchStartPos.nodeY)
//
);
//
const nodePos = node.parent.convertToNodeSpaceAR(
//
cc.v2(
//
worldNodePos.x + pos.x - touchStartPos.touchX,
//
worldNodePos.y + pos.y - touchStartPos.touchY
//
)
//
);
//
node.setPosition(nodePos);
//
});
//
node.on(cc.Node.EventType.TOUCH_END, async (event: cc.Event.EventTouch) => {
//
const playerMe = this.allPlayerList.find(
//
(player) => player.uuid == this.playerId
//
);
//
if (playerMe.color != this._status.current) {
//
return;
//
}
//
if (this._status.current != color) {
//
return;
//
}
//
if (this._status.letter == "") {
//
return;
//
}
//
if (node["cantMove"]) {
//
return;
//
}
//
node["cantMove"] = true;
//
if (this.checkNodeInRightBlock(node, color)) {
//
const idx = this.getNextRightIdx();
//
const playerMe = this.allPlayerList.find(
//
(player) => player.uuid == this.playerId
//
);
//
this.networkHelper.sendFrame({
//
type: "right",
//
idx: idx,
//
uuid: playerMe.uuid,
//
color: playerMe.color,
//
});
//
} else {
//
const playerMe = this.allPlayerList.find(
//
(player) => player.uuid == this.playerId
//
);
//
this.networkHelper.sendFrame({
//
type: "wrong",
//
uuid: playerMe.uuid,
//
color: playerMe.color,
//
});
//
}
//
});
//
node.on(cc.Node.EventType.TOUCH_CANCEL, async (event: cc.Event.EventTouch) => {
//
const playerMe = this.allPlayerList.find(
//
(player) => player.uuid == this.playerId
//
);
//
if (playerMe.color != this._status.current) {
//
return;
//
}
//
if (this._status.current != color) {
//
return;
//
}
//
if (this._status.letter == "") {
//
return;
//
}
//
if (node["cantMove"]) {
//
return;
//
}
//
node["cantMove"] = true;
//
if (this.checkNodeInRightBlock(node, color)) {
//
const idx = this.getNextRightIdx();
//
const playerMe = this.allPlayerList.find(
//
(player) => player.uuid == this.playerId
//
);
//
this.networkHelper.sendFrame({
//
type: "right",
//
idx: idx,
//
uuid: playerMe.uuid,
//
color: playerMe.color,
//
});
//
} else {
//
const playerMe = this.allPlayerList.find(
//
(player) => player.uuid == this.playerId
//
);
//
this.networkHelper.sendFrame({
//
type: "wrong",
//
uuid: playerMe.uuid,
//
color: playerMe.color,
//
});
//
}
//
});
}
blinkPiece
(
node
)
{
...
...
@@ -606,17 +606,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
async
pieceFindRightBlock
(
rightBlock
,
idx
)
{
const
board
=
this
.
_status
.
current
==
"
Red
"
?
cc
.
find
(
"
Canvas/bg/chessBoard/boardItems
"
)
:
cc
.
find
(
"
Canvas/bg/chessBoard/righttIems
"
);
const
color
=
this
.
_status
.
current
;
const
piece
=
cc
.
find
(
`Canvas/bg/chessBoard/piece
${
color
}
`
);
const
prograssbar
=
cc
.
find
(
`Canvas/bg/Life
${
color
.
toLowerCase
()}
/life_
${
color
.
toLowerCase
()}
/mask/prograssbar`
);
const
mask
=
cc
.
find
(
`Canvas/bg/Life
${
color
.
toLowerCase
()}
/life_
${
color
.
toLowerCase
()}
/mask`
);
let
targetHeight
=
(
idx
/
(
board
.
children
.
length
-
2
))
*
prograssbar
.
height
;
// console.log(idx + "_进度条高:" + targetHeight);
const
offsetX
=
{
Red
:
-
45
,
Blue
:
45
};
...
...
@@ -661,15 +653,29 @@ export default class SceneComponent extends MyCocosSceneComponent {
piece
.
stopAllActions
();
await
this
.
playLocalAudio
(
"
落子
"
);
piece
.
zIndex
=
0
;
const
effectNode
=
cc
.
find
(
`Canvas/bg/Life
${
color
.
toLowerCase
()}
/effect`
);
effectNode
.
active
=
true
;
asyncTweenTo
(
mask
,
1
,
{
height
:
targetHeight
},
{
easing
:
"
cubicInOut
"
});
this
.
playLocalAudio
(
"
进度条升高
"
);
await
asyncPlayDragonBoneAnimation
(
effectNode
,
"
normal
"
,
1
);
effectNode
.
active
=
false
;
}
updateProgress
(
idx
)
{
const
color
=
this
.
_status
.
current
;
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
// const board = cc.find("Canvas/bg/chessBoard/boardItems");
const
board
=
this
.
_status
.
current
==
"
Red
"
?
cc
.
find
(
"
Canvas/bg/chessBoard/boardItems
"
)
:
cc
.
find
(
"
Canvas/bg/chessBoard/righttIems
"
);
const
prograssbar
=
cc
.
find
(
`Canvas/bg/Life
${
color
.
toLowerCase
()}
/life_
${
color
.
toLowerCase
()}
/mask/prograssbar`
);
const
mask
=
cc
.
find
(
`Canvas/bg/Life
${
color
.
toLowerCase
()}
/life_
${
color
.
toLowerCase
()}
/mask`
);
let
targetHeight
=
(
idx
/
(
board
.
children
.
length
-
2
))
*
prograssbar
.
height
;
const
effectNode
=
cc
.
find
(
`Canvas/bg/Life
${
color
.
toLowerCase
()}
/effect`
);
effectNode
.
active
=
true
;
asyncTweenTo
(
mask
,
1
,
{
height
:
targetHeight
},
{
easing
:
"
cubicInOut
"
});
this
.
playLocalAudio
(
"
进度条升高
"
);
await
asyncPlayDragonBoneAnimation
(
effectNode
,
"
normal
"
,
1
);
effectNode
.
active
=
false
;
resolve
(
''
);
});
}
updateStatus
(
status
=
null
)
{
if
(
status
)
{
console
.
log
(
status
);
...
...
@@ -914,6 +920,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
let
isSuccess
=
await
this
.
showVoice
(
rightBlock
);
this
.
hideVoice
();
if
(
isSuccess
)
{
this
.
updateProgress
(
idx
);
this
.
networkHelper
.
sendFrame
({
type
:
"
right
"
,
idx
:
nextIdx
,
...
...
@@ -1300,48 +1307,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
});
}
async
movePiece
(
letter
,
color
)
{
const
offsetX
=
{
Red
:
-
45
,
Blue
:
45
};
const
offsetY
=
{
Red
:
-
90
,
Blue
:
-
90
};
const
pieceNode
=
cc
.
find
(
`Canvas/bg/chessBoard/piece
${
color
}
`
);
const
board
=
this
.
_status
.
current
==
"
Red
"
?
cc
.
find
(
"
Canvas/bg/chessBoard/boardItems
"
)
:
cc
.
find
(
"
Canvas/bg/chessBoard/righttIems
"
);
const
startIdx
=
this
.
_status
[
color
];
for
(
let
i
=
startIdx
+
1
;
i
<
board
.
children
.
length
;
i
++
)
{
const
targetNode
=
board
.
children
[
i
];
const
itemData
=
targetNode
.
getComponent
(
"
BoardGame4_double_ItemData
"
);
const
prograssbar
=
cc
.
find
(
`Canvas/bg/Life
${
color
.
toLowerCase
()}
/life_
${
color
.
toLowerCase
()}
/mask/prograssbar`
);
const
mask
=
cc
.
find
(
`Canvas/bg/Life
${
color
.
toLowerCase
()}
/life_
${
color
.
toLowerCase
()}
/mask`
);
const
targetHeight
=
(
i
/
board
.
children
.
length
)
*
prograssbar
.
height
;
this
.
playLocalAudio
(
"
movePiece 进度条升高
"
);
cc
.
tween
(
mask
)
.
to
(
1
,
{
height
:
targetHeight
},
{
easing
:
"
cubicInOut
"
})
.
start
();
await
asyncTweenTo
(
pieceNode
,
1
,
{
x
:
targetNode
.
x
+
offsetX
[
color
],
y
:
targetNode
.
y
+
offsetY
[
color
],
},
{
easing
:
"
cubicInOut
"
}
);
if
(
itemData
.
letter
.
toLowerCase
()
==
letter
.
toLowerCase
())
{
this
.
_status
[
color
]
=
i
;
return
;
}
}
this
.
finish
();
}
finish
()
{
// onHomeworkFinish();
}
...
...
assets/l2_boardgame4_double/script/AI.ts
View file @
66b3465f
...
...
@@ -47,10 +47,10 @@ export class AI {
});
}
else
{
//调试加速 2 Math.random() * 3 + 4
await
asyncDelay
(
Math
.
random
()
*
3
+
4
);
await
asyncDelay
(
Math
.
random
()
*
1
+
10
);
const
idx
=
this
.
getNextRightIdx
();
if
(
Math
.
random
()
<
1
)
{
if
(
Math
.
random
()
<
0.8
)
{
this
.
networkHelper
.
sendFrame
({
type
:
"
right
"
,
idx
:
idx
,
...
...
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