Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- using namespace std;
- char Grid[11] = "0123456789";//string get stored in the space for arrray
- void Title();
- void Board();
- void Checking123();
- int user, v;
- int main()
- {
- Title();
- Board();
- Checking123();
- system("PAUSE");
- }
- void Title()
- {
- for (int col = 1; col <= 9; col++)
- {
- cout << setw(2) << "-#";
- }
- cout << "\n" << setw(14) << "TIC TAC TOE" << endl;
- for (int col = 1; col <= 9; col++)
- {
- cout << setw(2) << "-#";
- }
- cout << "\n" << endl;
- }
- void Board()
- {
- cout << "\n ****************" << endl;
- cout << " | ";
- for (int col = 1; col <= 3; col++)
- {
- cout << setw(2) << col << " | "; //top numbers 1-3
- }
- cout << endl;
- cout << setw(16) << " |==============|";
- cout << "\n | ";
- for (int r = 4; r <= 6; r++)
- {
- cout << setw(2) << r << " | ";//middle numbers 4-6
- }
- cout << endl;
- cout << setw(16) << " |==============|";
- cout << "\n | ";
- for (int r = 7; r <= 9; r++)
- {
- cout << setw(2) << r << " | ";//bottom numbers 7-9
- }
- cout << "\n ****************" << endl;
- while (1)
- {
- cin >> user;
- srand(time(0));
- v = rand() % 9 + 1;
- Grid[v] = 'O';
- Grid[user] = 'X';
- cout << "\n ****************" << endl;
- cout << " | ";
- cout << setw(2) << Grid[1] << " | " << Grid[2] << " | " << Grid[3] << " | " << endl;
- cout << setw(16) << " |==============|";
- cout << "\n | ";
- cout << setw(2) << Grid[4] << " | " << Grid[5] << " | " << Grid[6] << " | " << endl;
- cout << setw(16) << " |==============|";
- cout << "\n | ";
- cout << setw(2) << Grid[7] << " | " << Grid[8] << " | " << Grid[9] << " | ";
- cout << "\n ****************" << endl;
- if (v == 'O'&&Grid[v] != 'X')
- {
- srand(time(0));
- v = rand() % 9 + 1;
- cout << "am i here?" << endl;
- Grid[v] = 'O';
- }
- /*
- else if (!'O' == 'X')
- {
- cin.ignore();
- //cin.get();
- cout << "ok" << endl;
- }*/
- if (user == 'X'&&Grid[user] != 'O')
- {
- Grid[user] = 'X';
- }
- else if (Grid[user] == Grid['O']|| Grid[user] == Grid[v])
- {
- cin.ignore();
- cin.get();
- cout << "TAKEN" << endl;
- }
- // cin.fail();
- cout << "1-9 only" << endl;
- }
- if (v == Grid[1] && v == Grid[2] && v == Grid[3] || v == Grid['O'] && v == Grid['O'] && v == Grid['O'] || v == Grid[7] && v == Grid[8] && v == Grid[9] || v == Grid[1] && v == Grid[5] && v == Grid[9] || v == Grid[3] && v == Grid[5] && v == Grid[7] || v == Grid[2] && v == Grid[5] && v == Grid[8])
- {
- cout << "AI WINS! " << endl;
- }
- else if (user == Grid[1] && user == Grid[2] && user == Grid[3] || user == Grid[4] && user == Grid[5] && user == Grid[6]||user == Grid[7] && user == Grid[8] && user == Grid[9]||user == Grid[1] && user == Grid[5] && user == Grid[9]||user == Grid[3] && user == Grid[5] && user == Grid[7]||user == Grid[2] && user == Grid[5] && user == Grid[8])
- {
- cout << "PLAYER WINS! " << endl;
- }
- else {
- cout << "DRAW" << endl;
- }
- }
- void Checking123()
- {
- //else
- // cout << "ITA A DRAW! " << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement