1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
//3T, or TicTacToe by Jay.
#include <iostream>
#include <string>
//Libraries
using namespace std;
/*****************************************************************/
//Function Declaration
/*****************************************************************/
void welcomeMessage();
//welcomeMessage() ---> Displays welcoming message
void insText();
//insText() ---> Instructions
void endSpace();
//endSpace() ---> Spaces (endl, endl, endl || \n, \n, \n)
void tttBoard();
//tttBoard() ---> Tic Tac Toe Board in the beginning
int playTurn(int);
//playTurn() ---> The Turn, whether it's P1's or P2's.
/**********************************************/
char bSquare[] = {'1','2','3','4','5','6','7','8','9'};
//Bad Programming, as variables shouldn't be declared out of function.
//Only const _____ should be on global declaration.
//Made for simplicity, as parameters are confusing, apologies to whoever is reading this.
/**********************************************/
//Main Function
int main() {
int i; //i is the variable for the loop
//also used in the turn count;
welcomeMessage(); //Function welcomeMessage, which displays welcoming message.
//It also includes a system("PAUSE"); that pauses the system temporarily.
i=0;
do {
/****************************************************************/
endSpace(); //Function endSpace--->Blank Lines
/***************************************************************/
insText(); //Function insText--->Instructions
//Right before the board, NO PAUSES
tttBoard(); //Function tttBoard displays the TicTacToe's 3 x 3 board.
//Numbers are marked for each square
} while(i<9);
system ("PAUSE");
return 0;
//returns the value 0, otherwise ends the program.
}
/******************************************************************/
//Function Description********************************************/
/*****************************************************************/
//Function: welcomeMessage ---> Displaying welcoming message & a pause.
void welcomeMessage(){
cout << "Hello~! Welcome to 3T, or \"TicTacToe\" This is a 2 player game on a 3 x 3 board. \n";
//The Welcoming Message is stated*************************************\n ends the line, same as endl
system("PAUSE"); //Displays "Press any key to continue"
//Temporarily pauses the program.
}
//Function: tttBoard ---> Displays the Tic Tac Toe 3 x 3 board.
void tttBoard(){
//TicTacToe Board is below
cout << "_" << bSquare[0] << "_|_" << bSquare[1] << "_|_" << bSquare[2] << "_" << endl; //endl is used instead of \n because of "beautiful code"
//First line of Table^
cout << "_" << bSquare[3] << "_|_" << bSquare[4] << "_|_" << bSquare[5] << "_" << endl; //endl is used instead of \n because of "beautiful code"
//Second line of Table^
cout << "_" << bSquare[6] << "_|_" << bSquare[7] << "_|_" << bSquare[8] << "_" << endl; //endl is used instead of \n because of "beautiful code"
//Third line of Table^
//***IMPORTANT***//
//bSquare[x]=x+1;
}
//Function endSpace ---> Just blankspaces for clearance.
void endSpace(){
cout << "\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n";
//Numerous empty lines.
}
//Function: insText ---> Displays instructions for the users
void insText(){
cout << "Player 1 is \"O\" and Player 2 is \"X.\" ";
playTurn();
cout << " Input \na number that's labeled in the square. \n";
//Gives a brief introduction to how the game works. Numbers ---> Squares.
}
//Function: playTurn ---> Calculates who's turn it is
int playTurn(int x){
if (x==0 || x==2 || x==4 || x==8){ //This checks if it's Player 1's turn
cout << "It's Player 1's turn." << endl; //Displays that it's Player 1's turn.
}//Ending brace of the if statement in playTurn();
else { //The rest is automatically Player 2's, as the user cannot make a change to this variable as an input.
cout << "It's Player 2's turn." << endl; //Displays who's turn it is
}//Ending brace of the else statement in playTurn();
return 0;
}
|