Code example for Queue

Methods: add, isEmpty, peek

0
	private void quit() { 
		startActivity(new Intent(getApplicationContext(), MainActivity.class));
	} 
 
	private void updateHero() { 
		hiv.setImageResource(queue.peek().getDrawable());
		htv.setText(queue.peek().printOut());
	} 
	 
	private void doNothing() { 
		queue.add(queue.poll());
		updateHero(); 
	} 
 
	private void attack() { 
		Log.i("COMBAT", "in attack");
		e1.setClickable(true);
		e2.setClickable(true);
		e3.setClickable(true);
		e4.setClickable(true);
		Toast.makeText(getApplicationContext(), "Click the enemy you want to attack", Toast.LENGTH_SHORT).show();
	} 
	 
	public void eb1(View v) {
		enemy1.setHealth(enemy1.getHealth()-queue.poll().getAttack());
		e1.setClickable(false);
		e2.setClickable(false);
		e3.setClickable(false);
		e4.setClickable(false);
		if(queue.isEmpty()) {
			monsterAttack(); 
		} 
		etv1.setText(enemy1.getHealth()+"/"+enemy1.getMaxHealth());
		checkFight(); 
		updateHero(); 
	} 
	public void eb2(View v) {
		enemy2.setHealth(enemy2.getHealth()-queue.poll().getAttack());
		e1.setClickable(false);
		e2.setClickable(false);
		e3.setClickable(false);
		e4.setClickable(false);
		if(queue.isEmpty()) {
			monsterAttack(); 
		} 
		 
		etv2.setText(enemy2.getHealth()+"/"+enemy2.getMaxHealth());
		checkFight(); 
		updateHero(); 
	} 
	public void eb3(View v) {
		enemy3.setHealth(enemy3.getHealth()-queue.poll().getAttack());
		e1.setClickable(false);
		e2.setClickable(false);
		e3.setClickable(false);
		e4.setClickable(false);
		if(queue.isEmpty()) {
			monsterAttack(); 
		} 
		etv3.setText(enemy3.getHealth()+"/"+enemy3.getMaxHealth());
		checkFight(); 
		updateHero(); 
	} 
	public void eb4(View v) {
		enemy4.setHealth(enemy4.getHealth()-queue.poll().getAttack());
		e1.setClickable(false);
		e2.setClickable(false);
		e3.setClickable(false);
		e4.setClickable(false);
		if(queue.isEmpty()) {
			monsterAttack(); 
		} 
		etv4.setText(enemy4.getHealth()+"/"+enemy4.getMaxHealth());
		checkFight(); 
		updateHero(); 
	} 
	 
	private void monsterAttack() { 
		 
		if (enemy1.getHealth() > 0) {
			mQueue.add(enemy1);
		} 
		if (enemy2.getHealth() > 0) {
			mQueue.add(enemy2);
		} 
		if (enemy3.getHealth() > 0) {
			mQueue.add(enemy3);
		} 
		if (enemy4.getHealth() > 0) {
			mQueue.add(enemy4);
		} 
		while (!mQueue.isEmpty()) {
			Hero target = getTarget();
			target.setHealth(target.getHealth()-mQueue.peek().getAttack());
			Toast.makeText(getApplicationContext(), mQueue.peek().getName() + " attacks " + target.getName() + " for " + mQueue.poll().getAttack() + " damage.", Toast.LENGTH_SHORT).show();
		} 
		repopulateHeroes(); 
		 
	} 
 
	private void repopulateHeroes() { 
		if (hero1.getHealth() > 0) {
			queue.add(hero1);
		} 
		if (hero2.getHealth() > 0) {
			queue.add(hero2);
		} 
		if (hero3.getHealth() > 0) {
			queue.add(hero3);
		} 
		if (queue.isEmpty()) {
			setResult(0, intent);
			finish();
		} 
		updateHero(); 
	}