Skip to content
Snippets Groups Projects
Controller.java 1.88 KiB
Newer Older
  • Learn to ignore specific revisions
  • Kovax's avatar
    v2
    Kovax committed
    /*
     * 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;
    
    
    Kovax's avatar
    v2
    Kovax committed
    
    /**
     *
     * @author Kovax
     */
    public class Controller
    {
    
    Kovax's avatar
    Kovax committed
        public View view;
    
    Kovax's avatar
    v2
    Kovax committed
        private Model model;
    
        public Settings settings;
    
    Kovax's avatar
    v2
    Kovax committed
        
    
    Kovax's avatar
    Kovax committed
        private Boolean isStopButtonPressed = false;
        
    
        public Controller(Settings settings)
    
    Kovax's avatar
    Kovax committed
        {
    
            this.settings = settings;
    
    Dániel's avatar
    Dániel committed
       }
    
    Kovax's avatar
    Kovax committed
        public void registerView(View view)
        {
            this.view = view;
        }
        public void registerModel(Model model)
    
    Kovax's avatar
    v2
    Kovax committed
        {
    
    Kovax's avatar
    Kovax committed
            this.model = model;
        }
        public int getButtonState()
        {
            if( isStopButtonPressed )
                return 1;
            return -1;
    
    Kovax's avatar
    v2
    Kovax committed
            
    
    Kovax's avatar
    Kovax committed
        }
        public void resetButtonState()
        {
            this.isStopButtonPressed = false;
    
    Kovax's avatar
    v2
    Kovax committed
        }
    
        
        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;
        }
        
    
    Dániel's avatar
    Dániel committed
        public void gameLeftButtonPressed(String button)
    
        {
            int[]pos = this.getButtonPos(button);
    
    Dániel's avatar
    Dániel committed
            model.calculateButtonStyle(pos);  
    
    Dániel's avatar
    Dániel committed
        public void gameRightButtonPressed(String button)
        {
            int[] pos = this.getButtonPos(button);
            model.flagButton(pos);
        }
        public void gameStart()
        {
            if( this.model != null && this.view != null )
            {
                StopWatch watch = new StopWatch(this);
                watch.start();
            }
        }
        public void timeLeft()
        {
            view.timeLeft();
        }
    
    Dániel's avatar
    Dániel committed
        public void reDraw()
        {
            this.view.draw();
    
    Kovax's avatar
    v2
    Kovax committed
    
        
        
        
    }