Question: Create a Java TicTac Game with the given info: TicTacToe Class: import java.util.Scanner; public class TicTacToe { private char[][] board; private char currentPlayer; // methods

 Create a Java TicTac Game with the given info: "TicTacToe Class":

Create a Java TicTac Game with the given info:

"TicTacToe Class":

import java.util.Scanner; public class TicTacToe { private char[][] board; private char currentPlayer; // methods we need // 0. constructor: new an empty board, set currentPlayer // 1. print board // 2. currentPlayer mark a place public void markPlace(){ Scanner scanner = new Scanner(System.in); int row = scanner.nextInt(); int col = scanner.nextInt(); // check if board[row][col] is vacant // mark board[row][col] to be currentPlayer } // 2.1 check if a place is vacant // 3. switch player // 4. check if one player wins // 5. check if the board is full public boolean boardIsFull(){ // check if board is full and return true or false return true; } }

"The Main Class":

public class Main { public static void main(String[] args) { // Create game and initialize it. // First player will be 'x' TicTacToe game = new TicTacToe(); while( !game.boardIsFull() ) { game.markPlace(); if (game.hasWinner()) { // display the winner break; } game.switchPlayer(); } } } 

This is the game of Tic Tac Toe. You will be playing against the computer. | | --- --- --- --------- Enter X,Y coordinates for your move: 1,1 XTOL ---/---/--- | --- --- --- Enter X,Y coordinates for your move: 2,2 X TOTO ---/---/--- IX. --------- Enter X, Y coordinates for your move: 3,3 You won! XIOLO --- --- --- TXT --- --- --- I IX

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!