
export enum FISH_OUT {
    RUNNING,
    TOUCH,
    CATCH,
    ESCAP,
    OUT
}
export class Fish {
    public isOut: number;
    public node: cc.Node;
    public isLeft: boolean;//在左侧 向右运动
    constructor() {
        this.isOut = 0;
        this.isLeft = Math.random() < 0.5;
    }
}
export class Option {
    public type;
    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 page;
    public fish: any;
    public contentArr;
    public endAudio;
    constructor(data, page) {
        this.type = data.type;
        // this.count = 0;
        this.txt = data.contentMain;
        // this.time = data.duration;
        this.picUrl = data.image;
        this.audioUrl = data.audio;
        this.endAudio = data.endAudio;
        this.right = data.right;
        // this.touchRight = false;
        this.fish = new Fish();
        this.page = page;
        this.contentArr = data.contentMain.split("");
    }
}
export class Item {
    public page;
    public audio;
    public endAudio;
    public text;
    public optionList;
    public group_arr;
    public type;
    constructor(data, page) {
        this.audio = data.question_audio_url;
        this.endAudio = data.question_audio_url_end;
        this.text = data.text;
        this.type = data.type;
        let id = 0;
        this.optionList = [];
        this.optionList = data.options.map((o, idx) => {
            return new Option(o, idx);
        });

        this.optionList.sort(function () {
            return (0.5 - Math.random());
        });
        this.group_arr = data.group_arr;
        this.page = page;
    }
}
class Role {
    public score: number;
    public right: number;
    public error: number;
    public voices: Array<any>;
    constructor() {
        this.score = 0;
        this.error = 0;
        this.right = 0;
        this.voices = [];
    }
    addScore(score: number = 1) {
        this.score += score;
    }
    addError(score: number = 1) {
        this.error += score;
    }
    addRight() {
        this.right += 1;
    }
    addVoice(obj: any) {
        this.voices.push(obj);
    }
}
export class Player extends Role {
    constructor() {
        super();
    }
    reset() {
        this.score = 0;
        this.error = 0;
        this.right = 0;
        this.voices = [];
    }
}
export class Robot extends Role {
    constructor() {
        super();
    }
    reset() {
        this.score = 0;
        this.error = 0;
        this.right = 0;
        this.voices = [];
    }
}
export enum GAME_STATE {
    WAIT,
    RUNNING,
    OVER
}
export default class Game {
    private static ins: Game;
    public static getIns(): Game {
        if (!Game.ins) Game.ins = new Game();
        return Game.ins;
    }
    private data: any;
    private lists: Array<Option>
    public player: Player;
    public robot: Robot;
    public state: GAME_STATE;
    public total: number;

    constructor() {
        this.start = false;
        this.lists = [];
        this.player = new Player();
        this.robot = new Robot();
        this.state = GAME_STATE.WAIT;
    }
    get len() {
        return this.lists.length;
    }
    public question: { text, audio };
    public title: string;
    public beginAudio: string;
    public endAudio: string;
    public loadingAudio: string;
    public waitAudio: string;
    public finishAudioList;
    public init(data) {
        this.title = data.title;
        this.start = false;
        this.beginAudio = data.guideBegin_audio_url || "";
        this.endAudio = data.endAudio || "";
        this.loadingAudio = data.startLoadingAudio || "";
        this.waitAudio = data.waitAudio || "";
        this.finishAudioList = data.finishAudioList || [];
        this.lists = [];
        this.data = data.questions;
    }
    public start: boolean;
    public page: number;
    reset() {
        this.player.reset();
        this.robot.reset();
        this.page = 1;
        this.start = true;
        this.lists = [];
        this.data.sort(function () {
            return (0.5 - Math.random());
        });
        for (let i = 0; i < this.data.length; i++) {
            let data = this.data[i];
            this.lists.push(new Option(data, i + 1));
        }
        this.state = GAME_STATE.WAIT;
        this.total = this.lists.length;
    }
    // public getCardInfo() {
    //     let option: Item = 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(): Option {
        let page = this.page;
        return this.lists.filter(li => li.page == page)[0]
    }
    getTotalPageNum() {
        return this.lists.length;
    }
    getCurrentPageNum() {
        return this.page;
    }
    addPage() {
        this.page += 1;
    }
    get getTotla() {
        return this.lists.length;
        // this.total = 0;
        // this.lists.forEach((item) => {
        //     this.total += item.rNum;
        // })
        // return this.total;
    }
    get isOver() {
        return this.page > this.lists.length;
    }
}