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

feat:

parent d92af14b
...@@ -4585,7 +4585,7 @@ ...@@ -4585,7 +4585,7 @@
"__id__": 106 "__id__": 106
}, },
"_enabled": true, "_enabled": true,
"letter": "E", "letter": "",
"idx": "25", "idx": "25",
"word": "end", "word": "end",
"jump": "", "jump": "",
......
...@@ -30,7 +30,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -30,7 +30,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this._audioResList.push({ url: this.data.waitingTurn }); this._audioResList.push({ url: this.data.waitingTurn });
} }
addPreloadAnima() {} addPreloadAnima() { }
onLoadEnd() { onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考 // TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
...@@ -55,7 +55,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -55,7 +55,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.networkHelper = new NetworkHelper(); this.networkHelper = new NetworkHelper();
this.initNetworkListener(); this.initNetworkListener();
do { do {
this.playerId = await this.networkHelper.init("op_16", 2); this.playerId = await this.networkHelper.init("op_16_2", 2);
if (this.playerId === null) { if (this.playerId === null) {
console.log("onDestroy"); console.log("onDestroy");
this.networkHelper.onDestroy(); this.networkHelper.onDestroy();
...@@ -68,6 +68,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -68,6 +68,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
console.log("房主"); console.log("房主");
this.isRoomOwner = true; this.isRoomOwner = true;
this.server = new GameServer(2, this.networkHelper); this.server = new GameServer(2, this.networkHelper);
this.server.jumpList = this.getJumpList();
await this.networkHelper.startFrameSync(); await this.networkHelper.startFrameSync();
this.server.addPlayer({ this.server.addPlayer({
uuid: this.playerId, uuid: this.playerId,
...@@ -83,6 +84,19 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -83,6 +84,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.initPiece(); 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() { initBg() {
const canvas = cc.find("Canvas"); const canvas = cc.find("Canvas");
const bgImg = cc.find("Canvas/bgImg"); const bgImg = cc.find("Canvas/bgImg");
...@@ -141,8 +155,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -141,8 +155,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
.start(); .start();
}); });
const dice = cc.find("Canvas/bg/chessBoard/diceBg/dice"); const dice2 = cc.find("Canvas/bg/chessBoard/diceBg/dice");
dice["canClick"] = true; dice2["canClick"] = true;
} }
stopBlinkTheDice() { stopBlinkTheDice() {
...@@ -153,8 +167,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -153,8 +167,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
node.scale = 1; node.scale = 1;
node.opacity = 255; node.opacity = 255;
}); });
const dice = cc.find("Canvas/bg/chessBoard/diceBg/dice"); const dice2 = cc.find("Canvas/bg/chessBoard/diceBg/dice");
dice["canClick"] = false; dice2["canClick"] = false;
} }
greyDice() { greyDice() {
...@@ -401,7 +415,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -401,7 +415,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
const itemData = targetNode.getComponent("ItemData"); const itemData = targetNode.getComponent("ItemData");
if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) { if (itemData.letter.toLowerCase() == this._status.letter.toLowerCase()) {
return targetNode; return targetNode;
// if(itemData.jump!=""){ // if(itemData.jump!=""){
// const jtNode=board.children[parseInt(itemData.jump)]; // const jtNode=board.children[parseInt(itemData.jump)];
// return jtNode; // return jtNode;
...@@ -414,12 +428,12 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -414,12 +428,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
return null; return null;
} }
jumpBlock(idx){ jumpBlock(idx) {
const board = cc.find("Canvas/bg/chessBoard/boardItems"); const board = cc.find("Canvas/bg/chessBoard/boardItems");
const targetNode = board.children[idx]; const targetNode = board.children[idx];
return targetNode; return targetNode;
} }
getNextRightIdx() { getNextRightIdx() {
const board = cc.find("Canvas/bg/chessBoard/boardItems"); const board = cc.find("Canvas/bg/chessBoard/boardItems");
const startIdx = this._status[this._status.current]; const startIdx = this._status[this._status.current];
...@@ -492,7 +506,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -492,7 +506,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
let targetHeight = let targetHeight =
(idx / (board.children.length - 2)) * prograssbar.height; (idx / (board.children.length - 2)) * prograssbar.height;
console.log(idx+"_进度条高:"+targetHeight); console.log(idx + "_进度条高:" + targetHeight);
const offsetX = { Red: -45, Blue: 45 }; const offsetX = { Red: -45, Blue: 45 };
const offsetY = { Red: -90, Blue: -90 }; const offsetY = { Red: -90, Blue: -90 };
...@@ -618,7 +632,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -618,7 +632,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
.delay(0.5) .delay(0.5)
.to(0.5, { opacity: 0 }) .to(0.5, { opacity: 0 })
.call(() => { .call(() => {
resolve(); resolve(null);
}) })
.start(); .start();
}); });
...@@ -656,7 +670,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -656,7 +670,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.networkHelper.leaveRoom(); this.networkHelper.leaveRoom();
this.log("playerOffLine" + JSON.stringify(event)); this.log("playerOffLine" + JSON.stringify(event));
}); });
this.networkHelper.on("gameStart", (event) => {}); this.networkHelper.on("gameStart", (event) => { });
this.networkHelper.on("frameEvent", (event) => { this.networkHelper.on("frameEvent", (event) => {
event.data.frame.items.forEach(async (item) => { event.data.frame.items.forEach(async (item) => {
if (this.server) { if (this.server) {
...@@ -735,10 +749,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -735,10 +749,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
pieceRed["cantMove"] = false; pieceRed["cantMove"] = false;
pieceBlue["cantMove"] = false; pieceBlue["cantMove"] = false;
await this.pieceFindRightBlock(rightBlock, idx); await this.pieceFindRightBlock(rightBlock, idx);
const riData=rightBlock.getComponent("ItemData"); const riData = rightBlock.getComponent("ItemData");
if(riData.jump!=""){ if (riData.jump != "") {
rightBlock=this.jumpBlock(parseInt(riData.jump)); rightBlock = this.jumpBlock(parseInt(riData.jump));
idx = parseInt(riData.jump);//this.getNextRightIdx(); idx = parseInt(riData.jump);//this.getNextRightIdx();
await this.pieceFindRightBlock(rightBlock, idx); await this.pieceFindRightBlock(rightBlock, idx);
} }
......
...@@ -28,6 +28,17 @@ export class GameServer { ...@@ -28,6 +28,17 @@ export class GameServer {
"http://staging-teach.cdn.ireadabc.com/f40ce4a8630039c4cf48a63fc1399c52.png", "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) { constructor(playerMaxNumber, networkHelper) {
this.playerMaxNumber = playerMaxNumber; this.playerMaxNumber = playerMaxNumber;
this.networkHelper = networkHelper; this.networkHelper = networkHelper;
...@@ -107,7 +118,7 @@ export class GameServer { ...@@ -107,7 +118,7 @@ export class GameServer {
} }
async onFrameEvent(data) { async onFrameEvent(data) {
if (this.gameStatus.gameOver) { if (this.gameStatus['gameOver']) {
return; return;
} }
if (data.type == "roll") { if (data.type == "roll") {
...@@ -128,15 +139,20 @@ export class GameServer { ...@@ -128,15 +139,20 @@ export class GameServer {
type: "SERVER_playerWin", type: "SERVER_playerWin",
color: this.gameStatus.current, color: this.gameStatus.current,
}); });
this.gameStatus.gameOver = true; this.gameStatus['gameOver'] = true;
} }
} else if (data.type == "right") { } else if (data.type == "right") {
if (this.gameStatus.letter != "") { if (this.gameStatus.letter != "") {
this.gameStatus.letter = ""; this.gameStatus.letter = "";
this.gameStatus[data.color] = data.idx; this.gameStatus[data.color] = data.idx;
const jump = this.jumpList.find(jump => parseInt(jump.from) == parseInt(data.idx));
const letterList = this.getLetterList(); const letterList = this.getLetterList();
console.log("letterList = " + JSON.stringify(letterList)); console.log("letterList = " + JSON.stringify(letterList));
if (letterList.length > 0) { if (letterList.length > 0) {
if (jump) {
this.gameStatus[data.color] = parseInt(jump.to);
}
this.changeSide(); this.changeSide();
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: "SERVER_playerRight", type: "SERVER_playerRight",
...@@ -149,7 +165,7 @@ export class GameServer { ...@@ -149,7 +165,7 @@ export class GameServer {
type: "SERVER_playerWin", type: "SERVER_playerWin",
color: this.gameStatus.current, color: this.gameStatus.current,
}); });
this.gameStatus.gameOver = true; this.gameStatus['gameOver'] = true;
} }
} else { } else {
console.log('汪汪汪'); console.log('汪汪汪');
...@@ -206,7 +222,7 @@ export class GameServer { ...@@ -206,7 +222,7 @@ export class GameServer {
startAI() { startAI() {
this.playerList this.playerList
.filter((player) => player.isAI == true) .filter((player) => player.isAI == true)
.forEach((player) => {}); .forEach((player) => { });
} }
_timeoutIds = null; _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