package de.htwg.minesweeper.aview.tui;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import de.htwg.minesweeper.controller.IController;
import util.observer.Event;
import util.observer.IObserver;


public class TUI implements IObserver {
	private static final Logger LOGGER = LogManager.getLogger();
	
	
	private IController controller;
	
	
	public TUI(IController controller){
		this.controller = controller;
		controller.addObserver(this);
	}
	

	public boolean answerOptions(String answer){
		boolean continu = true;
		switch(answer){
			case "q":
				continu = false;
				controller.exitGame();
			break;
			
			case "n":
				controller.newGame();
			break;
			
			case "h":
				controller.hilfe();
			break;
			
			
			default:
				controller.startGame(answer);
		}
		return continu;
	}

	@Override
	public void update(Event e) {
		printTui();
	}

	
	public StringBuilder printField(String[][] field){
		StringBuilder result = new StringBuilder();
		for(int j = 0; j < controller.getRow(); j++){
			for(int i= 0; i < controller.getColumn(); i++){
				result.append(field[i][j]).append(" ");
			}
			result.append("\n");
		}
		return result;
	}


	public void printTui() {
		int status = controller.getStatusCode();
		
		if(!(status == 5)){
			
		
			StringBuilder stringBuilder;
			
			stringBuilder = printField(controller.getFeldText());
			
			if(!"".equals(controller.getFieldPosition()))
				LOGGER.info("You typed: " + controller.getFieldPosition() + "\n");
			
			LOGGER.info(stringBuilder.toString());
			
			if(status == 1 || status == 0)
				LOGGER.info("Type: x,x | x is a number between 0 and 9(row, column):\n");
			if(status == 2)
				LOGGER.info("You Lost!");
			if(status == 3){
				LOGGER.info("You Won! " + controller.getTimeWon() + " Points!");
			}
			if(status == 4){
				LOGGER.info(controller.getHelpText());
			}
			if(status == 2 || status == 3)
				LOGGER.info("New Game? Type: n");
		}else{
			LOGGER.error("NOT A NUMBER!");
		}
	}
}	

@@ -33,16 +33,18 @@
 w.tui;%0D%0A
+%0D%0A
 import o
@@ -121,18 +121,16 @@
 ogger;%0D%0A
-%0D%0A
 import d
@@ -237,18 +237,16 @@
 ver;%0D%0A%0D%0A
-%0D%0A
 public c
@@ -341,22 +341,16 @@
 ger();%0D%0A
-%09%0D%0A%09%0D%0A
 %09private
@@ -379,14 +379,10 @@
 r;%0D%0A
-%09%0D%0A%09
 %0D%0A
+
 %09pub
@@ -488,18 +488,16 @@
 %0A%09%7D%0D%0A%09%0D%0A
-%0D%0A
 %09public 
@@ -921,19 +921,16 @@
 %0D%0A%09%7D%0D%0A%0D%0A
-%09%0D%0A
 %09public 
@@ -1227,18 +1227,16 @@
 %0D%0A%09%7D%0D%0A%0D%0A
-%0D%0A
 %09public 
@@ -1302,16 +1302,16 @@
 );%0D%0A%09%09%0D%0A
+
 %09%09if(!(s
@@ -1325,21 +1325,16 @@
 = 5))%7B%0D%0A
-%09%09%09%0D%0A
 %09%09%0D%0A%09%09%09S

Update TUI.java