Commit 4f0a62bb authored by 范雪寒's avatar 范雪寒

feat:

parent d92af14b
......@@ -4585,7 +4585,7 @@
"__id__": 106
},
"_enabled": true,
"letter": "E",
"letter": "",
"idx": "25",
"word": "end",
"jump": "",
......
......@@ -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 dice2 = cc.find("Canvas/bg/chessBoard/diceBg/dice");
dice2["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 dice2 = cc.find("Canvas/bg/chessBoard/diceBg/dice");
dice2["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);
}
......
......@@ -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;
......
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