Commit 7f0cc29e authored by limingzhe's avatar limingzhe

feat: AIAI

parent b75c59b4
......@@ -504,6 +504,10 @@ cc.Class({
this.showSearchIcon(res.data);
break;
case 'add_ai':
this.onAddAi(res.data);
return;
case 'send_result':
console.log('in send_result ~ ', JSON.stringify(res.data));
......@@ -515,9 +519,7 @@ cc.Class({
// this.getGood(res.data);
return;
case 'add_ai':
this.onAddAi(res.data);
return;
case 'add_player':
this.onAddPlayer(res.data);
......@@ -606,8 +608,58 @@ cc.Class({
// if (this.isTeacher) {
this.addUser(data)
// }
this.initAiGameData();
},
initAiGameData() {
// 默认数据
this.aiGameData = {"talkGroup":[{"word":"die"},{"word":"spy"},{"word":"pie"},{"word":"lie"},{"word":"light"}],"searchGroup":[{"word":"key","isRight":false},{"word":"candy","isRight":false},{"word":"jeep","isRight":false},{"word":"leaf","isRight":false},{"word":"bee","isRight":false}]}
},
setAiGameData(callback) {
const node = cc.find('middleLayer');
if (node) {
console.log('node exist');
const mScript = node.getComponent('middleLayer');
const coursewareid = mScript?.courseItem?.id;
if (!coursewareid) {
console.log(" !coursewareid~: ");
callback();
return;
}
console.log('~ coursewareid :' , coursewareid);
const count = 1;
const token = cc.sys.localStorage.getItem('token');
const url = "/api/oxford/courseware/v1/" + coursewareid + "/getanswer"
mScript.callNetworkApiGet(url, {coursewareid, token, count}, (res)=> {
console.log("res~: ", res);
if (typeof(res) == "string") {
res = JSON.parse(res);
console.log('objRes: ', res);
}
if(res.code == 200) {
// this.aiGameData = res
callback();
}
});
} else {
console.log('node not exist');
callback();
}
},
onRefreshPlayerList(data) {
console.log('onRefreshPlayerList data: ', data);
for (let i=0; i<data.length; i++) {
......@@ -650,15 +702,18 @@ cc.Class({
this.resultDataArr = [];
this.playerAudioDataArr = [];
this.initPlayerAB();
this.round = 1;
this.roundChangeCount = 0;
this.searchWrongCount = 0;
this.score = 0;
this.totalScore = 20;
this.selfScore = 0;
this.resultTalkGroup = [];
this.resultSearchGroup = [];
this.wordDataArr = baseData //JSON.parse( JSON.stringify(baseData) );
this.initPlayerAB();
if (this.isPlayer1) {
this.initDataGroup(baseData);
......@@ -678,10 +733,24 @@ cc.Class({
return;
}
this.isGameStart = true;
this.initData();
this.initView();
this.hideLoadingLayer();
const startShow = () => {
this.initData();
this.initView();
this.hideLoadingLayer();
}
if (this.aiGameData) {
this.setAiGameData(() => {
startShow();
});
} else {
startShow();
}
},
hideLoadingLayer() {
......@@ -1541,6 +1610,7 @@ cc.Class({
},
initDataGroup(baseData) {
this.dataGroup1 = baseData.splice(0, 5);
this.dataGroup2 = baseData;
},
......@@ -1567,14 +1637,15 @@ cc.Class({
this.bg = bg;
bg.on('touchstart', () => {
if (!this.isSearching || !this.curData) {
if (!this.isShowSearchIcon || !this.curData) {
return;
}
if (this.searchWrongCount >= 2) {
this.searchWrongCount ++;
if (this.searchWrongCount == 3) {
this.searchWrong();
} else {
this.searchWrongCount ++;
} else if (this.searchWrongCount < 3) {
playDragonBoneAnimation(this.coolcat, 'begin', -1);
this.playAudioByName('bad', () => {
......@@ -1829,9 +1900,9 @@ cc.Class({
let audio_url = data.audioUrl;
const score = data.result?.overall;
if (score >= 70) {
callback(audio_url);
callback(audio_url, score);
} else {
callback();
callback(null, score);
}
},
......@@ -1857,14 +1928,15 @@ cc.Class({
data = JSON.parse(data)
}
this.recordEnd(data, (audio_url) => {
this.recordEnd(data, (audio_url, score) => {
const sendData = {word: this.curData.word}
const sendData = {word: this.curData.word, score}
if (audio_url) {
sendData.audio_url = audio_url;
}
this.sendServerEvent('word_data', sendData);
this.resultTalkGroup.push(sendData);
this.showItemLight(audio_url, () => {
this.changeNewWord();
......@@ -1927,6 +1999,10 @@ cc.Class({
console.log(' getWordData: ', data);
this.showTalkIcon(false);
if(this.round == 1 && this.aiGameData) {
this.showAiSearching(data);
}
if ((this.isPlayer1 && this.round == 1) || (this.isPlayer2 && this.round == 2)) {
return;
}
......@@ -1981,6 +2057,59 @@ cc.Class({
},
showAiSearching(data) {
const {searchGroup} = this.aiGameData;
let index = -1;
for(let i=0; i<searchGroup.length; i++) {
if (searchGroup[i].word == data.word) {
index = i;
break;
}
}
const subData = searchGroup.splice(index, 1)[0];
this.sendServerEvent("show_search_icon", true)
setTimeout(() => {
if (subData.isRight) {
this.sendServerEvent('add_score')
}
this.sendServerEvent("show_search_icon", false)
if (searchGroup.length == 0) {
this.sendServerEvent("next_round")
}
}, 3000);
},
showAiTalking() {
this.sendServerEvent("show_talk_icon", true)
setTimeout(() => {
const {talkGroup} = this.aiGameData;
const subData = talkGroup.shift();
this.sendServerEvent('word_data', subData);
if (talkGroup.length > 0) {
setTimeout(() => {
this.showAiTalking();
}, 1500);
} else {
this.sendServerEvent("next_round")
}
}, 3000);
},
hideTalkBtn() {
this.talkBtn.active = false;
this.hideWave();
......@@ -2126,6 +2255,7 @@ cc.Class({
this.searchEnd();
});
this.resultSearchGroup.push({word: this.curData.word, isRight: true});
this.curTopSpr.active = false;
},
......@@ -2137,6 +2267,7 @@ cc.Class({
this.searchEnd();
});
this.resultSearchGroup.push({word: this.curData.word, isRight: false});
this.curTopSpr.active = false;
},
......@@ -2195,7 +2326,9 @@ cc.Class({
playDragonBoneAnimation(this.coolcat, 'normal', -1);
if (this.isPlayer1) {
if (this.aiGameData) {
this.showAiTalking();
}
} else {
this.dataGroup2 = this.wordDataArr;
this.initCurData();
......@@ -2209,8 +2342,35 @@ cc.Class({
gameEnd() {
console.log('in game end');
this.showResultLayer();
this.saveAnswer();
// console.log('this.resultDataArr: ', this.resultDataArr)
console.log('this.resultTalkGroup: ', JSON.stringify( this.resultTalkGroup) );
console.log('this.resultSearchGroup: ', JSON.stringify( this.resultSearchGroup) );
},
saveAnswer() {
console.log(' in saveAnswer')
const resultData = {
talkGroup: this.resultTalkGroup,
searchGroup: this.resultSearchGroup
}
const node = cc.find('middleLayer');
if (node) {
console.log('node exist');
const mScript = node.getComponent('middleLayer');
console.log(' saveAnswer ~ :', JSON.stringify(resultData));
mScript.saveAnswer(resultData, () => {
callback && callback();
})
}
},
showResultLayer() {
......
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