Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 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