/******************************* FILE HEADER **********************************
    File:        FoodCenter.java
    Main Class:  Aquarium.java
    
    Author:      James D. Skrentny
                 copyright 2000, all rights reserved
    Course:      CS302: Lectures 1 & 2
    
    Compiler:    CodeWarrior IDE 4.0 (JDK 1.2)
    Platform:    Windows NT 4.0
 **************************** 80 columns wide *********************************/

import java.awt.Color;

/** 
 * Represents a FoodCenter.
 * 
 * Bugs: Known bugs
 **/ 
 
class FoodCenter {           
           
    private int    foodPoints; // food available, 0 to Tank.MAX_FOOD_POINTS
    private Location location; // food center's Location in the tank


    /** 
     * Constructs a new FoodCenter at a random Location.
     **/
    public FoodCenter ( ) {           
        int Points;
	Points = Tank.FOOD_CENTER_POINTS;
       location = new Location((int)(Math.random()*Tank.TANK_WIDTH   + 1), 
                                  (int)(Math.random()*Tank.WATER_HEIGHT + 1));    
}           


    /**
     * Returns the Location of this FoodCenter.
     *
     * @return this food center's Location
     **/
    public Location getLocation () {           
        return location;
    }           


    /**
     * Get the Color of this FoodCenter.
     * Red if empty, Yellow if < 50% full, Green if > 50% full
     *
     * @return this food center's Color
     **/
    public Color getColor () {           
        if ((foodPoints <= Tank.FOOD_CENTER_POINTS/2) && (foodPoints > 0)) {
            return Color.yellow;
        }
        else if (foodPoints == 0) {
            return Color.red;
        }
        else {
            return Color.green;
        }
    }


    /**
     * Get the number of food points of this FoodCenter.
     *
     * @return this food center's food points
     **/
    public int getFoodPoints () {           
        return foodPoints;
    }           


    /**
     * Provides food to a Fish. If the this FoodCenter's food is less than
     * the amount wanted, the food center only gives its remaining amount. 
     * Otherwise it gives the wanted amount of food.
     *
     * @param amount the amount of food wanted
     * @return the amount of food given
     **/
    public int foodWanted (int amountWanted) {
        int amountGiven = amountWanted;
        
        // check if not enough to food
        if (amountWanted > foodPoints) {
            amountGiven = foodPoints;
        }
        
        foodPoints -= amountGiven;

        return amountGiven;
    }
    
    /**
     * Get the information about this FoodCenter.
     *
     * @return a String representation of this food center
     **/
    public String toString () {           
        String info = "FoodCenter ";
        info += "  Color: ";
        if ((foodPoints <= Tank.FOOD_CENTER_POINTS/2) && foodPoints > 0) {
            info += "yellow";
        }
        else if (foodPoints == 0) {
                info += "red";
        }
        else {
                info += "green";
        }
        info += "  Location: "    + location;
        info += "  Food points: " + foodPoints;

        return info;
    }           
           
}           
