import java.util.Scanner; /** * TicTacToeTextGame makes a console/text * based version of the game using the * TicTacToe2 class. * * @author Chris Thiel, ofmcap * @version 31 Oct 2020 */ public class TicTacToeTextGame { public static final int SIZE = 3; public static void makeMove(TicTacToe2 game, Scanner kb) { boolean valid = false; int row = -1; int col = -1; while (!valid) { System.out.print("row: (0-"+(SIZE-1)+") "); String r = kb.nextLine(); System.out.print("column: (0-"+(SIZE-1)+") "); String c = kb.nextLine(); try{ row = Integer.parseInt(r); col = Integer.parseInt(c); valid = (row >=0) && (row < SIZE) && (col >=0) && (col < SIZE); } catch ( NumberFormatException e ){ valid = false; } } game.mark(row, col); } public static void main(String[] args) { Scanner kb = new Scanner(System.in); TicTacToe2 game = new TicTacToe2(SIZE); while (game.winner().equals("TBD") ) { game.print(); System.out.println("It's " + game.getPlayer() + " turn"); makeMove(game, kb); } game.print(); System.out.println( game.winner() ); } }