All pastes #2049184 Raw Edit

Someone

public java v1 · immutable
#2049184 ·published 2011-04-22 01:16 UTC
rendered paste body
/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author shs.student */import java.util.Iterator;import java.util.Scanner;import java.util.Vector;import javax.swing.JOptionPane;import Item.ItemEffect;public class Item {		public abstract class ItemEffect	{		public int value;		protected int duration=1;		protected boolean used=false;				public abstract void applyTo(Object other);				protected void use()		{			duration--;			if(duration <= 0)				used=true;		}	}		public class HealthModifier extends ItemEffect	{		@Override		public void applyTo(Object other) {			other.health += value;			use();		}			}		public enum StatusEffects	{		EFFECT_POISON,		EFFECT_PARALYSIS	}		public class StatusModifier extends ItemEffect	{		public StatusEffects ModifiedEffect;		public boolean Cures = false;				@Override		public void applyTo(Object other) {			if(Cures)				other.RemoveStatus(ModifiedEffect);			else				other.AddStatus(ModifiedEffect);			use();		}			}		public class InventoryItem	{		protected Vector<ItemEffect> Effects = new Vector<ItemEffect>();				public InventoryItem()		{						HealthModifier hm = new HealthModifier();			hm.value = 50;			Effects.add(hm);						StatusModifier sm = new StatusModifier();			sm.ModifiedEffect = StatusEffects.EFFECT_PARALYSIS;			sm.Cures = true;						Effects.add(hm);		}				public void UseItem(Object other)		{						Iterator<ItemEffect> itr = Effects.iterator();			while(itr.hasNext())				((ItemEffect) itr).applyTo(other);						}	}}