Commit f3cc17b8 authored by linzhiguo's avatar linzhiguo

+ 修改表单|是否正确

+ 增加框架统计
+ 去掉自动生成干扰
+ 去掉随机顺序
parent 80e00ea1
......@@ -8,4 +8,5 @@ export class WL01{
export class Rat{
word : string;
audio_url : string;
correct: boolean;
}
......@@ -46,7 +46,7 @@
</div>
<div class="section" >
<div class="section-content">
<div style="flex-wrap:wrap; width: 800px;display: flex;" >
<div style="flex-wrap:wrap; width: 800px;" >
<div style="display: flex; margin-bottom: 10px;">
<div style="flex:1">
......@@ -65,7 +65,11 @@
<app-audio-recorder [audioUrl]="data.audio_url" (audioUploaded)="onAudioUploadSuccess($event, data, 'audio_url')" ></app-audio-recorder>
</div>
</div>
<div style="display: flex; margin-bottom: 10px;">
<div style="flex:5">
<label nz-checkbox [(ngModel)]="data.correct" (ngModelChange)="saveItem()" >是否正确</label>
</div>
</div>
</div>
......
......@@ -30,11 +30,19 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.item = new WL01();
this.item.time = 3;
this.item.mouses = new Array<Rat>();
let needsave = false;
// 获取存储的数据
(<any>window).courseware.getData((data) => {
if (data) {
this.item = data;
let len = this.item.mouses.length;
for(let i = 0; i < len; i++){
if (this.item.mouses[i].correct != false && this.item.mouses[i].correct != true){
this.item.mouses[i].correct = true;
needsave = true;
}
}
}
//console.log(data);
this.init();
......@@ -44,6 +52,10 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
}, this.saveKey);
//console.log(this.item);
if (needsave){
this.saveItem();
}
}
ngOnChanges() {
......@@ -99,6 +111,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
addRat(){
let rat = new Rat();
rat.correct = true;
if (!this.item.mouses)
this.item.mouses = new Array<Rat>();
......
......@@ -162,67 +162,8 @@ cc.Class({
this.initView();
},
handleData(data){
let arr = {};
let len = data.mouses.length;
this._flag_number = len;
if (len == 1){
data.mouses[0].correct = true;
data.mouses[0].system = false;
return data;
}
arr.time = data.time;
arr.title = data.title;
arr.audio_url = data.audio_url;
arr.mouses = [];
let words = [], origin = [];
for(let i = 0; i < len; i++){
words[i] = data.mouses[i].word;
origin[i] = words[i];
arr.mouses[i] = {};
arr.mouses[i].system = false;
arr.mouses[i].word = data.mouses[i].word;
arr.mouses[i].correct = true;
arr.mouses[i].audio_url = data.mouses[i].audio_url;
}
do{
this.shuffle(words);
}while(this.compareOne(origin, words));
let letter, tmp, j;
for(let i = 0; i < len; i++){
j = i+ len;
arr.mouses[j] = {};
arr.mouses[j].system = true;
letter = data.mouses[i].word;
tmp = words[i];
arr.mouses[j].word = tmp;
arr.mouses[j].correct = letter == tmp.toUpperCase() || letter == tmp.toLowerCase();
arr.mouses[j].audio_url = data.mouses[i].audio_url;
}
return arr;
},
initView() {
window.WL = this;
this.data = this.handleData(this.data);
let count = 0;
do{
this.shuffle(this.data.mouses);
count++;
if (count > 50)
break;
}while(this.sameCount(this.data.mouses))
console.log(this.data.mouses);
this._touched = false;
......@@ -247,8 +188,6 @@ cc.Class({
// }
});
this.node.on(cc.Node.EventType.TOUCH_START, (event)=>{
if (!this._touched)
return;
......@@ -256,6 +195,8 @@ cc.Class({
let canvas = cc.find('Canvas');
let pos = canvas.convertToNodeSpaceAR(cc.v2(event.touch._point.x, event.touch._point.y))
let astr = this.flyVirus[i]._text.string;
let item, len = this.mouses.length;
for(let i = 0; i < len; i++){
item = this.mouses[i];
......@@ -263,7 +204,8 @@ cc.Class({
this._hammer.x = pos.x;
this._hammer.y = pos.y;
this._touched = false;
this.playAudioByName(this.hit_result?'correct':'incorrect');
this.playAudioByName(this.hit_result==false?'incorrect':'correct');
this.sendAnswer(this._astr, !(his.hit_result == false));
cc.tween(item)
.delay(0.5)
.call(()=>{
......@@ -320,7 +262,7 @@ cc.Class({
let width = flag_area.width - lyt.paddingRight;
let padding_x = lyt.spacingX;
let item, len = this._flag_number;
let item, len = this.data.mouses.length;
for(let i = 0; i < len; i++){
item = cc.instantiate(node);
flag_area.addChild(item);
......@@ -328,13 +270,15 @@ cc.Class({
item.scale = this.Between(0.5, (width/len - padding_x)/item.width, 1);
}
this._mouse_index = 0;
this._flag_index = 0;
cb && cb();
},
nextMouse(){
this._startTime = this.getTime();
console.log(this._startTime);
let item, len = this.mouses.length;
let mouse_id = RandomInt(len)
let info = this.data.mouses[this._mouse_index];
......@@ -343,7 +287,9 @@ cc.Class({
this._time_ani = null;
}
this._aiexerciseid = info.aiexerciseid;
this.hit_result = info.correct;
this._astr = info.word;
for(let i = 0; i < len; i++){
item = this.mouses[i];
......@@ -362,6 +308,14 @@ cc.Class({
this._time_ani = cc.tween(this.node)
.delay(this.data.time)
.call(()=>{
if(his.hit_result == false){
this.sendAnswer(this._astr, true);
}
else{
this.sendAnswer();
}
this.moveDown(mouse.node, ()=>{
this.tryFinished();
});
......@@ -415,10 +369,13 @@ cc.Class({
},
updateFlag(){
if (this._flag_index >= this._flag_number || this.hit_result == false)
let flag_number = this.data.mouses.length;
let flag_index = this._mouse_index;
if (flag_index >= flag_number || this.hit_result == false)
return;
let idx = this._flag_number- this._flag_index- 1;
let idx = flag_number- flag_index- 1;
let area = cc.find('Canvas/flag_area');
let flag = area.children[idx].getComponent(cc.Sprite);
flag.enabled = false;
......@@ -441,11 +398,6 @@ cc.Class({
this._laugh = null;
}
let mouse = this.data.mouses[this._mouse_index];
if (mouse.system == false){
this._flag_index ++;
}
this._mouse_index ++;
if (this._mouse_index >= this.data.mouses.length){
this._finished = true;
......@@ -475,6 +427,19 @@ cc.Class({
}
},
sendAnswer(answer="", isRight = false){
console.log(this._aiexerciseid, answer, isRight, this._startTime);
if (window && window.courseware) {
window.courseware.sendAnswer(this._aiexerciseid, answer, isRight, this._startTime);
}
},
getTime(){
var date = new Date();
return date.getTime();
},
playTimer(cb){
this.timer.node.active = true;
this.setTimerString('3');
......@@ -575,42 +540,5 @@ cc.Class({
});
},
// ------------------------------------------
shuffle(arr) {
for (let i=arr.length-1; i>=0; i--) {
let rIndex = Math.floor(Math.random()*(i+1));
let temp = arr[rIndex];
arr[rIndex] = arr[i];
arr[i] = temp;
}
return arr;
},
compareOne(a, b){
let len = a.length;
for(let i = 0; i < len; i++){
if (a[i] == b[i].toUpperCase() || a[i] == b[i].toLowerCase())
return true;
}
return false;
},
sameCount(mouses, max = 2){
let cnt = 0;
let v = mouses[0].correct;
let i, len = mouses.length;
for(i = 1; i < len; i++){
if (v == mouses[i].correct){
cnt++;
if (cnt >= max)
return true;
}
else{
v = mouses[i].correct;
cnt = 0;
}
}
return false;
},
});
......@@ -3,10 +3,13 @@ export const defaultData =
"mouses": [
{
"word": "a",
"audio_url": "http://staging-teach.cdn.ireadabc.com/dd360bbbcf5817eea26ac5fa3341ef5d.mp3"
"audio_url": "http://staging-teach.cdn.ireadabc.com/dd360bbbcf5817eea26ac5fa3341ef5d.mp3",
"correct":false
},
{
"word": "A"
"word": "A",
"correct":true
},
{
"word": "u",
......
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