Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OPW_BoardGame_L5R4
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
OPW_BoardGame_L5R4
Commits
84eed4d9
Commit
84eed4d9
authored
Nov 25, 2022
by
李维
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成AI相关功能
parent
7735f9a1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
21 deletions
+83
-21
Turntable.js
assets/OPW_BoardGame_L5R4/prefab/Turntable/Turntable.js
+14
-5
OPW_BoardGame_L5R4.ts
assets/OPW_BoardGame_L5R4/scene/OPW_BoardGame_L5R4.ts
+62
-15
Server.ts
assets/OPW_BoardGame_L5R4/script/Server.ts
+7
-1
No files found.
assets/OPW_BoardGame_L5R4/prefab/Turntable/Turntable.js
View file @
84eed4d9
...
...
@@ -32,7 +32,9 @@ cc.Class({
// 是否可以转动
isRolling
:
false
,
// 是否正在闪烁
isBlinking
:
false
isBlinking
:
false
,
// 结果状态 转完之后禁止点击
isLock
:
false
,
},
// LIFE-CYCLE CALLBACKS:
...
...
@@ -53,10 +55,10 @@ cc.Class({
initEventLinister
()
{
// console.log("初始化事件监听");
cc
.
find
(
"
dice
"
,
this
.
node
).
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
if
(
this
.
canClick
&&
!
this
.
isRolling
)
{
if
(
this
.
canClick
&&
!
this
.
isRolling
&&
!
this
.
isLock
)
{
this
.
node
.
emit
(
"
Rolling_Start
"
)
}
else
{
cc
.
log
(
`已屏蔽转盘点击 canClick:
${
this
.
canClick
}
isRolling:
${
this
.
isRolling
}
`
)
// cc.log(`已屏蔽转盘点击 canClick:${this.canClick} isRolling:${this.isRolling} isLock:${this.isLock
}`)
}
})
},
...
...
@@ -84,7 +86,8 @@ cc.Class({
.
by
(
1.5
,
{
angle
:
360
},
{
easing
:
"
cubicOut
"
})
.
call
(()
=>
{
this
.
isRolling
=
false
;
this
.
node
.
emit
(
"
Rolling_End
"
)
this
.
isLock
=
true
;
this
.
node
.
emit
(
"
Rolling_End
"
);
resolve
(
null
);
})
.
start
();
...
...
@@ -101,7 +104,8 @@ cc.Class({
.
by
(
0.3
,
{
angle
:
360
},
{
easing
:
"
cubicOut
"
})
.
call
(()
=>
{
this
.
isRolling
=
false
;
this
.
node
.
emit
(
"
Rolling_End
"
)
this
.
isLock
=
true
;
this
.
node
.
emit
(
"
Rolling_End
"
);
resolve
(
null
);
})
.
start
();
...
...
@@ -109,6 +113,11 @@ cc.Class({
});
},
// 解锁
reset
()
{
this
.
isLock
=
false
;
},
// 放大提示
blink
()
{
this
.
isBlinking
=
true
;
...
...
assets/OPW_BoardGame_L5R4/scene/OPW_BoardGame_L5R4.ts
View file @
84eed4d9
...
...
@@ -25,6 +25,8 @@ const MSG_FINISH = "msg_finish";
const
MSG_PLAYER_TO_TREE
=
"
msg_player_to_tree
"
;
const
MSG_PLAYER_TO_HOME
=
"
msg_player_to_home
"
;
const
MSG_PROFIX_END
=
"
__END__
"
;
const
DEBUG
=
true
;
const
TOTAL_SCORE
=
42
;
// 总分 - 双方分数之和等于 TOTAL_SCORE
@
ccclass
export
default
class
SceneComponent
extends
MyCocosSceneComponent
{
...
...
@@ -42,7 +44,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
playerId
;
// 当前玩家ID
isRoomOwner
;
// 是否为房主
recordWaitCount
;
// 录音等待倒计时
asyncToken
:
""
;
// 同步令牌 消息发送发会把令牌一同传给其他客户端,当客户端执行异步动作完毕以后 会把同步令牌
withAiPlayer
=
false
;
// 对手是否AI
addPreloadImage
()
{
// TODO 根据自己的配置预加载图片资源
...
...
@@ -89,6 +91,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
isAI
:
false
,
});
this
.
server
.
startMatch
();
// 设置AI玩家消息处理方法
this
.
server
.
onAIEvents
=
this
.
onAiEvents
.
bind
(
this
);
}
await
this
.
initHeadImgAndName
();
this
.
recordWaitCount
=
0
;
...
...
@@ -511,10 +515,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
eventsMap
[
eventName
].
pending
=
true
;
}
// 我方执行方法
// 我方
或者 AI方
执行方法
runFunctionMySide
(
runFunction
)
{
if
(
this
.
side
==
this
.
currentGameSide
)
{
runFunction
&&
runFunction
();
runFunction
&&
runFunction
(
false
);
}
else
if
(
this
.
side
!=
this
.
currentGameSide
&&
this
.
withAiPlayer
)
{
runFunction
&&
runFunction
(
true
);
}
}
...
...
@@ -522,6 +528,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
turntable
:
null
;
initTurntable
()
{
this
.
turntable
=
cc
.
find
(
"
Canvas/Turntable
"
).
getComponent
(
"
Turntable
"
);
this
.
turntable
.
initTurntable
(
DEBUG
);
cc
.
find
(
"
Canvas/Turntable
"
).
on
(
"
Rolling_Start
"
,
()
=>
{
// 游戏流程1: 玩家点击转盘
this
.
turntable
.
stopBlink
();
...
...
@@ -627,7 +634,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
})
}
}
else
{
if
(
this
.
currentGameSide
==
RED
)
{
this
.
playerToHome
(
this
.
redPlayerNode
,
this
.
redPlayerHomeNode
).
then
(()
=>
{
next
()
...
...
@@ -641,13 +647,17 @@ export default class SceneComponent extends MyCocosSceneComponent {
},
()
=>
{
this
.
runFunctionMySide
(()
=>
{
if
(
this
.
currentGameSide
==
RED
)
{
this
.
currentGameSide
=
BLUE
;
if
(
(
this
.
scoreBlue
+
this
.
scoreRed
)
>=
TOTAL_SCORE
)
{
this
.
runEvent
(
MSG_FINISH
,
{})
;
}
else
{
this
.
currentGameSide
=
RED
;
if
(
this
.
currentGameSide
==
RED
)
{
this
.
currentGameSide
=
BLUE
;
}
else
{
this
.
currentGameSide
=
RED
;
}
let
side
=
this
.
currentGameSide
;
this
.
runEvent
(
MSG_SWITCHSIDE
,
{
side
});
}
let
side
=
this
.
currentGameSide
;
this
.
runEvent
(
MSG_SWITCHSIDE
,
{
side
});
})
})
...
...
@@ -677,7 +687,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
},
(
param
)
=>
{
// 游戏流程3: 测评 - 对手不会出现测评界面
this
.
runFunctionMySide
(()
=>
{
this
.
runFunctionMySide
((
isAi
)
=>
{
console
.
log
(
"
语音评测开始
"
);
setTimeout
(()
=>
{
console
.
log
(
"
语音评测结束
"
)
...
...
@@ -690,7 +700,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 玩家回家
this
.
runEvent
(
MSG_PLAYER_TO_HOME
,
{
success
:
true
,
gemIndex
:
param
.
index
});
}
},
2000
);
},
DEBUG
?
10
:
2000
);
})
})
...
...
@@ -712,6 +722,38 @@ export default class SceneComponent extends MyCocosSceneComponent {
})
}
async
onAiEvents
(
event
)
{
// 当有AI玩家的时候 需要处理这部分逻辑
switch
(
event
.
type
)
{
case
MSG_ROLLING
:
this
,
this
.
scheduleOnce
(()
=>
{
this
.
eventsMap
[
MSG_ROLLING
+
MSG_PROFIX_END
].
fn
(
event
.
param
);
},
DEBUG
?
2
:
5.5
)
break
;
case
MSG_GO
:
this
,
this
.
scheduleOnce
(()
=>
{
this
.
eventsMap
[
MSG_GO
+
MSG_PROFIX_END
].
fn
(
event
.
param
);
},
1
)
break
;
case
MSG_PLAYER_TO_HOME
:
this
,
this
.
scheduleOnce
(()
=>
{
this
.
eventsMap
[
MSG_PLAYER_TO_HOME
+
MSG_PROFIX_END
].
fn
(
event
.
param
);
},
1
)
break
;
case
MSG_SWITCHSIDE
:
if
(
this
.
side
!=
this
.
currentGameSide
)
{
this
.
runEvent
(
MSG_PLAYER_TO_TREE
,{});
await
asyncDelay
(
1
)
const
nextGem
=
this
.
getNextQuestionIndex
();
this
.
runEvent
(
MSG_ROLLING
,
{
nextGem
:
nextGem
});
}
break
;
}
}
// 获取下一道题的索引
getNextQuestionIndex
()
{
let
nums
=
[]
...
...
@@ -753,10 +795,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
let
gIndex
=
-
1
;
let
index
=
-
1
;
switch
(
num
)
{
case
0
:
gIndex
=
Math
.
floor
((
Math
.
random
()
*
gem1
.
length
*
10
)
/
10
);
console
.
log
(
gIndex
);
index
=
gem1
[
gIndex
].
__index
;
break
;
case
1
:
gIndex
=
Math
.
floor
((
Math
.
random
()
*
gem2
.
length
*
10
)
/
10
);
console
.
log
(
gIndex
);
index
=
gem2
[
gIndex
].
__index
;
break
;
case
2
:
gIndex
=
Math
.
floor
((
Math
.
random
()
*
gem3
.
length
*
10
)
/
10
);
console
.
log
(
gIndex
);
index
=
gem3
[
gIndex
].
__index
;
break
;
default
:
gIndex
=
Math
.
floor
((
Math
.
random
()
*
gem1
.
length
*
10
)
/
10
);
console
.
log
(
gIndex
);
index
=
gem1
[
gIndex
].
__index
;
break
;
case
0
:
gIndex
=
Math
.
floor
((
Math
.
random
()
*
gem1
.
length
*
10
)
/
10
);
index
=
gem1
[
gIndex
].
__index
;
break
;
case
1
:
gIndex
=
Math
.
floor
((
Math
.
random
()
*
gem2
.
length
*
10
)
/
10
);
index
=
gem2
[
gIndex
].
__index
;
break
;
case
2
:
gIndex
=
Math
.
floor
((
Math
.
random
()
*
gem3
.
length
*
10
)
/
10
);
index
=
gem3
[
gIndex
].
__index
;
break
;
default
:
gIndex
=
Math
.
floor
((
Math
.
random
()
*
gem1
.
length
*
10
)
/
10
);
index
=
gem1
[
gIndex
].
__index
;
break
;
}
return
{
score
:
num
,
...
...
@@ -784,6 +826,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
const
redName
=
cc
.
find
(
"
Canvas/playerLand/red/name/label
"
).
getComponent
(
cc
.
Label
);
const
blueName
=
cc
.
find
(
"
Canvas/playerLand/blue/name/label
"
).
getComponent
(
cc
.
Label
);
this
.
allPlayerList
.
forEach
((
player
)
=>
{
if
(
player
.
uuid
.
indexOf
(
"
ai_
"
)
!=
-
1
)
{
this
.
withAiPlayer
=
true
;
}
this
.
getSpriteFrimeByUrl
(
player
.
headUrl
,
(
sf
)
=>
{
if
(
player
.
color
==
"
Red
"
)
{
red
.
getComponent
(
cc
.
Sprite
).
spriteFrame
=
sf
;
...
...
@@ -811,5 +856,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
turntable
.
disable
();
this
.
turntable
.
stopBlink
();
}
// 重置转盘
this
.
turntable
.
reset
();
}
}
assets/OPW_BoardGame_L5R4/script/Server.ts
View file @
84eed4d9
...
...
@@ -39,6 +39,8 @@ export class GameServer {
// { from: 24, to: 16 },
];
onAIEvents
:
Function
=
null
;
constructor
(
playerMaxNumber
,
networkHelper
)
{
this
.
playerMaxNumber
=
playerMaxNumber
;
this
.
networkHelper
=
networkHelper
;
...
...
@@ -210,7 +212,11 @@ export class GameServer {
}
}
else
{
this
.
_aiPlayerList
.
forEach
((
ai
:
AI
)
=>
{
ai
.
onFrameEvent
(
data
);
if
(
this
.
onAIEvents
)
{
this
.
onAIEvents
(
data
);
}
else
{
ai
.
onFrameEvent
(
data
);
}
});
}
}
...
...
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