export class Item {
    public id: number;
    public type: string;
    public text: string;
    public pic: string;
    public right: boolean;
    constructor(data: any, isRight: boolean) {
        this.id = data.id;
        this.type = data.type;
        this.text = data.text;
        this.pic = data.pic;
        this.right = isRight;
    }
}
export class Part {
    public id: number;
    public stemAudio: string;
    public list: Array<Item>;
    constructor(data) {
        this.id = data.id;
        this.stemAudio = data.stem.audio;
        this.list = [];
        data.right.forEach(r => {
            this.list.push(new Item(r, true));
        })
        data.error.forEach(r => {
            this.list.push(new Item(r, false));
        })
        //随机打乱
        let arr = [];
        while (this.list.length > 0) {
            let id = Math.floor(this.list.length * Math.random());
            arr.push(this.list[id])
            this.list.splice(id, 1)
        }
        this.list = arr;
    }
    public getIdByX(x): number {
        let arrows = [];
        if (this.list.length == 2) {
            arrows = [0, 100]
        } else if (this.list.length == 3) {
            arrows = [0, 100, 200]
        } else if (this.list.length == 4) {
            arrows = [0, 100, 200, 300]
        }
        for (let i = 0; i < arrows.length; i++) {
            if (x <= arrows[i]) {
                return arrows[i];
            }
        }
    }
    getArrowXByX(x): number {
        let id = this.getIdByX(x);
        let arrows = [];
        if (this.list.length == 2) {
            arrows = [0, 100]
        } else if (this.list.length == 3) {
            arrows = [0, 100, 200]
        } else if (this.list.length == 4) {
            arrows = [0, 100, 200, 300]
        }
        return arrows[id];
    }
    getItemByX(x): Item {
        let id = this.getIdByX(x);
        return this.list[id];
    }
}
export class Game {
    private static instance: Game;
    public static getIns() {
        if (!Game.instance) Game.instance = new Game();
        return Game.instance;
    }
    private _list: Array<any>;
    public current: number;
    constructor() {
        this._list = [];
        this.current = 0;
    }
    public init(data) {
        this.list = data.list;
    }
    public get part(): Part {
        return this.list[this.current];
    }
    public set list(val) {
        this._list = val.map(li => {
            return new Part(li);
            // return li;
        })
    }
    public get list() {
        return this._list;
    }
}
