From ed29fd0b5949e34c2368e790ab790e06ffeda3de Mon Sep 17 00:00:00 2001 From: mavlushechka Date: Sun, 21 Nov 2021 16:30:47 +0500 Subject: Changed players char constants to enum --- src/com/mavlushechka/tictactoe/TicTacToe.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) mode change 100644 => 100755 src/com/mavlushechka/tictactoe/TicTacToe.java diff --git a/src/com/mavlushechka/tictactoe/TicTacToe.java b/src/com/mavlushechka/tictactoe/TicTacToe.java old mode 100644 new mode 100755 index a627585..b9b12e9 --- a/src/com/mavlushechka/tictactoe/TicTacToe.java +++ b/src/com/mavlushechka/tictactoe/TicTacToe.java @@ -2,18 +2,15 @@ package com.mavlushechka.tictactoe; import com.mavlushechka.tictactoe.exceptions.IncorrectCoordinatesDiapasonException; import com.mavlushechka.tictactoe.exceptions.OccupiedCellException; +import com.mavlushechka.tictactoe.players.Player; import java.util.Scanner; public final class TicTacToe { - private static final char FIRST_PLAYER = 'X'; - - private static final char SECOND_PLAYER = 'O'; - private final char[][] cells = {{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}}; - private char currentPlayer = FIRST_PLAYER; + private char currentPlayer = Player.FIRST.SYMBOL; private boolean gameFinished = false; @@ -34,7 +31,7 @@ public final class TicTacToe { When all 9 squares are full, the game is over. First player is %c. Players must enter the y and x coordinates separated by a space. - """, FIRST_PLAYER, SECOND_PLAYER, FIRST_PLAYER); + """, Player.FIRST.SYMBOL, Player.SECOND.SYMBOL, Player.FIRST.SYMBOL); } private void showCells() { @@ -81,7 +78,7 @@ public final class TicTacToe { private void move(byte y, byte x) { cells[y][x] = currentPlayer; - currentPlayer = (currentPlayer == FIRST_PLAYER) ? SECOND_PLAYER : FIRST_PLAYER; + currentPlayer = (currentPlayer == Player.FIRST.SYMBOL) ? Player.SECOND.SYMBOL : Player.FIRST.SYMBOL; showCells(); checkLines(); -- cgit v1.2.3