#include ; using namespace std; void drawBoard(); char box1 = '7'; char box2 = '8'; char box3 = '9'; char box4 = '4'; char box5 = '5'; char box6 = '6'; char box7 = '1'; char box8 = '2'; char box9 = '3'; char player1Move = '0'; int playerNum = 0; bool turnOver = false; void interpretInput(int player); void playerTurn1(); bool gameOver = false; void gameOverCheck(); void drawFinalBoard(); void playerTurn2(); void ticTacToe(); void main(){ ticTacToe(); system("PAUSE"); } void ticTacToe(){ cout << "LET'S PLAY TICTACTOE MOTHERFUCKER!! " << endl << endl; cout << endl << box1 << " | " << box2 << " | " << box3 << endl; cout << "---"<< "---"<< "---" << endl; cout << box4 << " | " << box5 << " | " << box6 << endl; cout << "---"<< "---"<< "---" << endl; cout << box7 << " | " << box8 << " | " << box9 << endl << endl; cout << "Press 'enter' to begin the game."; //will just pause the program for waiting for the player to begin cin.get(); //starts the game loop until a winner is found playerTurn1(); } //draws the current board on screen void drawBoard(){ system("CLS"); cout << "It is player " << playerNum << "'s turn now: "<< endl << endl; cout << endl << box1 << " | " << box2 << " | " << box3 << endl; cout << "---"<< "---"<< "---" << endl; cout << box4 << " | " << box5 << " | " << box6 << endl; cout << "---"<< "---"<< "---" << endl; cout << box7 << " | " << box8 << " | " << box9 << endl << endl; } void drawFinalBoard(){ cout << endl << box1 << " | " << box2 << " | " << box3 << endl; cout << "---"<< "---"<< "---" << endl; cout << box4 << " | " << box5 << " | " << box6 << endl; cout << "---"<< "---"<< "---" << endl; cout << box7 << " | " << box8 << " | " << box9 << endl << endl; } //reads the input and changes the box if it hasn't been selected before void interpretInput(int player){ if(player == 1){cout << endl << "Player is " << player << endl; //player 1 input check and select switch(player1Move){ case '0': cout << "Please make a move!"; interpretInput(player); break; case '1': box7 = (box7 == '1') ? 'X': box7; break; case '2': box8 = (box8 == '2') ? 'X': box8; drawBoard(); break; case '3': box9 = (box9 == '3') ? 'X': box9; drawBoard(); break; case '4': box4 = (box4 == '4') ? 'X': box4; drawBoard(); break; case '5': box5 = (box5 == '5') ? 'X': box5; drawBoard(); break; case '6': box6 = (box6 == '6') ? 'X': box6; drawBoard(); break; case '7': box1 = (box1 == '7') ? 'X': box1; drawBoard(); break; case '8': box2 = (box2 == '8') ? 'X': box2; drawBoard(); break; case '9': box3 = (box3 == '9') ? 'X': box3; drawBoard(); break; default: cout << endl << "Try again!!" << endl; system("PAUSE"); playerTurn1(); }} else{cout << endl << "Player is " << player << endl; //player 2 input check and select switch(player1Move){ case '0': cout << "Please make a move!"; interpretInput(player); break; case '1': box7 = (box7 == '1') ? 'O': box7; drawBoard(); break; case '2': box8 = (box8 == '2') ? 'O': box8; drawBoard(); break; case '3': box9 = (box9 == '3') ? 'O': box9; drawBoard(); break; case '4': box4 = (box4 == '4') ? 'O': box4; drawBoard(); break; case '5': box5 = (box5 == '5') ? 'O': box5; drawBoard(); break; case '6': box6 = (box6 == '6') ? 'O': box6; drawBoard(); break; case '7': box1 = (box1 == '7') ? 'O': box1; drawBoard(); break; case '8': box2 = (box2 == '8') ? 'O': box2; drawBoard(); break; case '9': box3 = (box3 == '9') ? 'O': box3; drawBoard(); break; default: cout << endl << "Try again!!" << endl; system("PAUSE"); playerTurn2(); }} } //cycles between player turns void playerTurn1(){ do{ playerNum = 1; drawBoard(); cin >> player1Move; interpretInput(playerNum); gameOverCheck(); turnOver = true; }while(gameOver != true && turnOver != true); turnOver = false; playerTurn2(); } void playerTurn2(){ do{ playerNum = 2; drawBoard(); cin >> player1Move; interpretInput(playerNum); gameOverCheck(); turnOver = true; }while(gameOver != true && turnOver != true); turnOver = false; playerTurn1(); } //checks if the game is over and quits the game if it is...and if not...will not do anything void gameOverCheck(){ if((box1==box2) && (box1==box3) || (box3==box6) && (box3==box9) || (box7==box8) && (box7==box9) || (box1==box4) && (box1==box7) || (box2==box5) && (box2==box8) || (box4==box5) && (box4==box6) || (box1==box5) && (box1==box9) || (box3==box5) && (box3==box7)){ system("CLS"); cout << endl << "!!!!!!!!!!!!!!!!! GAMEOVER !!!!!!!!!!!!!!!!!!!"; gameOver = true; cout << endl << "---------------Player " << playerNum << " won!!!!---------------"<< endl << endl; drawFinalBoard(); system("PAUSE"); exit(EXIT_FAILURE); } else if(box1 != '7' && box2 != '8' && box3 != '9' && box4 != '4' && box5 != '5' && box6 != '6' && box7 != '1' && box8 != '2' && box9 != '3'){ cout << "!!!!!!!!!!!!!!!! THE GAME WAS A DRAW !!!!!!!!!!!!!!!!" << endl; system("PAUSE"); exit(EXIT_FAILURE); } else {gameOver = false;} }