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
|
// TIC TAC TOE - Second Attempt - success ;)
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void instructions();
bool doYouWantToPlayFirst(string question, char& humanPiece, char& computerPiece);
void generateEmptyBoard(vector< vector<char> >& vec, const unsigned short& x, const unsigned short& y);
void getHumanMove(int& humanMove, vector< vector<char> >& vec, const unsigned short& x, const unsigned short& y);
void getComputerMove(const int& humanMove, vector< vector<char> >& vec, const unsigned short& x, const unsigned short& y);
bool legalMoves(string& tie, vector< vector<char> >& vec, const unsigned short& x, const unsigned short& y);
bool ifHumanWinner(char& winner, vector< vector<char> >& vec, const unsigned short& x, const unsigned short& y);
bool ifComputerWinner(char& winner, vector< vector<char> >& vec, const unsigned short& x, const unsigned short& y);
void printTable(vector< vector<char> >& vec, const unsigned short& x, const unsigned short& y);
void switcher(int& var_switcher);
//global consts
const unsigned short MAX_HORI = 3;
const unsigned short MAX_VERT = 3;
//global vars
vector< vector<char> > board(MAX_VERT, MAX_HORI);
char humanPiece;
char computerPiece;
int humanMove;
int computerMove;
int var_switcher;
string occupied;
int main ()
{
//main vars
string tie;
char winner;
char doYouWantToPlayAgain;
instructions();
do {
doYouWantToPlayFirst("Do you want to be first low form of life?? beep beeep....\n.... you hear something from your computers case ..WOW whats that!?? \n\nFirst? <y/n>: ", humanPiece, computerPiece);
generateEmptyBoard(board, MAX_VERT, MAX_HORI);
// **** MAIN LOOP ****
do
{
printTable(board, MAX_VERT, MAX_HORI); // prints the table
switcher(var_switcher); // swaps the move
} while ((legalMoves(tie, board, MAX_VERT, MAX_HORI) == false) && (ifHumanWinner(winner, board, MAX_VERT, MAX_HORI) == false) && (ifComputerWinner(winner, board, MAX_VERT, MAX_HORI) == false));
// ^^^^ MAIN LOOP ^^^^
printTable(board, MAX_VERT, MAX_HORI);
if(tie == "yes") // declares TIE
{
printTable(board, MAX_VERT, MAX_HORI);
cout << "\nTIE! Oooh you are worthy opponent! Though you are still low form of live.. \nno offense! ;) \nI challenge you again!!!\n";
}
else
{
if(ifComputerWinner(winner, board, MAX_VERT, MAX_HORI) == true) // declares a win if computer wins
{
cout << "That's right and now your kind awaits full assimilation! Huhaha ...\nrobotic laughs continues...\n...I may give you one more chance.. do you want to play again?!\n";
}
if (ifHumanWinner(winner, board, MAX_VERT, MAX_HORI) == true) // declares a win if human wins
{
cout << "How was that possible!?!? ... i mean.. i know 1+1=2, or 5*5 = 25, or that the grass is green.. and i know c++ better than you for sure! :confused: ...\nI'll get revenge! BLUE SCREEN OF DEATH IS COMMING SOON!!!\n\nOr just please give me one more chance!!!... \nthough you are still low form of life DON'T FORGET that :)\n";
}
}
cout << endl;
cout << "Again? <y/n>: "; // asks if you want to play again
cin >> doYouWantToPlayAgain;
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
doYouWantToPlayAgain=toupper(doYouWantToPlayAgain);
}while((doYouWantToPlayAgain != 'N') || (doYouWantToPlayAgain == 'Y')); // asks if you want to play again while y/n is entered
return 0;
}
|