@@ -0,0 +1,2627 @@
+package main.java.engine;%0A%0Aimport java.awt.geom.Point2D;%0Aimport java.util.List;%0Aimport main.java.engine.objects.monster.Monster;%0A%0A%0A/**%0A * %0A * Use EnvironmentKnowledge to abstract the passing of limited information into Tower and/or Monster%0A * behavior method calls.%0A * %0A * Goal is to give access to information about the environment of objects,%0A * and change their state with controlled methods,%0A * but not the ability nor access to directly modify the environmental objects themselves.%0A * %0A * Contains helper methods to return info which relies on knowledge unknown to individual objects%0A * (typically aggregate info about the entire field of towers and monsters)%0A * and methods to change state of environmental objects in a controlled manner.%0A * %0A * @author Austin%0A * %0A */%0Apublic class EnvironmentKnowledge %7B%0A%0A    List%3CMonster%3E allMonsters;%0A    Player currentPlayer;%0A%0A    /**%0A     * Add necessary state info.%0A     * %0A     * @param allMonsters%0A     */%0A    public EnvironmentKnowledge (List%3CMonster%3E allMonsters, Player currentPlayer) %7B%0A%0A        // add more parameters as necessary%0A%0A        this.allMonsters = allMonsters;%0A        this.currentPlayer = currentPlayer;%0A%0A    %7D%0A%0A    /**%0A     * Returns the coordinate of the monster nearest to the coordinate passed in%0A     * %0A     * @param x tower x-coor%0A     * @param y tower y-coor%0A     * @return coordinates of the nearest monster in the form of a Point2D object%0A     */%0A    public Point2D getNearestMonsterCoordinate (double x, double y) %7B%0A%0A        double minDistance = Double.MAX_VALUE;%0A        Point2D closestMonsterCoor = null;%0A        Point2D towerCoor = new Point2D.Double(x, y);%0A%0A        for (Monster m : allMonsters) %7B%0A            if (m.getCurrentCoor().distance(towerCoor) %3C minDistance) %7B%0A                minDistance = m.getCurrentCoor().distance(towerCoor);%0A                closestMonsterCoor = centerCoordinate(m);%0A            %7D%0A        %7D%0A%0A        return closestMonsterCoor;%0A    %7D%0A%0A    /**%0A     * Returns the center of the object for targeting%0A     * %0A     * @param m object coordinate%0A     * @return the center of the objects image according to the imageBBox%0A     */%0A    private Point2D centerCoordinate (Monster m) %7B%0A        return new Point2D.Double(m.getCurrentCoor().getX() + m.getImageBBoxConst().width / 2,%0A                                  m.getCurrentCoor().getY() + m.getImageBBoxConst().height / 2);%0A    %7D%0A%0A    /**%0A     * Give the current player a specified amount of money.%0A     * %0A     * @param grantedMoney money to be given to player%0A     */%0A    public void grantPlayerMoney (int grantedMoney) %7B%0A        currentPlayer.addMoney(grantedMoney);%0A    %7D%0A%0A%7D%0A

Add a EnvironmentKwowledge object for Model to delegate more easily