Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BoardGame2
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
BoardGame2
Commits
4f0a62bb
Commit
4f0a62bb
authored
Mar 15, 2022
by
范雪寒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:
parent
d92af14b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
21 deletions
+51
-21
BoardGame2.fire
assets/BoardGame2/scene/BoardGame2.fire
+1
-1
BoardGame2.ts
assets/BoardGame2/scene/BoardGame2.ts
+30
-16
Server.ts
assets/BoardGame2/script/Server.ts
+20
-4
No files found.
assets/BoardGame2/scene/BoardGame2.fire
View file @
4f0a62bb
...
...
@@ -4585,7 +4585,7 @@
"__id__": 106
},
"_enabled": true,
"letter": "
E
",
"letter": "",
"idx": "25",
"word": "end",
"jump": "",
...
...
assets/BoardGame2/scene/BoardGame2.ts
View file @
4f0a62bb
...
...
@@ -30,7 +30,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
_audioResList
.
push
({
url
:
this
.
data
.
waitingTurn
});
}
addPreloadAnima
()
{}
addPreloadAnima
()
{
}
onLoadEnd
()
{
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
...
...
@@ -55,7 +55,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
networkHelper
=
new
NetworkHelper
();
this
.
initNetworkListener
();
do
{
this
.
playerId
=
await
this
.
networkHelper
.
init
(
"
op_16
"
,
2
);
this
.
playerId
=
await
this
.
networkHelper
.
init
(
"
op_16
_2
"
,
2
);
if
(
this
.
playerId
===
null
)
{
console
.
log
(
"
onDestroy
"
);
this
.
networkHelper
.
onDestroy
();
...
...
@@ -68,6 +68,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
console
.
log
(
"
房主
"
);
this
.
isRoomOwner
=
true
;
this
.
server
=
new
GameServer
(
2
,
this
.
networkHelper
);
this
.
server
.
jumpList
=
this
.
getJumpList
();
await
this
.
networkHelper
.
startFrameSync
();
this
.
server
.
addPlayer
({
uuid
:
this
.
playerId
,
...
...
@@ -83,6 +84,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
initPiece
();
}
getJumpList
()
{
const
jumpList
=
[];
cc
.
find
(
'
Canvas/bg/chessBoard/boardItems
'
).
children
.
forEach
(
node
=>
{
const
itemData
=
node
.
getComponent
(
'
ItemData
'
);
if
(
itemData
.
jump
)
{
const
from
=
itemData
.
idx
;
const
to
=
itemData
.
jump
;
jumpList
.
push
({
from
,
to
});
}
});
return
jumpList
;
}
initBg
()
{
const
canvas
=
cc
.
find
(
"
Canvas
"
);
const
bgImg
=
cc
.
find
(
"
Canvas/bgImg
"
);
...
...
@@ -141,8 +155,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
.
start
();
});
const
dice
=
cc
.
find
(
"
Canvas/bg/chessBoard/diceBg/dice
"
);
dice
[
"
canClick
"
]
=
true
;
const
dice
2
=
cc
.
find
(
"
Canvas/bg/chessBoard/diceBg/dice
"
);
dice
2
[
"
canClick
"
]
=
true
;
}
stopBlinkTheDice
()
{
...
...
@@ -153,8 +167,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
node
.
scale
=
1
;
node
.
opacity
=
255
;
});
const
dice
=
cc
.
find
(
"
Canvas/bg/chessBoard/diceBg/dice
"
);
dice
[
"
canClick
"
]
=
false
;
const
dice
2
=
cc
.
find
(
"
Canvas/bg/chessBoard/diceBg/dice
"
);
dice
2
[
"
canClick
"
]
=
false
;
}
greyDice
()
{
...
...
@@ -401,7 +415,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
const
itemData
=
targetNode
.
getComponent
(
"
ItemData
"
);
if
(
itemData
.
letter
.
toLowerCase
()
==
this
.
_status
.
letter
.
toLowerCase
())
{
return
targetNode
;
return
targetNode
;
// if(itemData.jump!=""){
// const jtNode=board.children[parseInt(itemData.jump)];
// return jtNode;
...
...
@@ -414,12 +428,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
return
null
;
}
jumpBlock
(
idx
){
jumpBlock
(
idx
)
{
const
board
=
cc
.
find
(
"
Canvas/bg/chessBoard/boardItems
"
);
const
targetNode
=
board
.
children
[
idx
];
return
targetNode
;
}
getNextRightIdx
()
{
const
board
=
cc
.
find
(
"
Canvas/bg/chessBoard/boardItems
"
);
const
startIdx
=
this
.
_status
[
this
.
_status
.
current
];
...
...
@@ -492,7 +506,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
let
targetHeight
=
(
idx
/
(
board
.
children
.
length
-
2
))
*
prograssbar
.
height
;
console
.
log
(
idx
+
"
_进度条高:
"
+
targetHeight
);
console
.
log
(
idx
+
"
_进度条高:
"
+
targetHeight
);
const
offsetX
=
{
Red
:
-
45
,
Blue
:
45
};
const
offsetY
=
{
Red
:
-
90
,
Blue
:
-
90
};
...
...
@@ -618,7 +632,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
.
delay
(
0.5
)
.
to
(
0.5
,
{
opacity
:
0
})
.
call
(()
=>
{
resolve
();
resolve
(
null
);
})
.
start
();
});
...
...
@@ -656,7 +670,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
networkHelper
.
leaveRoom
();
this
.
log
(
"
playerOffLine
"
+
JSON
.
stringify
(
event
));
});
this
.
networkHelper
.
on
(
"
gameStart
"
,
(
event
)
=>
{});
this
.
networkHelper
.
on
(
"
gameStart
"
,
(
event
)
=>
{
});
this
.
networkHelper
.
on
(
"
frameEvent
"
,
(
event
)
=>
{
event
.
data
.
frame
.
items
.
forEach
(
async
(
item
)
=>
{
if
(
this
.
server
)
{
...
...
@@ -735,10 +749,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
pieceRed
[
"
cantMove
"
]
=
false
;
pieceBlue
[
"
cantMove
"
]
=
false
;
await
this
.
pieceFindRightBlock
(
rightBlock
,
idx
);
const
riData
=
rightBlock
.
getComponent
(
"
ItemData
"
);
if
(
riData
.
jump
!=
""
)
{
rightBlock
=
this
.
jumpBlock
(
parseInt
(
riData
.
jump
));
const
riData
=
rightBlock
.
getComponent
(
"
ItemData
"
);
if
(
riData
.
jump
!=
""
)
{
rightBlock
=
this
.
jumpBlock
(
parseInt
(
riData
.
jump
));
idx
=
parseInt
(
riData
.
jump
);
//this.getNextRightIdx();
await
this
.
pieceFindRightBlock
(
rightBlock
,
idx
);
}
...
...
assets/BoardGame2/script/Server.ts
View file @
4f0a62bb
...
...
@@ -28,6 +28,17 @@ export class GameServer {
"
http://staging-teach.cdn.ireadabc.com/f40ce4a8630039c4cf48a63fc1399c52.png
"
,
];
jumpList
=
[
// { from: 2, to: 11 },
// { from: 3, to: 7 },
// { from: 8, to: 18 },
// { from: 9, to: 2 },
// { from: 12, to: 15 },
// { from: 13, to: 1 },
// { from: 21, to: 5 },
// { from: 24, to: 16 },
];
constructor
(
playerMaxNumber
,
networkHelper
)
{
this
.
playerMaxNumber
=
playerMaxNumber
;
this
.
networkHelper
=
networkHelper
;
...
...
@@ -107,7 +118,7 @@ export class GameServer {
}
async
onFrameEvent
(
data
)
{
if
(
this
.
gameStatus
.
gameOver
)
{
if
(
this
.
gameStatus
[
'
gameOver
'
]
)
{
return
;
}
if
(
data
.
type
==
"
roll
"
)
{
...
...
@@ -128,15 +139,20 @@ export class GameServer {
type
:
"
SERVER_playerWin
"
,
color
:
this
.
gameStatus
.
current
,
});
this
.
gameStatus
.
gameOver
=
true
;
this
.
gameStatus
[
'
gameOver
'
]
=
true
;
}
}
else
if
(
data
.
type
==
"
right
"
)
{
if
(
this
.
gameStatus
.
letter
!=
""
)
{
this
.
gameStatus
.
letter
=
""
;
this
.
gameStatus
[
data
.
color
]
=
data
.
idx
;
const
jump
=
this
.
jumpList
.
find
(
jump
=>
parseInt
(
jump
.
from
)
==
parseInt
(
data
.
idx
));
const
letterList
=
this
.
getLetterList
();
console
.
log
(
"
letterList =
"
+
JSON
.
stringify
(
letterList
));
if
(
letterList
.
length
>
0
)
{
if
(
jump
)
{
this
.
gameStatus
[
data
.
color
]
=
parseInt
(
jump
.
to
);
}
this
.
changeSide
();
this
.
networkHelper
.
sendFrame
({
type
:
"
SERVER_playerRight
"
,
...
...
@@ -149,7 +165,7 @@ export class GameServer {
type
:
"
SERVER_playerWin
"
,
color
:
this
.
gameStatus
.
current
,
});
this
.
gameStatus
.
gameOver
=
true
;
this
.
gameStatus
[
'
gameOver
'
]
=
true
;
}
}
else
{
console
.
log
(
'
汪汪汪
'
);
...
...
@@ -206,7 +222,7 @@ export class GameServer {
startAI
()
{
this
.
playerList
.
filter
((
player
)
=>
player
.
isAI
==
true
)
.
forEach
((
player
)
=>
{});
.
forEach
((
player
)
=>
{
});
}
_timeoutIds
=
null
;
...
...
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