package view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.Timer;

import main.Window;
import model.GameModel;
import model.GameStateManager;

@SuppressWarnings("serial")
public class GameView extends JPanel implements ActionListener {

	private GameModel model;
	private GameStateManager gsm;
	private Timer t;

	public GameView(GameModel model, GameStateManager gsm) {
		this.model = model;
		this.gsm = gsm;

		setBackground(Color.WHITE);

		// Start paint timer
		t = new Timer(1000 / Window.FRAMES_PER_SECOND, this);
		t.start();
	}

	// Paint the game
	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		Graphics2D g2d = (Graphics2D) g;
		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2d.setRenderingHints(rh);
		gsm.paint(g2d);
		Toolkit.getDefaultToolkit().sync();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		repaint();
	}
}
