package pylos.controller;

import pylos.Pylos;
import pylos.model.Ball;
import pylos.model.Model;
import pylos.model.Position;
import pylos.view.View;

/**
 * The Pylos Controller.
 * Implements the singleton pattern by having everything static and no instance (the object is the class).
 */
public abstract class Controller {
	static View view;

	public static void initialize(View view) {
		Controller.view = view;
		initTurn();
	}

	public static void updateView() {
		view.board.drawBalls();
		view.updatePositionBalls();
	}

	public static void initTurn() {
		Model.currentPlayer.resetAction();
	}

	public static void finishTurn() {
		if (Model.isWinner()) {
			updateView();
			Pylos.logger.info(Model.currentPlayer + " won");
		} else {
			nextTurn();
		}
	}

	public static void placePlayerBall(Position position) {
		Model.currentPlayer.putBallOnBoard(position);
		finishTurn();
	}

	private static void nextTurn() {
		Model.currentPlayer = (Model.currentPlayer == Model.player1) ? Model.player2 : Model.player1;
		initTurn();
		updateView();
	}

	public static void risePlayerBall(Ball ball) {
		if (Model.getPositionsToRise(ball).isEmpty()) {
			System.err.println("Can not rise ball, there is no place to rise it.");
		} else {
			Model.currentPlayer.riseBall(ball);
			view.updatePositionsToRise(ball);
			updateView();
		}
	}
}

@@ -40,16 +40,51 @@
 .Pylos;%0A
+import pylos.exception.PylosError;%0A
 import p
@@ -1190,26 +1190,28 @@
 %0A%09%09%09
-System.err.println
+throw new PylosError
 (%22Ca

Raise an error instead of a printing it