001    package model.fish;
002    
003    import model.fish.display.CircleFishDisplay;
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 fish that swims around in a circle.
013     *
014     * @author Mathias Ricken
015     */
016    public class CircleFish extends AFish {
017        /**
018         * Create a new circle fish.
019         *
020         * @param fishColor color of the fish
021         */
022        public CircleFish(Color fishColor) {
023            super(fishColor, CircleFishDisplay.Singleton);
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                    // the field ahead is blocked, turn around
034                    turnRight(Math.PI);
035                    return null;
036                }
037            },
038                new IOpenCommand() {
039                    public Object apply(Object param) {
040                        // the field ahead is open, move
041                        ((ILambda)param).apply(null);
042                        // turn 10 degrees to the right
043                        turnRight(Math.PI / 18);
044                        return null;
045                    }
046                });
047    
048        }
049    }