I need screenshots for this solution done in Flowgorithm. Thank you.
Tic-Tac-Toe Game
Design a program that allows two players to play a game of
tic-tac-toe. Use a
two-
dimensional String array with three rows and three columns as the
game
board. Each element of the array should be initialized with an
asterisk (*). The
program should run a loop that does the following:
a. Displays the contents of the board array.
b. Allows player 1 to select a location on the board for an X. The
program should
ask the user to enter the row and column number.
c. Allows player 2 to select a location on the board for an O. The
program should
ask the user to enter the row and column number.
d. Determines whether a player has won or if a tie has occurred. If
a player has
won, the program should declare that player the winner and end. If
a tie has
occurred, the program should say so and end.
e. Player 1 wins when there are three Xs in a row on the game
board. Player 2
wins when there are three Os in a row on the game board. The
winning Xs or
Os can appear in a row, in a column, or diagonally across the
board. A tie
occurs when all of the locations on the board are full, but there
is no winner.
Create a project named 'TicTacToe', and add the following 6
classes, run and be happy.
-->TicTacToe.java
public class TicTacToe {
public static void main(String[] args) {
Game game = new Game();
}
}
-->Board.java
public class Board {
private int[][] Board= new int[3][3];
public Board(){
clearBoard();
}
public void clearBoard(){
for(int line=0 ; line<3 ; line++)
for(int column=0 ; column<3 ; column++)
Board[line][column]=0;
}
public void showBoard(){
System.out.println();
for(int line=0 ; line<3 ; line++){
for(int column=0 ; column<3 ; column++){
if(Board[line][column]==-1){
System.out.print(" X ");
}
if(Board[line][column]==1){
System.out.print(" O ");
}
if(Board[line][column]==0){
System.out.print(" ");
}
if(column==0 || column==1)
System.out.print("|");
}
System.out.println();
}
}
public int getPosition(int[] attempt){
return Board[attempt[0]][attempt[1]];
}
public void setPosition(int[] attempt, int player){
if(player == 1)
Board[attempt[0]][attempt[1]] = -1;
else
Board[attempt[0]][attempt[1]] = 1;
}
public int checkLines(){
for(int line=0 ; line<3 ; line++){
if( (Board[line][0] + Board[line][1] + Board[line][2]) == -3)
return -1;
if( (Board[line][0] + Board[line][1] + Board[line][2]) == 3)
return 1;
}
return 0;
}
public int checkColumns(){
for(int column=0 ; column<3 ; column++){
if( (Board[0][column] + Board[1][column] + Board[2][column]) == -3)
return -1;
if( (Board[0][column] + Board[1][column] + Board[2][column]) == 3)
return 1;
}
return 0;
}
public int checkDiagonals(){
if( (Board[0][0] + Board[1][1] + Board[2][2]) == -3)
return -1;
if( (Board[0][0] + Board[1][1] + Board[2][2]) == 3)
return 1;
if( (Board[0][2] + Board[1][1] + Board[2][0]) == -3)
return -1;
if( (Board[0][2] + Board[1][1] + Board[2][0]) == 3)
return 1;
return 0;
}
public boolean fullBoard(){
for(int line=0 ; line<3 ; line++)
for(int column=0 ; column<3 ; column++)
if( Board[line][column]==0 )
return false;
return true;
}
}
-->Game.java
import java.util.Scanner;
public class Game {
private Board board;
private int turn=1, who=1;
private Player player1;
private Player player2;
public Scanner input = new Scanner(System.in);
public Game(){
board = new Board();
startPlayers();
while( Play() );
}
public void startPlayers(){
System.out.println("Who will be player1 ?");
if(choosePlayer() == 1)
this.player1 = new Human(1);
else
this.player1 = new Computer(1);
System.out.println("----------------------");
System.out.println("Who will be Player 2 ?");
if(choosePlayer() == 1)
this.player2 = new Human(2);
else
this.player2 = new Computer(2);
}
public int choosePlayer(){
int option=0;
do{
System.out.println("1. Human");
System.out.println("2. Computer\n");
System.out.print("Option: ");
option = input.nextInt();
if(option != 1 && option != 2)
System.out.println("Invalid Option! Try again");
}while(option != 1 && option != 2);
return option;
}
public boolean Play(){
board.showBoard();
if(won() == 0 ){
System.out.println("----------------------");
System.out.println("\nTurn "+turn);
System.out.println("It's turn of Player " + who() );
if(who()==1)
player1.play(board);
else
player2.play(board);
if(board.fullBoard()){
System.out.println("Full Board. Draw!");
return false;
}
who++;
turn++;
return true;
} else{
if(won() == -1 )
System.out.println("Player 1 won!");
else
System.out.println("Player 2 won!");
return false;
}
}
public int who(){
if(who%2 == 1)
return 1;
else
return 2;
}
public int won(){
if(board.checkLines() == 1)
return 1;
if(board.checkColumns() == 1)
return 1;
if(board.checkDiagonals() == 1)
return 1;
if(board.checkLines() == -1)
return -1;
if(board.checkColumns() == -1)
return -1;
if(board.checkDiagonals() == -1)
return -1;
return 0;
}
}
-->Player.java
public abstract class Player {
protected int[] attempt = new int[2];
protected int player;
public Player(int player){
this.player = player;
}
public abstract void play(Board board);
public abstract void Try(Board board);
public boolean checkTry(int[] attempt, Board board){
if(board.getPosition(attempt) == 0)
return true;
else
return false;
}
}
-->Human.java
import java.util.Scanner;
public class Human extends Player{
public Scanner input = new Scanner(System.in);
public Human(int player){
super(player);
this.player = player;
System.out.println("Player 'Human' created!");
}
@Override
public void play(Board board){
Try(board);
board.setPosition(attempt, player);
}
@Override
public void Try(Board board){
do{
do{
System.out.print("Line: ");
attempt[0] = input.nextInt();
if( attempt[0] > 3 ||attempt[0] < 1)
System.out.println("Invalid line. It's 1, 2 or 3");
}while( attempt[0] > 3 ||attempt[0] < 1);
do{
System.out.print("Column: ");
attempt[1] = input.nextInt();
if(attempt[1] > 3 ||attempt[1] < 1)
System.out.println("Invalid column. É 1, 2 or 3");
}while(attempt[1] > 3 ||attempt[1] < 1);
attempt[0]--;
attempt[1]--;
if(!checkTry(attempt, board))
System.out.println("Placed already marked. Try other.");
}while( !checkTry(attempt, board) );
}
}
-->Computer.java
public class Computer extends Player{
public Computer(int player){
super(player);
System.out.println("Player 'Computer' created");
}
@Override
public void play(Board board){
}
@Override
public void Try(Board board){
}
}
I need screenshots for this solution done in Flowgorithm. Thank you. Tic-Tac-Toe Game Design a program...
18. Tic-Tac-Toe Game rite a program that allows two players to play a game of tic-tac-toe. Use dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Write . Displays the contents of the board array. . Allows player 1 to select a location on the board for an X. The program should ask the...
Using C Programming: (use printf, scanf)
18. Tic-Tac-Toc Game Write a program that allows two players to play a game of tic-tac-toc. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that Displays the contents of the board array Allows player 1 to select a location on the board for an X. The program should...
Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two-dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Displays the contents of the board array. Allows player 1 to select a location on the board for an X. The program should ask the user to enter...
Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I will not be able to use those). Please ALSO create a flowchart using Flowgarithm program. Thank you so much, if answer is provided in Pseudocode and Flowchart, I will provide good feedback and thumbs up to the resonder. Thank you! Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two- dimensional char array with three rows...
Tic-Tac-Toe (arrays and multidimensional arrays) C++ Write an interactive program that plays tic-tac-toe. Represent the board as a 3 X 3 character array. Initialize the array to blanks and ask each player in turn to input a position. The first player's position is marked on the board with a O and the second player's position is marked with an X. Continue the process until a player wins or the game is a draw. To win, a player must have 3...
Use Java language to create this program Write a program that allows two players to play a game of tic-tac-toe. Using a two-dimensional array with three rows and three columns as the game board. Each element of the array should be initialized with a number from 1 - 9 (like below): 1 2 3 4 5 6 7 8 9 The program should run a loop that Displays the contents of the board array allows player 1 to select the...
Write a program to Simulate a game of tic tac toe. A game of tic tac toe has two players. A Player class is required to store /represent information about each player. The UML diagram is given below.Player-name: string-symbol :charPlayer (name:string,symbol:char)getName():stringgetSymbol():chargetInfo():string The tic tac toe board will be represented by a two dimensional array of size 3 by 3 characters. At the start of the game each cell is empty (must be set to the underscore character ‘_’). Program flow:1) ...
Objective: To write a program to allow a game of Tic Tac Toe to be played, and to determine when the game is over Complete the TicTacToe program below. It will allow for a full game of Tic Tac Toe between two players, and it will tell you who won or if the game is over with no winner. Details: The TicTacToe board is stored in a 3x3 multidimensional list of characters containing spaces at the start of the game...
(Game: play a tic-tac-toe game) In a game of tic-tac-toe, two players take turns marking an available cell in a grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A draw (no winner) occurs when all the cells in the grid have been filled with tokens and neither player has achieved a win. Create...
(Tic-Tac-Toe) Create a class Tic-Tac-Toe that will enable you to write a program to play Tic-Tac-Toe. The class contains a private 3-by-3 two-dimensional array. Use an enumeration to represent the value in each cell of the array. The enumeration’s constants should be named X, O and EMPTY (for a position that does not contain an X or an O). The constructor should initialize the board elements to EMPTY. Allow two human players. Wherever the first player moves, place an X...