/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package blok.shell;

import blok.interfaces.ICore;
import blok.interfaces.IGameController;
import blok.interfaces.IPlugin;
import blok.interfaces.ISimulator;
import java.awt.Point;
import java.util.ArrayList;
import org.jbox2d.dynamics.Body;

/**
 *
 * @author aluno
 */
public class GameController implements IGameController {

    GameController() {}
    
    @Override
    public boolean initialize() {
        ArrayList<IPlugin> simulators = ICore.getInstance().getPluginController().getLoadedPluginsByType(ISimulator.class);
        if (simulators.isEmpty()) {
            System.out.println("Nenhum plugin de simulador instalado!");
            System.exit(-1);
        }
        m_simulator = (ISimulator) simulators.get(0);
        m_gameState = GameState.INITIAL;

        m_simulator.init();

        return true;
    }
    
    @Override
    public void setGameState(GameState gameState) {
        m_gameState = gameState;
        switch(m_gameState) {
            case INITIAL:
                m_simulator.init();
                m_simulator.stop();
                break;
            case RUNNING:
                m_simulator.start();
                break;
        }
        ICore.getInstance().getUIController().repaint();
    }

    @Override
    public GameState getGameState() {
        return m_gameState;
    }

    @Override
    public void removeBody(Point bodyPoint) {
        m_simulator.removeBody(bodyPoint);
    }

    private ISimulator m_simulator;
    private GameState m_gameState;
}
