class Horse {
	private static _instance: Horse;
	static get instance(): Horse {
		if (!this._instance) {
			this._instance = new Horse();
		}
		return this._instance;
	}

	private matchData: any[] = [];
	private matchHorse: UI_Horse[] = [];
	private contaniner: egret.DisplayObjectContainer;

	public constructor() {
		GameMgr.instance.addEventListener(Channel.RUN_MSG, this.onReceived, this);
	}

	private onReceived(ev: egret.Event): void {
		let {data} = ev;
	}

	public setHorseContainer(contaniner: egret.DisplayObjectContainer): void {
		this.contaniner = contaniner;

		this.initHorse();
	}

	/**
	* 初始化赛马
	*/
	private initHorse(): void {
		const len = GameMgr.instance.GameData.count;

		for (let i = 0; i < len; i++) {
			this.matchData.push(i);
		}

		this.matchData.forEach((item, index) => {
			let horse = new UI_Horse();

			horse.x = 400 - Math.floor(index / 8) * 30;

			horse.y = index % 8 * 70 + 35;

			this.matchHorse.push(horse);

			this.contaniner.addChild(horse);

			horse.play(HorseState.run);
		})
	}

	public startRain(): void {
		this.matchHorse.forEach(horse => horse.startRain());
	}

	public stopRain(): void {
		this.matchHorse.forEach(horse => horse.stopRain());
	}

	public startSnow(): void {
		this.matchHorse.forEach(horse => horse.startSnow());
	}

	public stopSnow(): void {
		this.matchHorse.forEach(horse => horse.stopSnow());
	}

	public startWind(): void {

	}

	public stopWind(): void {

	}
}