import greenfoot.*;

/**
 * Produces random collectibles. TODO: setting of probabilities (see Jannis's Moleskine for ideas).
 * 
 * @author Martin Schend, Jannis Andrija Schnitzer
 * @version 2011-01-21
 */
public class CollectibleFactory  
{
    public static final int N_COLLECTIBLE_CLASSES = 7;
    
    public static final int C_HEALTH = 0;
    public static final int C_MOREGUNS = 1;
    public static final int C_FASTERGUNS = 2;
    public static final int C_STRONGERGUNS = 3;
    public static final int C_ANGLEDGUNS = 4;
    public static final int C_STRAIGHTGUNS = 5;
    public static final int C_SICKNESS = 6;
    
    public static final double BASE_SPEED = .4;
    
    protected int side;
    
    public CollectibleFactory(int the_side)
    {
        side = the_side;
    }
    
    /**
     * Spits out a random collectible which has a speed based on the "side" variable.
     */
    public Collectible collectible() {
        int number = Greenfoot.getRandomNumber(N_COLLECTIBLE_CLASSES);
        Collectible result_collectible;
        
        // TODO: dynamize this.
        switch (number) {
            case C_HEALTH:
                result_collectible = new Health();
                break;
            case C_MOREGUNS:
                result_collectible = new MoreGuns();
                break;
            case C_FASTERGUNS:
                result_collectible = new FasterGuns();
                break;
            case C_STRONGERGUNS:
                result_collectible = new StrongerGuns();
                break;
            case C_ANGLEDGUNS:
                result_collectible = new AngledGuns();
                break;
            case C_STRAIGHTGUNS:
                result_collectible = new StraightGuns();
                break;
            case C_SICKNESS:
                result_collectible = new Sickness();
                break;
            default:
                return null;
        }
        
        double factor = 0.0;
        if (side == InvadersWorld.WHITE)
            factor = -1.0;
        else if (side == InvadersWorld.BLACK)
            factor = 1.0;
        
        result_collectible.setSpeed(new Vector(0.0, factor * BASE_SPEED));
        return result_collectible;
    }
}
