import javax.swing.*;

@SuppressWarnings("serial")
public class GUI extends JFrame implements UserInterface {

    /** constant defining the (default) size of each cell of the board */
    public static final int UNIT = 100;

    /** main panel, now in separate class */
    private GUIPanel content;

    @Override
    public void startGame(Game game) {
        game.setUserInterface(this);
        this.setTitle(game.getTitle());
        int xSize = game.getHorizontalSize();
        int ySize = game.getVerticalSize();
        this.setSize(xSize*UNIT, ySize*UNIT);
        this.content = new GUIPanel(game);
        this.content.addMouseListeners();
        this.setContentPane(this.content);
        this.setLocation(100,100);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    @Override
    public void showResult(String message) {
        JOptionPane.showMessageDialog(this, message+"\n\nThanks for playing.");
        System.exit(0);
    }

    @Override
    public int getParameter(String message, int min, int max) {
        Object[] options = new Object[max-min+1];
        for (int i = min; i <= max; i++) {
            options[i-min] = i;
        }
        return (Integer) JOptionPane.showInputDialog(null, "Select "+message, "Input", JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
    }

}
