JAVA Tic Tac Nole This project can be done utilizing intellJ 1. You need to writ
ID: 3810207 • Letter: J
Question
JAVA
Tic Tac Nole
This project can be done utilizing intellJ
1. You need to write a while loop followed by if/else statements.
2. You need to write 1 while loop followed by 3 if/else statements. - Borderline, try to avoid.
3. You need to write while(x>1){}.
title bar.
2. The footer should include your name.
3. All logic must be written in Java.
4. Minimum requirement is the ability for 2 human players.
5. You can be creative. The game does not have to be exactly like the wireframes, but it does have to be obvious that the game is Tic Tac Toe.
6. Extra credit will be given for going above and beyond. For example:
a. Playing against the computer.
b. Adding AI to the computer's responses such as building in logic so that if player X has two in a row, then Player O will detect that and block.
c. Instead of X's and O's, give the ability to use college mascots. X may be an image of a Seminole where O may be an image of a Gator.
7. Absolutely NO AUTO GENERATED CODE
Explanation / Answer
Answer:
import java.util.*;
public class GameofTicTacToe
{
private int incrementer;
private char location[]=new char[10];
private char gamer;
public static void main(String args[])
{
String ch;
GameofTicTacToe input=new GameofTicTacToe();
do{
input.newGame();
input.play();
System.out.println ("If you want to play the game again please enter yes ");
Scanner in =new Scanner(System.in);
ch=in.nextLine();
System.out.println("ch value is "+ch);
}while (ch.equals("yes"));
}
public void newGame()
{
char locationdef[] = {'0','1', '2', '3', '4', '5', '6', '7', '8', '9'};
int i;
incrementer = 0;
gamer = 'X';
for (i=1; i<10; i++) location[i]=locationdef[i];
presentworkingBoard();
}
public String presentworkingBoard()
{
System.out.println( " " );
System.out.println( " " );
System.out.println( " " + location [1] + " | " +location [2]+ " | " +location [3]);
System.out.println( " | | " );
System.out.println( " ___|____|___ " );
System.out.println( " " +location [4]+ " | " +location [5]+ " | " +location [6]);
System.out.println( " | | " );
System.out.println( " ___|____|___ " );
System.out.println( " " +location [7]+ " | " +location [8]+ " | " +location [9]);
System.out.println( " | | " );
System.out.println( " | | " );
System.out.println( " " );
return "presentworkingBoard";
}
public void play()
{
int center;
char empty = ' ';
System.out.println( "Player " + obtainGamer() +" will go initially and would take the letter 'X'" );
do {
presentworkingBoard();
System.out.println( " Player " + obtainGamer() +" occupy a location" );
boolean locationOccupied = true;
while (locationOccupied) {
Scanner in =new Scanner (System.in);
center=in.nextInt();
locationOccupied = examinelocation(center);
if(locationOccupied==false)
location[center]=obtainGamer();
}
System.out.println( "Brilliant move" );
presentworkingBoard();
upcomingGamer();
}while ( examineWinner() == empty );
}
public char examineWinner()
{
char Winner = ' ';
if (location[1] == 'X' && location[2] == 'X' && location[3] == 'X') Winner = 'X';
if (location[4] == 'X' && location[5] == 'X' && location[6] == 'X') Winner = 'X';
if (location[7] == 'X' && location[8] == 'X' && location[9] == 'X') Winner = 'X';
if (location[1] == 'X' && location[4] == 'X' && location[7] == 'X') Winner = 'X';
if (location[2] == 'X' && location[5] == 'X' && location[8] == 'X') Winner = 'X';
if (location[3] == 'X' && location[6] == 'X' && location[9] == 'X') Winner = 'X';
if (location[1] == 'X' && location[5] == 'X' && location[9] == 'X') Winner = 'X';
if (location[3] == 'X' && location[5] == 'X' && location[7] == 'X') Winner = 'X';
if (Winner == 'X' )
{System.out.println("Gamer1 won the game." );
return Winner;
}
if (location[1] == 'O' && location[2] == 'O' && location[3] == 'O') Winner = 'O';
if (location[4] == 'O' && location[5] == 'O' && location[6] == 'O') Winner = 'O';
if (location[7] == 'O' && location[8] == 'O' && location[9] == 'O') Winner = 'O';
if (location[1] == 'O' && location[4] == 'O' && location[7] == 'O') Winner = 'O';
if (location[2] == 'O' && location[5] == 'O' && location[8] == 'O') Winner = 'O';
if (location[3] == 'O' && location[6] == 'O' && location[9] == 'O') Winner = 'O';
if (location[1] == 'O' && location[5] == 'O' && location[9] == 'O') Winner = 'O';
if (location[3] == 'O' && location[5] == 'O' && location[7] == 'O') Winner = 'O';
if (Winner == 'O' )
{
System.out.println( "Gamer2 won the game" );
return Winner; }
for(int i=1;i<10;i++)
{
if(location[i]=='X' || location[i]=='O')
{
if(i==9)
{
char design='D';
System.out.println(" Game is standoff ");
return design;
}
continue;
}
else
break;
}
return Winner;
}
public boolean examinelocation(int center)
{
if (location[center] == 'X' || location[center] == 'O')
{
System.out.println("That location is already occupied please choose other location");
return true;
}
else {
return false;
}
}
public void upcomingGamer()
{
if (gamer == 'X')
gamer = 'O';
else gamer = 'X';
}
public String getName()
{
return "Tic Tac Toe Mind Game" ;
}
public char obtainGamer()
{
return gamer;
}
}
Output:
E:>javac GameofTicTacToe.java
E:>java GameofTicTacToe
1 | 2 | 3
| |
___|____|___
4 | 5 | 6
| |
___|____|___
7 | 8 | 9
| |
| |
Player X will go initially and would take the letter 'X'
1 | 2 | 3
| |
___|____|___
4 | 5 | 6
| |
___|____|___
7 | 8 | 9
| |
| |
Player X occupy a location
1
Brilliant move
X | 2 | 3
| |
___|____|___
4 | 5 | 6
| |
___|____|___
7 | 8 | 9
| |
| |
X | 2 | 3
| |
___|____|___
4 | 5 | 6
| |
___|____|___
7 | 8 | 9
| |
| |
Player O occupy a location
2
Brilliant move
X | O | 3
| |
___|____|___
4 | 5 | 6
| |
___|____|___
7 | 8 | 9
| |
| |
X | O | 3
| |
___|____|___
4 | 5 | 6
| |
___|____|___
7 | 8 | 9
| |
| |
Player X occupy a location
5
Brilliant move
X | O | 3
| |
___|____|___
4 | X | 6
| |
___|____|___
7 | 8 | 9
| |
| |
X | O | 3
| |
___|____|___
4 | X | 6
| |
___|____|___
7 | 8 | 9
| |
| |
Player O occupy a location
3
Brilliant move
X | O | O
| |
___|____|___
4 | X | 6
| |
___|____|___
7 | 8 | 9
| |
| |
X | O | O
| |
___|____|___
4 | X | 6
| |
___|____|___
7 | 8 | 9
| |
| |
Player X occupy a location
9
Brilliant move
X | O | O
| |
___|____|___
4 | X | 6
| |
___|____|___
7 | 8 | X
| |
| |
Gamer1 won the game.
If you want to play the game again please enter yes
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.