Question

Tic Tac Toe Game: Help, please. Design and implement a console based Tic Tac Toe game....

Tic Tac Toe Game: Help, please.

Design and implement a console based Tic Tac Toe game. The objective of this project is to demonstrate your understanding of various programming concepts including Object Oriented Programming (OOP) and design.

Tic Tac Toe is a two player game. In your implementation one opponent will be a human player and the other a computer player.

? The game is played on a 3 x 3 game board.

? The first player is known as X and the second is O.

? X always goes first.

? Players alternate placing Xs and Os on the game board.

? Winning: ? The opponent that gets 3 of their assigned symbol in a row (horizontal, vertical or diagonal) wins!

? Draw: ?If no one has 3 in a row and all nine squares are filled no one wins, the game is a draw

You will need to design your program using OOP design, meaning you must use classes, interfaces etc as needed to implement your program. This section describes some required functionality to get you started. Some code is given to get you started, note you can change this code to fit your needs. You can create more than the listed classes etc below if needed. Implement A Game Board

? Must represent a 3 x 3 game board. ? Hint: ?Use two dimensional array. ? The data type used is up to you (examples: String, Char or a custom class that represents a cell).

? Must include methods? that implement the following functionality: ? Build the initial game board, this will create a game board with empty cells.

Example:

| |

-----------

| X |

-----------

| |

? Prints the current board that represents current board / game state. ? Checks board and returns a list of current, valid moves.

? A valid move is an empty space on the board. Players can only place their symbol in an empty cell.

? Hint:? A move is simply represented by a two values, row and column. These are the indices for the space on the game board (two dimensional array). ? Applies a player’s move to the board. ? Getter and setter methods for any instance variables you need to expose to other classes to use.

GameState (Enum)

? Enumeration that represents game state. This code is given. IllegalMoveException

? Create this exception class, it should extend the Exception class. The constructor should take a String message. The message given will describe the move that was illegal. Implement A “Rules Engine”

? Must include methods? that implement the following functionality: ? Method that checks for draw game state. ? Method that checks for winning game state (diagonals, rows and columns). ? Method that checks if a proposed move (i.e. row,column pair) by a player is a valid move.

? Hint:? Get list of valid moves from board class, then check the move against the list.

? If the move is invalid, raise an IllegalMoveException. The caller should catch and handle this exception, returning appropriate message to the user

ComputerPlayer

? File is given, but you must fill in the parts where it says “Your Code Goes Here”

? Some code such as the method to implement generating a valid move for the computer player is implemented for you.

? When the computer wins, it should display a taunting catch phrase. ? Create a method that randomly selects from a list of custom catch phrases (Strings), and returns the selected phrase. Implement A Game Class

? This is the driver class for your game.

****************************************************************

public class ComputerPlayer

{

private int[][] preferredMoves = {

{1, 1}, {0, 0}, {0, 2}, {2, 0}, {2, 2},

{0, 1}, {1, 0}, {1, 2}, {2, 1}};

private Board board;

//----- YOUR CODE GOES HERE:

// ADDED INSTANCE VARIABLE THAT STORES THE GAME SYMBOL ASSIGNED TO THE COMPUTER PLAYER

/** Constructor with reference to game board */

public ComputerPlayer(Board board)

{

this.board = board;

}

//----- YOUR CODE GOES HERE:

// ADD A SETTTER METHOD FOR THE INSTANCE VARIABLE THAT

// STORES THE GAME SYMBOL ASSIGNED TO THE COMPUTER PLAYER

/** Search for the first empty cell, according to the preferences

* @return int array of two values [row, col]

*/

public int[] generateMove()

{

for (int[] move : preferredMoves)

{

// checks for empty space on board

// (i.e. checks if this "move" is available, if the space is empty its available)

if (this.board[move[0]][move[1]] == " ")

{

return move;

}

}

return null;

}

}

****************************************************

public enum GameState
{
PLAYING, DRAW, X_WON, O_WON
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

all tane sfart Game( 1 ingeret jave cety, Scannere elegs tame wanor Conclctions connor-red) conn eftCon2 3col inful.neytInt()冫 ase elge て(bea to mohartn Pelçe ran patseskm.ese penin (Thene es ast coluad

Add a comment
Know the answer?
Add Answer to:
Tic Tac Toe Game: Help, please. Design and implement a console based Tic Tac Toe game....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In traditional Tic Tac Toe game, two players take turns to mark grids with noughts and...

    In traditional Tic Tac Toe game, two players take turns to mark grids with noughts and crosses on the 3 x 3 game board. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row in the game board wins the game. Super Tic Tac Toe game also has a 3 x 3 game board with super grid. Each super grid itself is a traditional Tic Tac Toe board. Winning a game of Tic...

  • In a game of Tic Tac Toe, two players take turns making an available cell in...

    In a game of Tic Tac Toe, two players take turns making an available cell in a 3 x 3 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 stalemate occurs when all the cells on the grid have been filled with tokens and neither player has achieved a win. Write a program...

  • Write a program to Simulate a game of tic tac toe in c#

    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)    ...

  • Implement a tic-tac-toe game. At the bottom of these specifications you will see a template you...

    Implement a tic-tac-toe game. At the bottom of these specifications you will see a template you must copy and paste to cloud9. Do not change the provided complete functions, or the function stub headers / return values. Currently, if the variables provided in main are commented out, the program will compile. Complete the specifications for each function. As you develop the program, implement one function at a time, and test that function. The provided comments provide hints as to what...

  • (Tic-Tac-Toe) Create a class Tic-Tac-Toe that will enable you to write a program to play Tic-Tac-Toe....

    (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...

  • In a game of Tic Tac Toe, two players take turns making an available cell in...

    In a game of Tic Tac Toe, two players take turns making an available cell in a 3 x 3 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 stalemate occurs when all the cells on the grid have been filled with tokens and neither player has achieved a win. Write a program...

  • You will create a PYTHON program for Tic-Tac-Toe game. Tic-Tac-Toe is normally played with two people....

    You will create a PYTHON program for Tic-Tac-Toe game. Tic-Tac-Toe is normally played with two people. One player is X and the other player is O. Players take turns placing their X or O. If a player gets three of his/her marks on the board in a row, column, or diagonal, he/she wins. When the board fills up with neither player winning, the game ends in a draw 1) Player 1 VS Player 2: Two players are playing the game...

  • 18. Tic-Tac-Toe Game rite a program that allows two players to play a game of tic-tac-toe. Use di...

    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...

  • (Game: play a tic-tac-toe game) In a game of tic-tac-toe, two players take turns marking an...

    (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...

  • I need screenshots for this solution done in Flowgorithm. Thank you. Tic-Tac-Toe Game Design a program...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT