package Game;

import DreamBubbleMidlet;

import java.util.Enumeration;
import java.util.Vector;

public class SingleGame extends Game {

	protected Vector enemies;
	protected int heroType = Global.JACK;
	protected int grade = Global.SIMPLE;

	public SingleGame(DreamBubbleMidlet dreamBubbleMidlet,int heroType,int grade) {
		super(dreamBubbleMidlet);
		this.heroType = heroType;
		this.grade = grade;
	}

	public void loadPlayer() {		
		this.player = SingleGameRole.createSingleGameRole(this, this.heroType,
				this.bornPlace[0][0], this.bornPlace[0][1]);
		this.gameLayerManager.append(player);
		
		this.enemies = new Vector();

		int npcNumber = 1;
		switch(this.grade){
		case Global.SIMPLE:
			npcNumber = 1;
			break;
		case Global.NORMAL:
			npcNumber = 2;
			break;
		case Global.HARD:
			npcNumber = 3;
			break;
		}
		for (int i = 1; i <= npcNumber; i++) {
			NPC npc = NPC.createNPC(this, this.bornPlace[i][0],
					this.bornPlace[i][1]);
			this.enemies.addElement(npc);
			this.gameLayerManager.append(npc);
		}
	}

	public void playerUpdate() {
		this.player.updateRole();
		if (this.player.deadTime == 21) {
			this.preStage();
			return;
		}
		this.enemyUpdate();
	}

	public void enemyUpdate() {
		Enumeration enu = this.enemies.elements();
		while (enu.hasMoreElements())// ±éÀúÕ¨µ¯¼¯ºÏ
		{
			NPC npc = (NPC) enu.nextElement();
			npc.updateRole();

			if (npc.deadTime == 21) {
				npc.setVisible(false);
				this.enemies.removeElement(npc);
				System.out.println(npc.deadTime);
				npc = null;
				if (this.enemies.isEmpty()) {
					this.nextStage();
				}
			}
		}
	}

}
