package bwyap.familyfeud.render.state;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;

import bwyap.familyfeud.game.Family;
import bwyap.familyfeud.game.FamilyFeudGame;
import bwyap.familyfeud.render.RenderableInterface;
import bwyap.familyfeud.render.RenderingPanel;
import bwyap.familyfeud.render.component.Fader;
import bwyap.familyfeud.render.component.RenderableImage;
import bwyap.familyfeud.render.component.RenderableString;
import bwyap.gridgame.res.ResourceLoader;

/**
 * Renders the new game state:
 * each family's name will be rendered on the screen as they are added to the game.
 * @author bwyap
 *
 */
public class RenderStateNewGame implements RenderableInterface {
	
	private FamilyFeudGame game;
	
	private Fader bg;
	private RenderableString newgame;
	private List<RenderableString> families;
	
	/**
	 * Create a new game render state
	 * @param game
	 */
	public RenderStateNewGame(FamilyFeudGame game) {
		this.game = game;
		bg = new Fader(500, 
				new RenderableImage(ResourceLoader.getImage("blur")), 
				new RenderableImage(ResourceLoader.getImage("title")), false);
		
		newgame = new RenderableString("NEW GAME", 150, ResourceLoader.getFontName("Bebas Neue"), 100);
		newgame.setColor(Color.WHITE);
		
		families = new ArrayList<RenderableString>();
	}
	
	@Override
	public void update(float timeElapsed) {
		bg.update(timeElapsed);
		
		families.clear();
		final int INTERVAL = 80;
		int count = 0;
		for(Family f : game.getFamilies()) {
			RenderableString s = new RenderableString(f.getName(), 250 + INTERVAL * count++, ResourceLoader.getFontName("Bebas Neue"), 70);
			s.setColor(new Color(0x333333));
			families.add(s);
		}
	}
	
	@Override
	public void render(RenderingPanel panel, Graphics g) {
		bg.render(panel, g);
		
		// Draw 'NEW GAME'
		newgame.render(panel, g);
		
		// Draw families
		for(RenderableString s : families) {
			s.render(panel, g);
		}
	}

}

@@ -110,16 +110,66 @@
 ayList;%0A
+import java.util.ConcurrentModificationException;%0A
 import j
@@ -1530,16 +1530,28 @@
  = 0;%0A%09%09
+%0A%09%09try %7B%0A%09%09%09
 for(Fami
@@ -1579,16 +1579,17 @@
 es()) %7B%0A
+%09
 %09%09%09Rende
@@ -1714,16 +1714,17 @@
 70);%0A%09%09%09
+%09
 s.setCol
@@ -1751,16 +1751,17 @@
 3));%0A%09%09%09
+%09
 families
@@ -1769,16 +1769,119 @@
 add(s);%0A
+%09%09%09%7D%0A%09%09%7D%0A%09%09catch (ConcurrentModificationException e) %7B%0A%09%09%09System.err.println(e.getLocalizedMessage());%0A
 %09%09%7D%0A%09%7D%0A%09

Add try-catch for concurrent modification of families