package gameEngine.controller;

import gameEngine.model.Model;
import gameEngine.model.Tile;
import gameEngine.model.tower.Tower;
import gameEngine.model.tower.TowerInfo;
import gameEngine.view.View;
import java.awt.Dimension;
import java.io.File;
import java.util.List;


public class Controller {

    Model model;
    View view;


    Dimension gameSize;

    public Controller () {

        gameSize = new Dimension(20, 20);
        view = new View(this);
        model = new Model();
    }

    public void newGame (File jsonFile) throws Exception {
        model.newGame(jsonFile); // will throw exception if fail
        view.startGame();
        startGame();
        // Model parses jsonFile and passes gameData to view
        // view.initialize(gameData);
        // view.showGame();
    }

    public void startGame () {
        model.startGame();
    }

    /**
     * Get All kinds of TowerFactory
     * However, can only return the basic property of the TowerFactory
     */
    public List<TowerInfo> getTowerFactory () {
        return model.getAllTowerInfo();  
    }

    /**
     * Sends a call to the model to purchase tower tower at position x,y
     * If position is invalid, do nothing for now
     */
    public boolean purchaseTower (int x, int y, String name) {
        return model.purchaseTower(x, y, name);
    }

    /**
     * Sends a call to the model to update the monitored tower stats to the tower
     * at x,y. If the position is invalid, do nothing
     */
    public TowerInfo getTowerInfo (int x, int y) {
        TowerInfo towerinfo;
        try {
            towerinfo=model.getTowerInfo(x,y);
        } catch (Exception e) {
            towerinfo=null;
        }
        return towerinfo;
    }

    /**
     * Returns the size of the game in number of tiles
     */
    public Dimension getGameSize () {
        return model.getGameSize();
    }

    /**
     * Returns the URL to the game's background image
     */
    public String getBGImage () {
        return model.getBGImage();
    }

    /**
     * Returns the amount of money in the game
     */
    public int getMoney () {
        return model.getMoney();
    }

    /**
     * Return the number of lives remaining
     */
    public int getLives () {
        return model.getLife();
    }

    public List<Tile> getPath () {
        return model.getPathList();
    }

    // public String getPathImage(){
    // }


}

@@ -1328,32 +1328,1213 @@
 y, name);%0A    %7D%0A
+    %0A    /**%0A     * @author Yuhua%0A     * %0A     * Sell Tower at (x,y)%0A     * Succeed, return true, added gold%0A     * No such tower, return false%0A     * %0A     * @param x%0A     * @param y%0A     * @return%0A     */%0A    public boolean sellTower(int x, int y)%7B%0A        %0A        return false;%0A    %7D%0A    %0A    /**%0A     * @author Yuhua%0A     * %0A     * Upgrade Tower at (x, y)%0A     * Succeed, return true, decrease gold%0A     * No such tower/Insufficient fund, return false%0A     * %0A     * @param x%0A     * @param y%0A     * @return%0A     */%0A    public boolean upgradeTower(int x, int y)%7B%0A        %0A        return false;%0A    %7D%0A    %0A    /**%0A     * Set Tower Attack Mode at (x, y)%0A     * %0A     * AttackMode include %0A     * 0 - shoot the closest enemy%0A     * 1 - shoot the farthest enemy%0A     * 2 - shoot weakest enemy with least life%0A     * 3 - shoot strongest enemy with most life%0A     *%0A     * Return true when set tower attackMode succeed%0A     * Return false when no such tower/already at that attackMode%0A     * %0A     * @param x%0A     * @param y%0A     * @param attackMode%0A     * @return%0A     */%0A    public boolean setTowerAttackMode(int x, int y, int attackMode)%7B%0A        %0A        return false;%0A    %7D%0A    
 %0A    /**%0A     * 

add API in controller for tower