001    package model.fish;
002    
003    import model.fish.display.ImageFishDisplay;
004    import model.ILambda;
005    import sysModel.fish.AFish;
006    import sysModel.env.IBlockedCommand;
007    import sysModel.env.IOpenCommand;
008    
009    import java.awt.*;
010    
011    /**
012     * A simple fish that swims back and forth.
013     *
014     * @author Mathias Ricken
015     */
016    public class SimpleFish extends AFish {
017        /**
018         * Constructor.
019         *
020         * @param fishColor color of the fish
021         */
022        public SimpleFish(Color fishColor) {
023            super(fishColor, new ImageFishDisplay("smallfish.gif", 3.0 * Math.PI / 2.0));
024        }
025    
026        /**
027         * Carry out movement behavior for the fish.
028         */
029        protected void move() {
030            // attempt to move forward
031            tryMoveFwd(new IBlockedCommand() {
032                public Object apply(Object param) {
033                    // cannot move
034                    // turn PI radians
035                    turnRight(Math.PI);
036                    return null;
037                }
038            }, new IOpenCommand() {
039                public Object apply(Object param) {
040                    // can move forward, do it
041                    ((ILambda)param).apply(null);
042                    return null;
043                }
044            });
045        }
046    }