package is.ru.tictactoe;
import java.util.Scanner;

public class TicTacToe {

  private Board board;
  private Player player1, player2, winner;
  private final int SIZE = 3;

  public TicTacToe (Player player1, Player player2) {
    this.board = new Board();
    this.player1 = player1;
    this.player2 = player2;
    this.winner = null;
  }

  private Player switchPlayer(Player player){
    if(player == player1){
      player = player2;
    }
    else{
      player = player1;
    }

    return player;
  }

  private void gameIteration(Player player, Scanner scanner){
    for (int i = 0; i < (SIZE*SIZE); i++) {
      System.out.println();
      board.print();
      System.out.println();
      System.out.print(player.getName() + ", its your move: ");
      int input = scanner.nextInt();
      board.changeBoard(player.getSymbol(), input);
      if (board.checkWinner(player)){
        winner = player;
        return;
      }
      player = switchPlayer(player);
    }
  }

  public void play(Scanner scanner) {
    boolean continueGame = true;
    Player player = player1;
    while (continueGame) {
      gameIteration(player, scanner);
      board.print();
      board = new Board();
      if(winner != null){
        if(winner == player1){
          player1.incrementScore();
        }
        else{
          player2.incrementScore();
        }
        System.out.println(winner.getName() + ", You won this round");      
        winner = null;
      }
      else{
        System.out.println("This round was a draw!");
      }
      System.out.println("Do you want to play another round (Y/N): ");
      char cont = scanner.next().charAt(0);
      continueGame = cont == 'Y' ? true : false;
    }
  }

  public static void main(String[] args){
      Scanner scanner = new Scanner(System.in);
      System.out.println();
      System.out.print("Please enter a name for player1: ");
      String p1Name = getName(scanner);
      Player player1 = new Player(p1Name, Symbol.CROSS);
      System.out.println();
      System.out.print("Please enter a name for player2: ");
      String p2Name = getName(scanner);
      Player player2 = new Player(p2Name, Symbol.CIRCLE);
      TicTacToe game = new TicTacToe(player1, player2);
      game.play(scanner);
      scanner.close();
  }

  private static String getName(Scanner scanner){
    String name;
    name = scanner.nextLine();
    return name;
  }
}

@@ -994,209 +994,23 @@
 oid 
-play(Scanner scanner) %7B%0A    boolean continueGame = true;%0A    Player player = player1;%0A    while (continueGame) %7B%0A      gameIteration(player, scanner);%0A      board.print();%0A      board = new Board();%0A  
+restartGame()%7B%0A
     
@@ -1035,18 +1035,16 @@
 %7B%0A      
-  
 if(winne
@@ -1062,26 +1062,24 @@
 1)%7B%0A        
- 
- 
 player1.incr
@@ -1094,30 +1094,26 @@
 re();%0A      
-  %7D%0A  
+%7D%0A
       else%7B%0A
@@ -1108,26 +1108,24 @@
       else%7B%0A
-  
         play
@@ -1148,30 +1148,26 @@
 re();%0A      
-  %7D%0A  
+%7D%0A
       System
@@ -1226,17 +1226,9 @@
 d%22);
-      %0A  
+%0A
     
@@ -1244,18 +1244,16 @@
 = null;%0A
-  
     %7D%0A  
@@ -1250,34 +1250,30 @@
 ;%0A    %7D%0A    
-  
 else%7B%0A
-  
       System
@@ -1312,27 +1312,264 @@
 raw!%22);%0A    
+%7D%0A
   %7D
+%0A%0A  public void play(Scanner scanner) %7B%0A    boolean continueGame = true;%0A    Player player = player1;%0A    while (continueGame) %7B%0A      gameIteration(player, scanner);%0A      board.print();%0A      board = new Board();%0A      restartGame();
 %0A      Syste

Refactor last commit