<commit_before>package com.java.laiy.view;


import com.java.laiy.controller.GameController;
import com.java.laiy.model.Player;
import com.java.laiy.model.Point;
import com.java.laiy.model.exceptions.InvalidPointException;

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

public class ConsoleView implements IView {

    private static final String CHARACTER_HYPHEN = "_";

    private static final String EMPTY_FIGURE = " ";

    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 Point startTurn() {
        System.out.println("Next turn!");
        return new Point(getCoordinate(),getCoordinate());
    }

    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() {
        int lineSize = game.getBoard().getFiguresArray().length;
        for (int i = 0 ; i < lineSize; i++) {
            showBoardLine(i);
            printLine(CHARACTER_HYPHEN, lineSize);
        }
    }

    public void  showWinner(){
        System.out.println("The winner is " + game.getWinner().getName());
    }

    public void showDraw(){
        System.out.println("Draw!");
    }

    public void showPointOccupied(){
        System.out.println("Point already occupied!");
    }

    private 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++) {
            try {
                if (game.getBoard().getFigure(row, i) == null) {
                    System.out.print(EMPTY_FIGURE);
                } else {
                    System.out.print(game.getBoard().getFigure(row, i).toString());
                }
            } catch (final InvalidPointException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
        System.out.println();
    }

    private int getCoordinate() {
        while (true) {
            System.out.print("Input the coordinate ");
            try {
                final Scanner in = new Scanner(System.in);
                int coordinate = in.nextInt() - 1;
                if (game.getBoard().checkCoordinate(coordinate)) {
                    return coordinate;
                }
                else {
                    System.out.println(INPUT_ERROR);
                }
            }
            catch (final InputMismatchException e) {
                System.out.println(INPUT_ERROR);
                }<commit_msg>Revert "Revert "ConsoleView updated""<commit_after>package com.java.laiy.view;


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

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

public class ConsoleView implements IView {

    private static final String CHARACTER_HYPHEN = "-";

    private static final String EMPTY_FIGURE = " ";

    private static final String INPUT_ERROR = "Incorrect input, please try again";

    protected final GameController game;

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

    public Point startTurn() {
        System.out.println("Next turn!");
        return new Point(getCoordinate(),getCoordinate());
    }

    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() {
        int lineSize = game.getBoard().getFiguresArray().length;
        for (int i = 0 ; i < lineSize; i++) {
            showBoardLine(i);
            printLine(CHARACTER_HYPHEN, lineSize);
        }
    }

    public void  showWinner(){
        System.out.println("The winner is " + game.getWinner().getName());
    }

    public void showDraw(){
        System.out.println("Draw!");
    }

    public void showPointOccupied(){
        System.out.println("Point already occupied!");
    }

    private 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++) {
            try {
                if (game.getBoard().getFigure(row, i) == null) {
                    System.out.print(EMPTY_FIGURE);
                } else {
                    System.out.print(game.getBoard().getFigure(row, i).toString());
                }
            } catch (final InvalidPointException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
        System.out.println();
    }

    private int getCoordinate() {
        while (true) {
            System.out.print("Input the coordinate ");
            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);
                }
{'fraction_non_alphanumeric': 0.11366601435094585, 'fraction_numerical': 0.001304631441617743, 'mean_word_length': 1.94997594997595, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2479250', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1649, 'n_words': 370}