package life;

import java.awt.*;
import java.io.*;
import java.util.Map;

import javax.imageio.ImageIO;
import javax.swing.*;

import life.board.*;
import life.controller.*;
import life.generator.*;
import life.ruleset.*;

import com.google.common.collect.ImmutableMap;

public class Life extends JPanel {

	private static final int TILE_SIZE = 10;
	private static final int FPS = 10;

	private static final int FRAME_WIDTH = 1920;
	private static final int FRAME_HEIGHT = 1080;

	private final Controller controller;

	public Life(final Controller controller) {
		this.controller = controller;
	}

	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		controller.render(g);
	}

	public static void main(String[] args) throws IOException {
		JFrame frame = new JFrame("Life");

//		Good rules for a HexBoard
		Map<Integer, BlockState> rulesMap = ImmutableMap.of(
				2, BlockState.STAY,
				3, BlockState.LIVE,
				5, BlockState.LIVE,
				6, BlockState.LIVE
				);

//		Good rules for a Triangle4Board
//		Map<Integer, BlockState> rulesMap = ImmutableMap.of(
//				0, BlockState.STAY,
//				2, BlockState.LIVE,
//				3, BlockState.LIVE
//				);
		
//		Good rules for a SquareBoard
//		Map<Integer, BlockState> rulesMap = ImmutableMap.of(
//				2, BlockState.STAY,
//				3, BlockState.LIVE
//				);
		
		RuleSet rules = new StandardRules(rulesMap);
		
//		BoardGenerator gen = new RandomBoardGenerator(FRAME_HEIGHT/TILE_SIZE, FRAME_WIDTH/TILE_SIZE);
//		BoardGenerator gen = new StaticBoardGenerator();
		BoardGenerator gen = new FileBoardGenerator("Pulsar");
		
		BoardHandler boardHandler = new BoardHandler(rules, gen.getBoard());
		
//		Board board = new SquareBoard(boardHandler, TILE_SIZE);
//		Board board = new Triangle4Board(boardHandler, TILE_SIZE);
		
		Image full = ImageIO.read(new File("res/tileImages/FilledHex.png"));
		Image empty = ImageIO.read(new File("res/tileImages/EmptyHex.png"));
		Board board = new HexBoard(boardHandler, TILE_SIZE, full, empty, frame);
		
//		Controller controller = new AlwaysPlay(f, board, FPS);
		Controller controller = new PlayPauseController(frame, board, FPS);

		Life life = new Life(controller);
		
		life.addMouseListener(controller);
		life.addMouseWheelListener(controller);
		
		frame.add(life);

		setUpFrame(frame);
		controller.run();
	}

	private static void setUpFrame(JFrame f) {
		f.setUndecorated(true);
		f.setSize(FRAME_WIDTH, FRAME_HEIGHT);
		f.setVisible(true);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}

@@ -379,17 +379,16 @@
 S = 10;%0A
-%0A
 %09private
@@ -832,16 +832,18 @@
 exBoard%0A
+//
 %09%09Map%3CIn
@@ -889,16 +889,18 @@
 Map.of(%0A
+//
 %09%09%09%092, B
@@ -915,16 +915,18 @@
 e.STAY,%0A
+//
 %09%09%09%093, B
@@ -937,24 +937,26 @@
 State.LIVE,%0A
+//
 %09%09%09%095, Block
@@ -967,16 +967,18 @@
 e.LIVE,%0A
+//
 %09%09%09%096, B
@@ -992,16 +992,18 @@
 te.LIVE%0A
+//
 %09%09%09%09);%0A%0A
@@ -1213,26 +1213,24 @@
 SquareBoard%0A
-//
 %09%09Map%3CIntege
@@ -1264,34 +1264,32 @@
 mmutableMap.of(%0A
-//
 %09%09%09%092, BlockStat
@@ -1288,34 +1288,32 @@
 lockState.STAY,%0A
-//
 %09%09%09%093, BlockStat
@@ -1311,34 +1311,32 @@
 BlockState.LIVE%0A
-//
 %09%09%09%09);%0A%09%09%0A%09%09Rule
@@ -1375,26 +1375,24 @@
 lesMap);%0A%09%09%0A
-//
 %09%09BoardGener
@@ -1528,16 +1528,18 @@
 ator();%0A
+//
 %09%09BoardG
@@ -1664,18 +1664,16 @@
 ());%0A%09%09%0A
-//
 %09%09Board 
@@ -1788,16 +1788,18 @@
 ZE);%0A%09%09%0A
+//
 %09%09Image 
@@ -1861,16 +1861,18 @@
 png%22));%0A
+//
 %09%09Image 
@@ -1934,16 +1934,18 @@
 png%22));%0A
+//
 %09%09Board 

Set Default board in Life to SquareBoard