/*
 * 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 GUI.game;

import Program.Settings;


/**
 *
 * @author Kovax
 */
public class Controller
{
    public View view;
    public Model model;
    public Settings settings;
    public Game game;
    public StopWatch watch;
    
    private Boolean isStopButtonPressed;
    
    public Controller(Settings settings)
    {
        this.settings = settings;
        this.isStopButtonPressed = false;
   }
    public void stopButtonPressed()
    {
        this.isStopButtonPressed = true;
    }
    public void registerView(View view)
    {
        this.view = view;
    }
    public void registerModel(Model model)
    {
        this.model = model;
    }
    public void registerGame(Game game)
    {
        this.game = game;
    }
    public int getButtonState()
    {
        if( isStopButtonPressed )
            return 1;
        return -1;
        
    }
    public void resetButtonState()
    {
        this.isStopButtonPressed = false;
    }
    
    private int[] getButtonPos(String buttonName)
    {
        String[] splitted =  buttonName.split(":");
        int[] pos = new int[2];
        pos[0] = Integer.parseInt(splitted[0]);
        pos[1] = Integer.parseInt(splitted[1]);
        
        return pos;
    }
    
    public void gameLeftButtonPressed(String button)
    {
        int[]pos = this.getButtonPos(button);
        model.calculateButtonStyle(pos);  
        
        
    }
    public void gameRightButtonPressed(String button)
    {
        int[] pos = this.getButtonPos(button);
        model.flagButton(pos);
    }
    public void gameStart()
    {
        if( this.model != null && this.view != null )
        {
            watch = new StopWatch(this);
            watch.start();
            watch.startTimer();
        }
    }
    public void gameOver()
    {
        this.model.isGameOver = true;
        this.watch.stopTimer();
    }
    public void timeLeft()
    {
        view.timeLeft();
    }
    public void newGame()
    {
        this.game.newGame();
    }

    

    
    
    
}