⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 behavior.java

📁 SIMULATION FOURMILIERE -3D-ISOMETRIQUE
💻 JAVA
字号:
package fr.umlv.fourmIR2000.insect.behaviors;

import fr.umlv.fourmIR2000.insect.Insect;
import fr.umlv.fourmIR2000.pictures.Values;
import fr.umlv.fourmIR2000.world.WorldPoint;


/**
 * Comportments of the insects
 */
public abstract class Behavior {
    
    /**
     * Do the appropriated action for the insect
     * @param insect    the insect we work with
     * @return true if an action has been executed, else false
     */
    public boolean doAction(final Insect insect) {
        // If we are fighting, we continue
        if (insect.isFighting()) {
            insect.fight(insect.getOpponent());
            insect.askForHelpToFight();
            return true;
        }
        
        // If we are on a food point, we pickup some
        final WorldPoint curPos = insect.getPos();
        if (insect.getTeam().getWorld().getElement(curPos.getX(), curPos.getY()) == Values.food)
            insect.eat();
        
        // Then, we do future actions only if it is time to walk
        int delay = insect.getTimeBeforeActing();
        insect.setTimeBeforeActing(--delay);
        if (delay > 0)
            return true;
        insect.setTimeBeforeActing(insect.getSpeed());

        return false;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -