/* * * * * * * * * * * * * * * * * * * * * * * * * * * * Alex Launi * * Jordan Goldberk * * Kyle Sebring * * * * 2DTicTacToe.java is a two dimentional TicTacToe * * game. It implements the AnyTicTacToe interface * * TicTacToe games. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ import java.util.Scanner; public class 2DTicTacToe implements AnyTicTacToe { // Field variables for 2D TicTacToe public char[][] gameBoard; final int ROWS = 3, COLS = 3; // Class constructor to initialize the game board public 2DTicTacToe() { gameBoard = new char[ROWS][COLS]; } // Prints game board in its current state public void printBoard() { System.out.println(" 1 2 3 "); vertes(); vertes(); System.out.println("1 " + gameBoard[0][0] + " | " + gameBoard[0][1] + " | " + gameBoard[0][2] + " "); vertes(); vertHoriz(); vertes(); vertes(); System.out.println("2 " + gameBoard[1][0] + " | " + gameBoard[1][1] + " | " + gameBoard[1][2] + " "); vertes(); vertHoriz(); vertes(); vertes(); System.out.println("3 " + gameBoard[2][0] + " | " + gameBoard[2][1] + " | " + gameBoard[2][2] + " "); vertes(); vertes(); } // Prints some vertical lines private void vertes() { System.out.println(" | | "); } // Prints some vertical lines and some horiztonal ones too private void verteHoriz() { System.out.println(" _____|_____|_____"); } // returns true if move was made, false if said space is already occupied // @console is a Scanner to take location to place X or O // @player X or O depending on whose turn it is public void move(Scanner console, char player) { int row, col; System.out.print("It is the " + player + " turn."); System.out.print("Please enter a row and a column: "); int row = console.nextInt(); int col = console.nextInt(); while(canMove(row,col)) { gameBoard[row][col] = player; } } // helper method for move() that checks if the space is occupied private boolean canMove(int row, int col) { if(gameBoard[row][col] != '') { return false; } else { return true; } } // Checks board for a full row of Xs or Os. // returns true if there is a full row public boolean fullRow() { // Checks the array for 3 of the same characters in a horizontal, vertical, or diagonal row. // It returns true if there are 3 of the same characters in a h, v, or d row. // Will be useful to use as the conditon for a loop in the main body of our program } }