package com.lofibucket.yotris.logic;
import java.util.Observable;
import com.lofibucket.yotris.ui.UserInterface;
import com.lofibucket.yotris.util.Settings;

public class GameLogic extends Observable {
	private UserInterface ui;
	private Grid grid;
	private Settings settings;
	private Piece fallingPiece;
	private int score;
	
	public GameLogic(UserInterface ui, Settings settings)	 {
		this.ui = ui;
		this.settings = settings;
		this.reset(settings);

		addObserver(ui);
	}

	private void reset(Settings settings) {
		this.grid = new Grid(settings.getGridWidth(), settings.getGridHeight());	
		fallingPiece = null;
		score = 0;

		GameState state = getGameState();
		notifyObservers(state);
	}

	public GameState update() {
		GameState state = getGameState();
		notifyObservers(state);

		return state;
	}

	public GameState getGameState() {
		GameState state = new GameState(true);	
		state.running = false;

		Grid renderGrid = getRenderGrid();
		state.renderGrid = renderGrid;

		return state;
	}

	public Grid getRenderGrid() {
		Grid renderGrid = new Grid(this.grid.getWidth(), this.grid.getHeight());
		if (fallingPiece != null) {
			renderGrid.plotPiece(fallingPiece);
		}
		return renderGrid;
	}

}

@@ -34,37 +34,8 @@
 ic;%0A
-import java.util.Observable;%0A
 impo
@@ -77,16 +77,16 @@
 erface;%0A
+
 import c
@@ -120,16 +120,45 @@
 ettings;
+%0Aimport java.util.Observable;
 %0A%0Apublic
@@ -319,16 +319,41 @@
  score;%0A
+%09private int frames = 0;%0A
 %09%0A%09publi
@@ -648,16 +648,30 @@
 ore = 0;
+%0A%09%09frames = 0;
 %0A%0A%09%09Game
@@ -751,32 +751,47 @@
 tate update() %7B%0A
+%09%09frames++;%0A%09%09%0A
 %09%09GameState stat
@@ -1255,10 +1255,121 @@
 id;%0A%09%7D%0A%0A
+%09public int getSimulatedFrames() %7B%0A%09%09return frames;%0A%09%7D%0A%0A%09public Settings getSettings() %7B%0A%09%09return settings;%0A%09%7D%0A
 %7D%0A

add gamelogic frame counter