Commit 5b9a217b authored by Tt's avatar Tt

游戏完成

parent dd7329ff
This diff is collapsed.
This diff is collapsed.
......@@ -16,17 +16,31 @@ export class Fish {
}
export class Option {
// public type;
public type: string;
public image: string;
public audio: string;
public text: string;
public right: boolean;
constructor(data) {
this.type = data.type;
this.image = data.image;
this.audio = data.audio;
this.text = data.text;
this.right = data.isRight == 1;
}
}
export class Question {
public txt;
// public picUrl;
public audioUrl;
// public right: boolean;
public data;
public id: number;
public count: number;
public time: number;
public touchRight: boolean;
public parent;
public options: Array<Option>;
public rights: Array<Option>;
constructor(data, id) {
this.id = id;
// this.type = data.type;
......@@ -37,6 +51,15 @@ export class Option {
this.audioUrl = data.audio;
// this.right = data.right;
this.touchRight = false;
this.rights = [];
this.options = data.options.map(op => new Option(op))
}
addRight(option) {
this.rights.push(option)
}
checkRight() {
let rights = this.options.filter(op => op.right);
return this.rights.length >= rights.length
}
}
export class Item {
......@@ -124,7 +147,7 @@ export default class Game {
return Game.ins;
}
private data: any;
private lists: Array<Option>
private lists: Array<Question>
public player: Player;
public robot: Robot;
public state: GAME_STATE;
......@@ -156,61 +179,44 @@ export default class Game {
this.data = data.questions;
}
public start: boolean;
public page: number;
public idx: number;
reset() {
this.player.reset();
this.robot.reset();
this.page = 1;
this.idx = 0;
this.start = true;
this.lists = [];
for (let i = 0; i < this.data.length; i++) {
let data = this.data[i];
this.lists.push(new Option(data, i + 1));
this.lists.push(new Question(data, i + 1));
}
this.state = GAME_STATE.WAIT;
this.total = this.lists.length;
}
public getCardInfo() {
let option: Option = this.lists.splice(0, 1)[0];
// if (this.lists.length > 0) {
// let random = Math.floor(Math.random() * this.lists.length);
// option = this.lists.splice(random, 1)[0];
// } else {
// option = null;
// }
console.log(" this.cardInfo=======", option)
return option;
}
// checkSuccess(arr: Option[]) {
// let data = this.getCurrentPage();
// let options = data.optionList.concat();
// options.sort((A, B) => A.id - B.id)
// for (let i = 0; i < options.length; i++) {
// if (arr[i] && arr[i].id != options[i].id) {
// return false;
// }
// }
// return true;
// }
// getDataByPage(page): Item {
// return this.lists.filter(li => li.page == page)[0]
// }
// getCurrentPage(): Item {
// let page = this.page;
// return this.lists.filter(li => li.page == page)[0]
// public getCardInfo() {
// let option: Question = this.lists.splice(0, 1)[0];
// // if (this.lists.length > 0) {
// // let random = Math.floor(Math.random() * this.lists.length);
// // option = this.lists.splice(random, 1)[0];
// // } else {
// // option = null;
// // }
// console.log(" this.cardInfo=======", option)
// return option;
// }
getCurrentPage(): Question {
return this.lists[this.idx];
}
getTotalPageNum() {
return this.lists.length;
}
getCurrentPageNum() {
return this.page;
return this.idx;
}
addPage() {
this.page += 1;
this.idx += 1;
}
get getTotla() {
get getTotal() {
return this.lists.length;
// this.total = 0;
// this.lists.forEach((item) => {
......@@ -219,6 +225,6 @@ export default class Game {
// return this.total;
}
get isOver() {
return this.page > this.lists.length;
return this.idx > this.lists.length;
}
}
\ No newline at end of file
......@@ -187,6 +187,12 @@ let pg = {
if (!child) return pg.logger.w("findChildByPath error->" + "找不到此节点,请检查层级路径:" + childPath);
return child;
},
//--------------------坐标转换--------------------------------------
coverPosition(sourceNode, targetNode) {
let startWorldPos = sourceNode.convertToWorldSpaceAR(cc.v2(0, 0));
let startPos = targetNode.convertToNodeSpaceAR(startWorldPos);
return startPos;
},
//--------------------触控事件--------------------------------
//添加监听
touchOn(item, callback, target) {
......
export const defaultData = {
"title": "听音选择",
"questions": [
{
"audio": "http://staging-teach.cdn.ireadabc.com/c14938125a52096dc0be9fbbf6638cb2_l.mp3",
"time": null,
"duration": "",
"audioName": "进入下一题.mp3",
"options": [
{
"type": "text",
"audio": "",
"image": "",
"word": "",
"text": "apple"
},
{
"type": "text",
"audio": "",
"image": "",
"word": "",
"text": "banner"
}, { "type": "text", "audio": "", "image": "", "word": "", "text": "pie" }, { "type": "text", "audio": "", "image": "", "word": "", "text": "test" }]
}, { "audio": "http://staging-teach.cdn.ireadabc.com/c14938125a52096dc0be9fbbf6638cb2_l.mp3", "time": null, "duration": "", "audioName": "进入下一题.mp3", "options": [{ "type": "img", "audio": "", "image": "http://staging-teach.cdn.ireadabc.com/07c89b4a6a1a18b0c0a3029720fdfdbc.png", "word": "" }, { "type": "img", "audio": "", "image": "http://staging-teach.cdn.ireadabc.com/d20b34eac11f5687d3386389aea170a2.png", "word": "" }, { "type": "img", "audio": "", "image": "http://staging-teach.cdn.ireadabc.com/639ada88f3e52966103caca156f720d6.png", "word": "" }, { "type": "img", "audio": "", "image": "http://staging-teach.cdn.ireadabc.com/38408b9ce048508830086c5e5cd2f384.png", "word": "" }] }]
}
\ No newline at end of file
export const defaultData = { "title": "听音选择", "questions": [{ "audio": "http://staging-teach.cdn.ireadabc.com/c14938125a52096dc0be9fbbf6638cb2_l.mp3", "time": null, "duration": "", "audioName": "进入下一题.mp3", "options": [{ "type": "text", "audio": "", "image": "", "word": "", "text": "apple", "isRight": "1" }, { "type": "text", "audio": "", "image": "", "word": "", "text": "banner", "isRight": "0" }, { "type": "text", "audio": "", "image": "", "word": "", "text": "pie", "isRight": "0" }, { "type": "text", "audio": "", "image": "", "word": "", "text": "test", "isRight": "1" }] }, { "audio": "http://staging-teach.cdn.ireadabc.com/c14938125a52096dc0be9fbbf6638cb2_l.mp3", "time": null, "duration": "", "audioName": "进入下一题.mp3", "options": [{ "type": "img", "audio": "", "image": "http://staging-teach.cdn.ireadabc.com/07c89b4a6a1a18b0c0a3029720fdfdbc.png", "word": "", "isRight": "0" }, { "type": "img", "audio": "", "image": "http://staging-teach.cdn.ireadabc.com/d20b34eac11f5687d3386389aea170a2.png", "word": "", "isRight": "0" }, { "type": "img", "audio": "", "image": "http://staging-teach.cdn.ireadabc.com/639ada88f3e52966103caca156f720d6.png", "word": "", "isRight": "1" }, { "type": "img", "audio": "", "image": "http://staging-teach.cdn.ireadabc.com/38408b9ce048508830086c5e5cd2f384.png", "word": "", "isRight": "1" }] }, { "audio": "", "time": null, "duration": "", "audioName": "", "options": [{ "type": "img_text", "audio": "", "image": "http://staging-teach.cdn.ireadabc.com/3f36264d6aaa65e578a6d7e261ea8a2e.png", "isRight": "1", "text": "fish" }, { "type": "img_text", "audio": "", "image": "http://staging-teach.cdn.ireadabc.com/713e3312f1ed1876baf169026654d0c2.png", "isRight": "0", "text": "gray" }, { "type": "img_text", "audio": "", "image": "http://staging-teach.cdn.ireadabc.com/23290ec65a6700c931105c52aaf4e24c.jpg", "isRight": "0", "text": "international" }, { "type": "img_text", "audio": "", "image": "http://staging-teach.cdn.ireadabc.com/912b16d5a85e46fa5b0e2b75fb9d6bdf.png", "isRight": "0", "text": "break" }] }] }
\ No newline at end of file
......@@ -114,7 +114,7 @@
选项类型:
</div>
<div style="margin-top: 5px;">
<nz-radio-group [(ngModel)]="option.type">
<nz-radio-group [(ngModel)]="option.type" (ngModelChange)="save()">
<label nz-radio nzValue="img">
<span [style]="{color:option.type=='img' ? '#169BD5':'#000'}">图片</span>
</label>
......@@ -128,6 +128,23 @@
</div>
</div>
<div style="margin-top: 20px;">
<div class="word-type-option-title">
是否正确:
</div>
<div style="margin-top: 5px;">
<nz-radio-group [(ngModel)]="option.isRight" (ngModelChange)="save()">
<label nz-radio nzValue="1">
<span [style]="{color:option.isRight=='1' ? '#169BD5':'#000'}">正确</span>
</label>
<label nz-radio nzValue="0">
<span [style]="{color:option.isRight=='0' ? '#169BD5':'#000'}">错误</span>
</label>
</nz-radio-group>
</div>
</div>
<div style="margin-top: 25px;">
<div class="option-img">
<div *ngIf="option.type=='img' || option.type =='img_text'" style="width: 200px;">
......
......@@ -69,6 +69,7 @@ export class FormComponent extends ComponentBase implements OnInit, OnChanges, O
type: 'img',
audio: '',
image: '',
isRight: "0",
});
this.save();
}
......
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