package gui;

import backend.util.GameRules;
import game.api.GameState;
import game.impl.GamePiece;
import game.impl.Move;
import game.impl.Player;
import game.io.InputUnit;

public class OthelloGuiInputUnit extends InputUnit {
	private GameState state;
	private OthelloGameFrame gameFrame;
	private String input;
	
	private Move getNextMove(GameState state) {
		Move result = null;
		try {
			result = new Move(state.getPlayerInTurn(), new GamePiece(
					getGamePieceID(state.getPlayerInTurn(), state)),
					GameRules.getLocationById(state.getBoard(), input));
		} catch (Exception ex) {
			gameFrame.setStatusLabelText(ex.getMessage());
		}
		return result;
	}

	private String getGamePieceID(Player player, GameState gameState) {
		if (player == gameState.getPlayers().get(0))
			return "O";
		else
			return "X";
	}

	@Override
	public void setup(GameState state) {
		this.state = state;
		this.state.reset();
	}

	public void notifyListeners(String inputTileName) {
		input = inputTileName;
		notifyListenersOfMove(getNextMove(state));
	}
}

@@ -354,16 +354,89 @@
 tate) %7B%0A
+        if(input.toLowerCase().equals(%22undo%22))%0A            return null;%0A%0A
 %09%09Move r
@@ -457,16 +457,17 @@
 %09%09try %7B%0A
+%0A
 %09%09%09resul

undo added in gui inputunit