package com.emmett.chess.main.games;

import com.emmett.chess.main.model.Position;
import com.emmett.chess.main.model.boards.ChessBoard;
import com.emmett.chess.main.model.pieces.Piece;
import com.emmett.chess.main.model.players.HumanPlayer;
import com.emmett.chess.main.model.players.Player;
import com.emmett.chess.main.model.util.Color;
import com.emmett.chess.main.view.ConsoleBoardRenderer;
import com.emmett.chess.main.view.ConsoleMoveGetter;

import java.util.List;

/**
 * Created by emmett on 11/08/15.
 */
public class ConsoleChessGame {

    ChessBoard board = new ChessBoard();
    HumanPlayer player1 = new HumanPlayer(Color.WHITE);
    HumanPlayer player2 = new HumanPlayer(Color.BLACK);
    ConsoleMoveGetter prompt1 = new ConsoleMoveGetter();
    ConsoleMoveGetter prompt2 = new ConsoleMoveGetter();
    int turn = Color.WHITE;

    public ConsoleChessGame() {

        board.renderer = new ConsoleBoardRenderer(board);
        player1.moveGetter = prompt1;
        player2.moveGetter = prompt2;
        prompt1.player = player1;
        prompt2.player = player2;

        board.renderer.update();
        while(true) {
            doMoves();
        }
    }

    private void doMoves() {
        doMove(player1);
        doMove(player2);
    }

    private void doMove(Player player) {
        List<Position> move = player.getMove();
        Piece piece = board.getPieceAt(move.get(0));

        if(turn == player.color && piece.color == player.color) {
            piece.move(move.get(1));
            turn *= -1;
        }
        else {
            System.out.println("You can't do that!");
        }

    }
}

@@ -1119,113 +1119,280 @@
     
-while(true) %7B%0A            doMoves();%0A        %7D%0A    %7D%0A%0A    private void doMoves() %7B%0A        doMove
+doMoves();%0A    %7D%0A%0A    private void doMoves() %7B%0A        while(true) %7B%0A            playerMove(player1);%0A            playerMove(player2);%0A        %7D%0A    %7D%0A%0A    private void playerMove(Player player) %7B%0A        while(true) %7B%0A            try %7B%0A                promptPlayer
 (player
-1
 );%0A 
@@ -1402,24 +1402,152 @@
     
+       
-doMove(player2);
+ return;%0A            %7D%0A            catch(IllegalArgumentException e) %7B%0A                System.out.println(%22No.%22);%0A            %7D%0A        %7D
 %0A   
@@ -1567,22 +1567,28 @@
 te void 
-doMove
+promptPlayer
 (Player 
@@ -1867,46 +1867,52 @@
     
-System.out.println(%22You can't do that!
+throw new IllegalArgumentException(%22Dude no.
 %22);%0A
@@ -1917,21 +1917,20 @@
 ;%0A        %7D%0A
-%0A
     %7D%0A%7D%0A

Move prompting works now.