/** * TicTacToe2. * * @author (your name) * @version (a version number or a date) */ public class TicTacToe { // instance variables - replace the example below with your own private String[][] grid; private String player; /** * Constructor for objects of class TicTacToe * initializes the fields and places a Space in * each element of grid of the specified size */ public TicTacToe(int size) { grid = new String[size][size]; for (int row = 0; row < size; row++) for (int col = 0; col < size; col++) grid[row][col] = " "; //space player ="X"; } /** * will switch player back and forth between "X and "O" */ public void changePlayer() { if (player.equals("X") ) player="O"; else player ="X"; } /** * will put the palyers mark in the grid */ public void mark(int row, int col) { grid[row][col]=player; changePlayer(); } public String toString() { String result = ""; for(int r = 0 ; r < grid.length; r++) { for(int c = 0; c < grid[r].length; c++) { result += " " + grid[r][c]; if (c < 2) result += " |"; } if (r< 2) { result+="\n "; for (int i = 0; i < grid[r].length; i ++) result +="---"; } result +="\n"; } return result; } public void print() { System.out.println( this ); } }