import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.event.*;
import javax.swing.*;

/**
 * Game Core for Applet and Application
 * <P>
 * 
 * @author Owen Astrachan
 */
public class GameCore extends JPanel implements IGameView
{
    protected GameModel myModel;
    protected GamePanel myGamePanel;
    protected JLabel myMessageLabel;
    protected JLabel myScoreLabel;
    /**
     * Create a view with a model
     * @param model is the model for this view
     */
    
    public GameCore(GameModel model, GamePanel panel)
    {
	setLayout(new BorderLayout());

        myModel = model;
	myGamePanel = panel;
        myMessageLabel = new JLabel("   ");
	myScoreLabel = new JLabel("",SwingConstants.RIGHT);
	setScore(0);
	add(myScoreLabel,  BorderLayout.NORTH);
	add(myGamePanel, BorderLayout.CENTER);
        add(myMessageLabel,BorderLayout.SOUTH);
	
        myModel.addView(this); // draws board
    }

    public void newGame()
    {
	myModel.initialize();
    }

    public void setScore(int score)
    {
	myScoreLabel.setText(score+" Score");
    }

    /**
     * Required by interface, show the grid that's the model
     * @param list represents the model
     */
    public void showGrid(GridPoint[][] list)
    {
	myGamePanel.setGrid(list);	
    }

    public void highlight(GridPoint[] list, boolean show)
    {
        myGamePanel.highlight(list,show);
    }

    public void showMessage(String s)
    {
        myMessageLabel.setText(s);
    }

    public void gameOver()
    {
	JOptionPane.showMessageDialog(this,"game over!");
    }
}
