Lab #2 Solution

$30.00

Category:

Description

Tic Tac Toe

 

For this lab, you will de ne the essential methods of the class TicTacToe so that you can play Tic-Tac-Toe which is implemented by using an array as the board that consists of nine (9) elements. The indices association with the positions on the board are:

0 1 2
3 4 5
6 7 8

 

Your group will have to rewrite the given method so that they perform their descriptions correctly.

 

A public default constructor. It assigns – (blank) to each element of board and assigns 1 to player. [Initialization.h] A public copy constructors. It copies the elds of a TicTacToe object. [Copy.h]

 

A public overloaded assignment operator. It copies the  elds of a TicTacToe object. [Assignment.h]

 

A public boolean constant method named verticalWinner() that takes no parameters. It returns true if any vertical line consists of the same non-blank character; otherwise, it returns false. [VerticalWinner.h]

 

A public boolean constant method named horizontalWinner() that takes no parameters. It returns true if any horizontal line consists of the same non-blank character; otherwise, it returns false. [HorizontalWinner.h]

 

A public boolean constant method named diagonalWinner() that takes no parameters. It returns true if any diagonal line consists of the same non-blank character; otherwise, it returns false. [DiagonalWinner.h]

 

A public boolean constant method named winner() that takes no parameters. It returns true if any vertical, horizontal, or diagonal line consists of the same non-blank character; otherwise, it returns false. [Winner.h]

 

A public boolean constant method named hasMove() that takes no parameters. It returns true if any element of board is equal to the blank character; otherwise, it returns false. [HasMove.h]

 

A public boolean method named makeMove() that takes an int named position as a parameter. If the element of board associated with position is a blank character, it is assigned the token associated with the currrent player, and the function returns true. Otherwise, the function returns false. Positions from top-left to bottom-right are 1 through 9. [MakeMove.h]

 

A public void method named switchPlayer() that takes no parameters. It switchs player to the next player. Tic-Tac-Toe only has two players. [SwitchPlayer.h]

 

A public boolean constant method named canPlay() that takes no parameters. It returns true if there is no winner and there are blank spaces on the board. [CanPlay.h]

 

A public boolean constant method named ToString() that takes no parameters. It returns a string that displays the current player preceed by the label \Player “, and then two spaces below, the values of the elements of board in the same formats and order as the image above with a newline after the image. [ToString.h]


error: Content is protected !!