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 fish: Fish;
    constructor(data, id) {
        this.id = id;
        this.data = data;
        this.type = data.type;
        this.txt = data.text;
        this.picUrl = data.image;
        this.audioUrl = data.audio;
        this.right = data.right;
        this.fish = new Fish();
    }
}
export class Item {
    private static ID: number = 1000;
    public audio: string;
    public text: string;
    public optionList: Array<Option>;
    public rightList: Array<Option>;
    constructor(data) {
        this.rightList = []
        this.audio = data.audio;
        this.text = data.text;
        this.optionList = data.options.map(o => {
            return new Option(o, Item.ID++);
        })

        this.optionList.sort(function () {
            return (0.5 - Math.random());
        });
        for (let i = 0; i < this.optionList.length; i++) {
            this.optionList[i].count = i;
        }
    }
    isChild(data) {
        return this.optionList.find(option => option.id == data.id)
    }
    setRight(data) {
        this.rightList.push(data);
    }
    isAllRight() {
        return this.optionList.length == this.rightList.length;
    }
}
class Role {
    public score: number;
    public error: number;
    constructor() {
        this.score = 0;
        this.error = 0;
    }
    addScore(score: number = 1) {
        this.score += score;
    }
    addError(score: number = 1) {
        this.error += score;
    }
}
export class Player extends Role {
    constructor() {
        super();
    }
    reset() {
        this.score = 0;
        this.error = 0;
    }
}
export enum GAME_STATE {
    WAIT = 1,
    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<Item>
    public player: Player;
    public state: GAME_STATE;

    public title: string;
    public total: number;
    public aniEnter;
    public startAudio;
    constructor() {
        this.start = false;
        this.lists = [];
        this.player = new Player();
        this.state = GAME_STATE.WAIT;
    }
    get len() {
        return this.lists.length;
    }
    public init(data) {
        this.start = false;
        this.lists = [];
        this.data = data.questions;
        
        this.title = data.title;
        this.startAudio = data.startAudio || "";
        this.aniEnter = data.imgAni;
    }
    public start: boolean;
    public boatLeft: Item;
    public boatRight: Item;
    reset() {
        this.player.reset();
        this.start = true;
        this.lists = [];
        this.boatLeft = new Item(this.data[0]);
        this.boatRight = new Item(this.data[1]);
        this.state = GAME_STATE.WAIT;
    }
    getFishList() {
        return this.boatLeft.optionList.concat(this.boatRight.optionList)
    }
    checkSuccess(arr: Option[]) {
        return false;
        // 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;
    }
    addPage() {
    }
    get isOver() {
        return false;
    }
}