Java Program that implements the TicTacToe game. The program should support the following interface:
class Player{
String name;
char symbol;
void setName (String pName)
String getName ()
void setSymbol (char symb)
char getSymbol (symb)
String toString()
}
class TicTacTaeBoard{
char [][] board ;
Player plyr1;
Player plyr2;
Player winner ;
byte turn; // 1 for player 1 or 2 for player 2
byte round; // from 1 to 9
/* constructor */
TicTacTaeBoard (Player p1, Player p2)
/* shows the name of the player to play, his symbol and game round.
Prompts the player to Enter his movement (row and column numbers)
if the movement is correct it records the movement and update the turn and the round, else it asks the player to retry. */
void play()
/* returns true if the board has a wining situation and false otherwise. */
boolean isWinSituation ()
/* returns a string representing the two player names, their symbols, the game round, the winner name (if there is a winner), and the board contents
*/
String toString()
}
Class TicTacTaeGame{
/* Runs the game as follows:
- Prompts the users to enter the two players names and symbols
- Instantiates an object for each of the two players and an object for the TicTacTaeBoard
- Invokes the play method of TicTacTaeBoard repetitively until the game ends (one of the players has won or game reached round 9) .
- Invokes the toString method to print the game result
*/
public static void main (String [] args)
}
and also 2 more conditions but in different classes:
1) Computer-to-computer game: Modify the program so it simulates automated games where the system defines two players and plays the game automatically. The system first chooses the first movement for each player randomly (use the Random API), then it continues playing following specific hard-coded rules.
2) Computer-to-player: Modify the program so it allows a player to play against the computer
thx alot