ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 12 Weeks Ago, 4 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 08 May 2017 My Price 9.00

Write a class called Board that represents a tic-tac-toe board

Write a class called Board that represents a tic-tac-toe board. It should have a 3x3 array as a data member, which will store the locations of the players' moves. It should have a default constructor that initializes the 3x3 array to being empty. It should have a method called makeMove that takes the x and y coordinates of the move (see the example below) and which player's turn it is as parameters. If that location is unoccupied, makeMove should record the move and return true. If that location is already occupied, makeMove should just return false. There should be a method called gameState that takes no parameters and returns a value indicating one of four possibilities: 'x' has won, 'o' has won, the game is a draw, or the game is still in progress - use an enum for this (the enum definition should go in Board.hpp). There should also be a method called print, which just prints out the current board to the screen. Write a class called TicTacToe that allows two people to play a game. This class will have a field for a Board object and a field to keep track of which player's turn it is. It should have a constructor that takes a char parameter that specifies whether 'x' or 'o' should have the first move. It should have a method called play that starts the game. The play method should keep looping, asking the correct player for their move and sending it to the board (with makeMove) until someone has won or it's a draw (as indicated by gameState), and then declare what the outcome was. Write a main method (in TicTacToe.cpp) that asks the user which player should go first, creates a new TicTacToe object and starts the game. Input validation: If someone tries to take an occupied square, tell them that square is already occupied and ask for a different move.

Here's an example portion of a game (already in progress):

0 1 2
0 x . .
1 . . .
2 . . .

Player O: please enter your move.

1 2

0 1 2
0 x . .
1 . . o
2 . . .

Player X: please enter your move.

1 2

That square is already taken.

0 1 2
0 x . .
1 . . o
2 . . .

Player X: please enter your move.

The files must be named: Board.hpp, Board.cpp, TicTacToe.hpp and TicTacToe.cpp

Answers

(11)
Status NEW Posted 08 May 2017 06:05 AM My Price 9.00

-----------

Not Rated(0)