0% found this document useful (0 votes)
61 views1 page

Test

This C++ code defines a TicTacToe game class and uses it to create a console-based TicTacToe game. It includes header files for input/output and the TicTacToe class. The main function creates a TicTacToe object, displays instructions, and uses a while loop to repeatedly draw the board, get user input, check for a win, toggle players, and break if there is a win. It displays which player won when the loop exits.

Uploaded by

api-346895508
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views1 page

Test

This C++ code defines a TicTacToe game class and uses it to create a console-based TicTacToe game. It includes header files for input/output and the TicTacToe class. The main function creates a TicTacToe object, displays instructions, and uses a while loop to repeatedly draw the board, get user input, check for a win, toggle players, and break if there is a win. It displays which player won when the loop exits.

Uploaded by

api-346895508
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 1

//preprocessor directives & headers.

#include <iostream> //utilized to instate basic I/O functionality.


#include <iomanip> //required to use various useful manipulators.
#include "TicTacToe.h" //includes header file which contains class with prototyped functions.

//standard library.
using namespace std; //allows the use of cout & endl without "std::" prefix.

//makes object labeled 'game' of TicTacToe Class.


TicTacToe game;

//function main.
int main()
{
//declare local variables.
int a = 0;

//Introduction to program.
cout << "Welcome to TicTacToe! If you dont know TicTacToe is a game\n"
<< "for two players, X and O, who take turns marking the spaces\n"
<< "in a 3×3 grid. The player who succeeds in placing three of their\n"
<< "marks in a horizontal, vertical, or diagonal row wins the game.\n"
<< "----------\n"
<< "TicTacToe:" << endl;

game.drawGrid(); //creates TicTacToe board.


while (1){ //While loop which loops until a 'break' is encountered
game.input(a); //prompts user for input and passes inputted variable.
game.drawGrid(); //updates TicTacToeBoard
if (game.win() == 'X'){ //if win determining function returns 'X', execute following
statements.
cout << "X wins!" << endl; //outputs parenthesized text to console
break; //exits loop
}
else if (game.win() == 'O'){ //if win determining function returns 'O', execute
following statements.
cout << "O wins!" << endl; //outputs parenthesized text to console
break; //exits loop
}
game.togglePlayer(); //Switch Player
}
cout << "-------------------------------" << endl;
return 0; //returns 0 & exits function main.
} //end of function main

You might also like