InternalState.java
package prey;
 
public class InternalState extends Thread {
    private static int hunger = 0;
    private static int hungerCounter = 0;
    private int maxHungerCount = 30;
 
    public InternalState(){
        this.setDaemon(true);
        this.start();
    }
 
    public void run() {
        while(true) {
            // To avoid the hunger being increased to fast, the hungercounter is used.
            // When the hungercounter is equal to the maxHungerCount the hunger is incremented.
            hungerCounter++;
            if (hungerCounter == maxHungerCount) {
                incrementHunger();
            }
 
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {}
        }
    }
 
    public static int getHunger() {
        return hunger;
    }
 
    public static void decrementHunger() {
        hunger = Math.max(0, hunger - 1);
    }
 
    private static void incrementHunger() {
        hunger = Math.min(100, hunger+1);
        hungerCounter = 0;
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License