package com.java.laiy.view;


import com.java.laiy.controller.GameController;
import com.java.laiy.model.Player;
import com.java.laiy.helpers.CoordinateHelper;

import java.util.InputMismatchException;
import java.util.Scanner;

public class ConsoleView {

    private static final int LINE_SIZE = 3;

    private static final String CHARACTER_HYPHEN = "_";

    private static final String EMPTY_FIGURE = " ";

    private static final String DEFAULT_PLAYER_1 = "X";

    private static final String DEFAULT_PLAYER_2 = "O";

    private static final String INPUT_ERROR = "Coordinate is incorrect, please try again";

    protected final GameController game;

    public ConsoleView(final GameController game) {
        assert game != null;
        this.game = game;
    }

    public void start() {
        System.out.println("Your turn, input coordinates: ");
        int x = getCoordinate(DEFAULT_PLAYER_1);
        int y = getCoordinate(DEFAULT_PLAYER_2);
    }

    public  void showGameName() {
        System.out.println(game.getGameName());
    }

    public void showPlayers() {
         for (Player player : game.getPlayers()) {
             System.out.println(player.getName() + ": " + player.getFigure().toString() );
         }
    }

    public void showBoard() {
        for (int i = 0 ; i < game.getBoard().getFiguresArray().length; i++) {
            showBoardLine(i);
            printLine(CHARACTER_HYPHEN, LINE_SIZE);
        }
    }

    protected static void printLine(final String lineCharacter, final int lineSize) {
        for (int i = 0; i < lineSize; i++) {
            System.out.print(lineCharacter);
        }
        System.out.println();
    }

    private void showBoardLine(final int row) {
        for (int i = 0; i < game.getBoard().getRowLength(row); i++) {
            if (game.getBoard().getFigure(row, i) == null) {
                System.out.print(EMPTY_FIGURE);
            } else {
                System.out.print(game.getBoard().getFigure(row, i).toString());
            }
        }
        System.out.println();
    }

    private int getCoordinate(final String coordinateName) {
        while (true) {
            System.out.print(String.format("Input the coordinate %s:", coordinateName));
            try {
                final Scanner in = new Scanner(System.in);
                int coordinate = in.nextInt() - 1;
                if (CoordinateHelper.checkCoordinate(coordinate)) {
                    return coordinate;
                }
                else {
                    System.out.println(INPUT_ERROR);
                }
            }
            catch (final InputMismatchException e) {
                System.out.println(INPUT_ERROR);
                }
            }

    }

}

@@ -347,17 +347,17 @@
 PHEN = %22
-_
+-
 %22;%0A%0A    
@@ -437,32 +437,28 @@
  String 
-DEFAULT_PLAYER_1
+COORDINATE_X
  = %22X%22;%0A
@@ -494,29 +494,25 @@
 ing 
-DEFAULT_PLAYER_2
+COORDINATE_Y
  = %22
-O
+Y
 %22;%0A%0A
@@ -608,24 +608,21 @@
 ;%0A%0A    p
-rotected
+ublic
  final G
@@ -771,84 +771,123 @@
 lic 
-void
+int
  start(
-) %7B%0A        System.out.println(%22Your turn, input coordinates: %22);
+String coordinate, Player player) %7B%0A        int x = 0;%0A        switch(coordinate) %7B%0A            case %22X%22:
 %0A   
@@ -887,27 +887,31 @@
 X%22:%0A        
-int
+       
  x = getCoor
@@ -921,74 +921,265 @@
 ate(
-DEFAULT_PLAYER_1);%0A        int y = getCoordinate(DEFAULT_PLAYER_2)
+COORDINATE_X, player);%0A                break;%0A            case %22Y%22:%0A                x = getCoordinate(COORDINATE_Y, player);%0A                break;%0A            default:%0A                System.out.println();;%0A                break;%0A        %7D%0A        return x
 ;%0A  
@@ -1194,17 +1194,16 @@
  public 
- 
 void sho
@@ -1679,237 +1679,13 @@
    p
-rotected static void printLine(final String lineCharacter, final int lineSize) %7B%0A        for (int i = 0; i %3C lineSize; i++) %7B%0A            System.out.print(lineCharacter);%0A        %7D%0A        System.out.println();%0A    %7D%0A%0A    private
+ublic
  voi
@@ -2054,24 +2054,244 @@
 n();%0A    %7D%0A%0A
+    public static void printLine(final String lineCharacter, final int lineSize) %7B%0A        for (int i = 0; i %3C lineSize; i++) %7B%0A            System.out.print(lineCharacter);%0A        %7D%0A        System.out.println();%0A    %7D%0A%0A
     private 
@@ -2335,16 +2335,37 @@
 nateName
+, final Player player
 ) %7B%0A    
@@ -2379,24 +2379,79 @@
 le (true) %7B%0A
+            System.out.print(player.getName() + %22, %22);%0A
             
@@ -2482,17 +2482,17 @@
 format(%22
-I
+i
 nput the

Update ConsoleView.java