Commit c67bfeb5 authored by Tt's avatar Tt

完成

parent 26b6f182
...@@ -47,7 +47,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -47,7 +47,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
Red: 0, Red: 0,
Blue: 0, Blue: 0,
letter: "", letter: "",
current: "Blue", current: "Red",
}; };
playerId; playerId;
isRoomOwner; isRoomOwner;
...@@ -57,7 +57,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -57,7 +57,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", 2); this.playerId = await this.networkHelper.init("l2_boardgame2_tree", 2);
if (this.playerId === null) { if (this.playerId === null) {
console.log("onDestroy"); console.log("onDestroy");
this.networkHelper.onDestroy(); this.networkHelper.onDestroy();
...@@ -105,15 +105,13 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -105,15 +105,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
initView() { initView() {
this.addComponents();
this.hideVoice(); this.hideVoice();
this.initBg(); this.initBg();
this.initLoadingLayer(); this.initLoadingLayer();
this.initPiece(); this.initPiece();
} }
addComponents() {
getJumpList() {
const jumpList = [];
cc.find('Canvas/bg/chessBoard/boardItems').children.forEach(node => { cc.find('Canvas/bg/chessBoard/boardItems').children.forEach(node => {
let itemData = node.getComponent("BoardGame2_ItemData"); let itemData = node.getComponent("BoardGame2_ItemData");
if (!itemData) { if (!itemData) {
...@@ -131,14 +129,18 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -131,14 +129,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
} }
}); });
// cc.find('Canvas/bg/chessBoard/boardItems').children.forEach(node => { }
// const itemData = node.getComponent("BoardGame2_ItemData");
// if (itemData.jump) { getJumpList() {
// const from = itemData.idx; const jumpList = [];
// const to = itemData.jump; cc.find('Canvas/bg/chessBoard/boardItems').children.forEach(node => {
// jumpList.push({ from, to }); const itemData = node.getComponent("BoardGame2_ItemData");
// } if (itemData.jump) {
// }); const from = itemData.idx;
const to = itemData.jump;
jumpList.push({ from, to });
}
});
return jumpList; return jumpList;
} }
...@@ -492,6 +494,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -492,6 +494,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
.start(); .start();
} }
getCurrentBlock() {
const board = cc.find("Canvas/bg/chessBoard/boardItems");
const startIdx = this._status[this._status.current];
return board.children[startIdx]
}
getRightBlock() { getRightBlock() {
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];
...@@ -872,11 +879,19 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -872,11 +879,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
let idx = this.getNextRightIdx(); let idx = this.getNextRightIdx();
const pieceRed = cc.find("Canvas/bg/chessBoard/pieceRed"); const pieceRed = cc.find("Canvas/bg/chessBoard/pieceRed");
const pieceBlue = cc.find("Canvas/bg/chessBoard/pieceBlue"); const pieceBlue = cc.find("Canvas/bg/chessBoard/pieceBlue");
const node = cc.find(
`Canvas/bg/chessBoard/piece${this._status.current}`
);
node["touchStartPos"] = {
nodeX: node.x,
nodeY: node.y,
touchX: node.x,
touchY: node.y,
};
let lastIdx = this._status[playerMe.color];
pieceRed["cantMove"] = false; pieceRed["cantMove"] = false;
pieceBlue["cantMove"] = false; pieceBlue["cantMove"] = false;
await this.pieceFindRightBlock(rightBlock, idx); await this.pieceFindRightBlock(rightBlock, idx);
pieceRed["cantMove"] = true;
pieceBlue["cantMove"] = true;
let isSuccess = await this.showVoice(rightBlock); let isSuccess = await this.showVoice(rightBlock);
this.hideVoice(); this.hideVoice();
if (isSuccess) { if (isSuccess) {
...@@ -887,6 +902,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -887,6 +902,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
color: playerMe.color, color: playerMe.color,
}); });
} else { } else {
this._status[playerMe.color] = lastIdx
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: "wrong", type: "wrong",
uuid: playerMe.uuid, uuid: playerMe.uuid,
...@@ -897,6 +913,19 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -897,6 +913,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
} else if (item.data.type == "SERVER_playerRight") { } else if (item.data.type == "SERVER_playerRight") {
const playerMe = this.allPlayerList.find((player) => player.uuid == this.playerId); const playerMe = this.allPlayerList.find((player) => player.uuid == this.playerId);
if (this._status.current == playerMe.color) { if (this._status.current == playerMe.color) {
// let rightBlock = this.getRightBlock();
let rightBlock = this.getCurrentBlock();
const pieceRed = cc.find("Canvas/bg/chessBoard/pieceRed");
const pieceBlue = cc.find("Canvas/bg/chessBoard/pieceBlue");
const riData = rightBlock.getComponent("BoardGame2_ItemData");
if (riData.jump != "") {
rightBlock = this.jumpBlock(parseInt(riData.jump));
let idx = parseInt(riData.jump);//this.getNextRightIdx();
await this.pieceFindRightBlock(rightBlock, idx);
}
pieceRed["cantMove"] = true;
pieceBlue["cantMove"] = true;
this._status.letter = ""; this._status.letter = "";
this.changeSide(); this.changeSide();
this.updateStatus(); this.updateStatus();
...@@ -1005,6 +1034,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1005,6 +1034,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
console.log('startTest->' + this._status.letter); console.log('startTest->' + this._status.letter);
courseware && courseware.startTest(this._status.letter); //开始录音 courseware && courseware.startTest(this._status.letter); //开始录音
setTimeout(async () => { setTimeout(async () => {
if (!courseware) {
let testData = { let testData = {
"dtLastResponse": "2021-09-17 13:36:26:109", "dtLastResponse": "2021-09-17 13:36:26:109",
"refText": "I haven't found anything out about him yet.", "refText": "I haven't found anything out about him yet.",
...@@ -1016,7 +1046,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1016,7 +1046,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
"fluency": 60, "fluency": 60,
"rhythm": 90, "rhythm": 90,
"kernel_version": "5.2.4", "kernel_version": "5.2.4",
"overall": 25,//75 "overall": 80,//25
"integrity": 100, "integrity": 100,
"duration": "6.779", "duration": "6.779",
"rear_tone": "fall", "rear_tone": "fall",
...@@ -1122,7 +1152,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1122,7 +1152,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
"tokenId": "6144295408558b08dd000001", "tokenId": "6144295408558b08dd000001",
"applicationId": "154838659000009e" "applicationId": "154838659000009e"
} }
if (!courseware) {
if (this.recrodEnd(testData)) { if (this.recrodEnd(testData)) {
await this.showVoiceGood(); await this.showVoiceGood();
return resolve(true) return resolve(true)
...@@ -1186,12 +1215,13 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1186,12 +1215,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
}); });
} }
async recrodEnd(data) { recrodEnd(data) {
// return true; // return true;
let score = data.result.overall; let score = data.result.overall;
let isSuccess = this.checkWords(data); let isSuccess = this.checkWords(data);
this.log("score->" + score);
this.log("isSuccess->" + isSuccess);
if (score >= 70 && isSuccess) { if (score >= 70 && isSuccess) {
//提示成功
return true; return true;
} else { } else {
return false; return false;
...@@ -1200,13 +1230,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1200,13 +1230,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
private checkWords(data) { private checkWords(data) {
const sentences = data.result.sentences; const sentences = data.result.sentences;
if (!sentences) return true;
for (let i = 0; i < sentences.length; i++) { for (let i = 0; i < sentences.length; i++) {
const details = sentences[i].details; const details = sentences[i].details;
const isSuccess = details.some(item => item.overall <= 40); const isSuccess = details.some(item => item.overall <= 40);
if (isSuccess) { if (isSuccess) return false;
return false;
}
} }
return true; return true;
} }
......
...@@ -8,7 +8,7 @@ export class AI { ...@@ -8,7 +8,7 @@ export class AI {
Red: 0, Red: 0,
Blue: 0, Blue: 0,
letter: "", letter: "",
current: "Blue", current: "Red",
}; };
constructor(networkHelper: NetworkHelper, playerData: any) { constructor(networkHelper: NetworkHelper, playerData: any) {
...@@ -49,12 +49,21 @@ export class AI { ...@@ -49,12 +49,21 @@ export class AI {
//调试加速 2 Math.random() * 3 + 4 //调试加速 2 Math.random() * 3 + 4
await asyncDelay(Math.random() * 3 + 4); await asyncDelay(Math.random() * 3 + 4);
const idx = this.getNextRightIdx(); const idx = this.getNextRightIdx();
if (Math.random() < 0.8) {
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: "right", type: "right",
idx: idx, idx: idx,
uuid: this.playerData.uuid, uuid: this.playerData.uuid,
color: this.playerData.color, color: this.playerData.color,
}); });
} else {
this.networkHelper.sendFrame({
type: "wrong",
uuid: this.playerData.uuid,
color: this.playerData.color,
});
}
} }
} }
} }
......
...@@ -58,7 +58,7 @@ export class GameServer { ...@@ -58,7 +58,7 @@ export class GameServer {
name: this.nameList.splice(0, 1)[0], name: this.nameList.splice(0, 1)[0],
uuid: player.uuid, uuid: player.uuid,
color: color:
player.uuid == this.networkHelper.room.roomInfo.owner ? "Blue" : "Red", player.uuid == this.networkHelper.room.roomInfo.owner ? "Red" : "Blue",
isAI: player.isAI, isAI: player.isAI,
headUrl: this.headUrls.splice(0, 1)[0], headUrl: this.headUrls.splice(0, 1)[0],
}); });
...@@ -82,7 +82,7 @@ export class GameServer { ...@@ -82,7 +82,7 @@ export class GameServer {
Red: 0, Red: 0,
Blue: 0, Blue: 0,
letter: "", letter: "",
current: "Blue", current: "Red",
}; };
startGame() { startGame() {
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
...@@ -108,13 +108,13 @@ export class GameServer { ...@@ -108,13 +108,13 @@ export class GameServer {
const playerInfo = { const playerInfo = {
uuid: "ai_" + i, uuid: "ai_" + i,
isAI: true, isAI: true,
color: "Red", color: "Blue",
}; };
this._aiPlayerList.push(new AI(this.networkHelper, playerInfo)); this._aiPlayerList.push(new AI(this.networkHelper, playerInfo));
this.addPlayer(playerInfo); this.addPlayer(playerInfo);
} }
//TODO:调试加速 //TODO:调试加速
}, 1000)//RandomInt(10000, 15000) }, 10000)//RandomInt(10000, 15000)
); );
} }
} }
...@@ -128,9 +128,9 @@ export class GameServer { ...@@ -128,9 +128,9 @@ export class GameServer {
console.log('letterList: ', letterList); console.log('letterList: ', letterList);
if (letterList.length > 0) { if (letterList.length > 0) {
if (this.gameStatus.letter == "") { if (this.gameStatus.letter == "") {
// let max = Math.max(letterList.length - 2, 0); // let max = Math.max(9, 0);
// let letter = letterList[max];//[RandomInt(letterList.length) % 3];//转盘只有1-3 // let letter = letterList[max];//[RandomInt(letterList.length) % 3];//转盘只有1-3
// if (this.gameStatus.current != 'Blue') { // if (this.gameStatus.current == 'Blue') {
// letter = letterList[0] // letter = letterList[0]
// } // }
let letter = letterList[RandomInt(letterList.length) % 3]; let letter = letterList[RandomInt(letterList.length) % 3];
......
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