export class Item {
    public page;

    public pic_url;
    public audio_url;
    public text;
    public recordAudio;
    public recordScore;
    constructor(data, page) {
        this.pic_url = data.pic_url;
        this.audio_url = data.audio_url;
        this.text = data.text;
        this.recordAudio = data.recordAudio;
        this.recordScore = data.recordScore;
        this.page = page;
    }
}
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;
    public lists: Array<Item>
    constructor() {
        //
        this.start = false;
        this.lists = [];
    }
    get len() {
        return this.lists.length;
    }
    public init(data) {
        this.start = false;
        this.lists = [];
        this.data = data.pages;
    }
    public start: boolean;
    public page: number;
    reset() {
        this.page = 1;
        this.start = true;
        this.lists = [];
        for (let i = 0; i < this.data.length; i++) {
            let data = this.data[i];
            this.lists.push(new Item(data, i));
        }
    }
    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]
    }
    getTotalPageNum() {
        return this.lists.length;
    }
    getCurrentPageNum() {
        return this.page;
    }
    addPage() {
        if (this.page >= this.lists.length) {
            return false;
        } else {
            this.page += 1;
            return true
        }
    }
    subPage() {
        if (this.page <= 1) {
            return false;
        } else {
            this.page -= 1;
            return true
        }
    }
    get isOver() {
        return this.page > this.lists.length;
    }
}

let win: any = window;
win.Game = Game;