/** * TicTacToe2 * is a 2D implementation of the game Tic-Tac-Toe * (Some know this as Naughts and Crosses). * It can be more than just 3 by 3 in size. * * * @author (your name) * @version (a version number or a date) */ public class TicTacToe2 { // instance variables private String[][] grid; private String player; private int size; /** * Constructor for objects of class TicTacToe * initializes the fields and places a Space in * each element of grid of the specified size, * and a "X" */ public TicTacToe2(int size) { // your code here } /** * changePlayer will switch player back and forth between "X" and "O" */ public void changePlayer() { // your code here } /** * If there is a space in the grid location (row,col), * will put the players mark in the grid and * change the player (don't duplicate code). */ public void mark(int row, int col) { // your code here } /** * returns the mark of the current player */ public String getPlayer() { // your code here } /** * returns the number of spaces (moves) * remaining in the grid. */ public int movesRemaining() { // your code here } /** * winner returns: * "TBD" if the winner is yet to be determined * "X won" or "O won" if a player has SIZE in a row * "Cat's game" is there is no moves left and no one won. */ public String winner() { // first: // your code here to look for size in a row // your code here to look for size in a column // your code here to look for size in a diagonal top left to bottom right // your code here to look for size in a diagonal top right to bottom left //finally, if no winner found... if (movesRemaining() > 0) return "TBD"; return "Cats game"; } public String toString() { String result = ""; for(int r = 0 ; r < grid.length; r++) { int cols = grid[r].length; for(int c = 0; c < cols; c++) { result += " " + grid[r][c]; if (c < cols-1) result += " |"; } if (r < cols-1) { result+="\n----"; for (int i = 0; i < grid[r].length-1; i ++) result +="----"; } result +="\n"; } return result; } public void print() { System.out.println( "\n"+this ); System.out.println( movesRemaining() + " moves remaining."); } public static void main(String[] args) { TicTacToe2 board = new TicTacToe2(3); // try changing 3 to make a 4x4 game board.print(); } }