Commit 77ca5448 authored by Tt's avatar Tt

02数据上传添加

parent 7b6396a1
...@@ -109,6 +109,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -109,6 +109,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
.sort(() => Math.random() - 0.5) .sort(() => Math.random() - 0.5)
} }
}) })
this.setTotalCount(this.wordDataList.length)
console.log(data); console.log(data);
} }
...@@ -130,40 +131,62 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -130,40 +131,62 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.resetView(); this.resetView();
this.showWord(); this.showWord();
} }
sendData(score) {
private rightCount: number;
private errorCount: number;
private totalCount: number;
addRightCount() {
if (!this.rightCount) this.rightCount = 0;
this.rightCount++;
}
addErrorCount() {
if (!this.errorCount) this.errorCount = 0;
this.errorCount++;
}
setTotalCount(val) {
this.totalCount = val;
}
sendData() {
return new Promise(res => { return new Promise(res => {
if (!this.totalCount) this.totalCount = this.rightCount + this.errorCount;
if (!this.totalCount) console.error('未设置总计数');
if (this.totalCount && !this.rightCount && !this.errorCount) {
this.rightCount = this.totalCount;
this.errorCount = 0;
}
let upData: any = { let upData: any = {
word_count: this.data.word_count || 0, right_count: this.rightCount || 0,
sentence_count: this.data.sentence_count || 0, wrong_count: this.errorCount || 0,
zi_count: this.data.zi_count || 0, total_count: this.totalCount || 0,
score: score,
}; };
upData.score = upData.right_count || 0;
let recordList = pg.hw.getRecord(); let recordList = pg.hw.getRecord();
if (recordList && recordList.length > 0) { if (recordList && recordList.length > 0) {
upData.recordList = recordList upData.result = recordList
} }
const middleLayer = cc.find('middleLayer').getComponent('middleLayer');
console.log('upload->' + JSON.stringify(upData)) console.log('upload->' + JSON.stringify(upData))
if (!cc.find('middleLayer')) return;
const middleLayer = cc.find('middleLayer').getComponent('middleLayer');
middleLayer.onHomeworkFinish(upData, () => { middleLayer.onHomeworkFinish(upData, () => {
res(''); res('');
}) })
}) })
} }
gameOver() { gameOver() {
this.sendData(this.wordDataList.length * 3).then(() => { this.sendData().then(() => {
}) if (!cc.find('middleLayer')) return;
this.scheduleOnce(() => {
this.onDestroy();
const middleLayer = cc.find('middleLayer'); const middleLayer = cc.find('middleLayer');
if (!middleLayer) return; if (middleLayer) {
const middleLayerComponent = middleLayer.getComponent('middleLayer'); const middleLayerComponent = middleLayer.getComponent('middleLayer');
middleLayerComponent.saveGolds(this.wordDataList.length * 3); // 保存金币数量;num 是获得金币的数量,数字类型; middleLayerComponent.goNextPage();
middleLayerComponent.goNextPage(); // 跳转到下一页 return;
}, 0.5) } else {
// pg.event.once('layer_ending_touch_replay', () => { console.log("[onFinish] middleLayer not found")
// this.replay(); }
// }) })
// pg.event.emit('layer_ending_show', { coin: this.wordDataList.length * 3 })
} }
private wordBgList: Array<cc.Node>; private wordBgList: Array<cc.Node>;
......
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