THE COMPLETE C++ CODING FOR A SIMPLE BUT UNIQUE AND CUTE 'TIC TAC TOE' COMPUTER' GAME by sirjon

      IT seems to be, not that easy to create a video presentation of this type of  C++  Do-It-Yourself project in one go. Especially, if you wish to explain some important details for non-techie and beginners out there - for them to fully understand the world of computer programming. 

     I decided to share the complete package of this simple but unique and cute 'tic tac toe' computer game  for people out there who interested on how I did it.
     Please, as a token of appreciation - like , subscribe and share my youtube version of this game....

(The game's design looks like this)


 (Instruction: Type a number from 1 to 9 only... Then hit the ENTER key)

                             ***If you WISH TO END THE GAME...just enter the number 500

   WARNING TO PLAYERS: Be careful in entering numbers or you might lose your turn as penalty

    LET'S PLAY!!!

               PLAYER A (X)

               PLAYER B (O)

                                                  * * *    |1 2 3|
                                                  * * *    |4 5 6|
                                                  * * *    |7 8 9|           
______________________________________________________________________________

#include <iostream>
using namespace std;
int main()
{
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                             A C++ TIC TAC TOE GAME"<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                        (Instruction: Type a number from 1 to 9 only... Then hit the ENTER key)"<<"\n";
  cout<<"                        ***If you WISH TO END THE GAME...just enter the number 500"<<"\n";
  cout<<"                  WARNING TO PLAYERS: Be careful in entering numbers or you might lose your turn as penalty"<<"\n";
  cout<<"\n";
  cout<<"                           LET'S PLAY!!!"<<"\n";
  cout<<"\n";
  cout<<"                           PLAYER A (X)"<<"\n";
  cout<<"                           PLAYER B (O)"<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  
  char a ='*';
  char b ='*'; 
  char c ='*'; 
  char d ='*'; 
  char e ='*'; 
  char f ='*'; 
  char g ='*'; 
  char h ='*'; 
  char i ='*';
  int cell = 0;
  int CNum[9] = {1,2,3,4,5,6,7,8,9};
  int N = 0; 
  int cycle= N;
  
  while(cycle<500)
  {
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                   PLAYER 'A' READY... "<<"\n";
          
  cout<<"\n"; 
  cout<<"                                       CELL:";
  cin>>cell;
  cycle=cell;
  N++;
  if(cell==500)
  {N=N+500;}
  
  if(cell==CNum[0])
    { if(a=='O')
        {a='O';
          N--;
          cout<<"Sorry you lose your turn"<<"\n";}
    else{a='X';}
    }
  if(cell==CNum[1])
    { if(b=='O')
        {b='O';
          N--;
          cout<<"Sorry you lose your turn"<<"\n";}
    else{b='X';}
    }
  if(cell==CNum[2])
    { if(c=='O')
        {c='O';
           N--;
           cout<<"Sorry you lose your turn"<<"\n";}
    else{c='X';}
    }
  if(cell==CNum[3])
    { if(d=='O')
        {d='O';
          N--;
          cout<<"Sorry you lose your turn"<<"\n";
            
        }
    else{d='X';}
    }
  if(cell==CNum[4])
    { if(e=='O')
        {e='O';
           N--;
           cout<<"Sorry you lose your turn"<<"\n";}
    else{e='X';}
    }
  if(cell==CNum[5])
    { if(f=='O')
        {f='O';
            N--;
            cout<<"Sorry you lose your turn"<<"\n";}
    else{f='X';}
    }
  if(cell==CNum[6])
    { if(g=='O')
        {g='O';
         N--;
            cout<<"Sorry you lose your turn"<<"\n";}
    else{g='X';}
    }
  if(cell==CNum[7])
    { if(h=='O')
        {h='O';
            N--;
            cout<<"Sorry you lose your turn"<<"\n";}
    else{h='X';}
    }
  if(cell==CNum[8])
   { if(i=='O')
       {i='O';
            N--;
            cout<<"Sorry you lose your turn"<<"\n";}
   else{i='X';}
    } 
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                "<<a<<" "<<b<<" "<<c<<"    |1 2 3|"<<"\n";
  cout<<"                                                "<<d<<" "<<e<<" "<<f<<"    |4 5 6|"<<"\n";
  cout<<"                                                "<<g<<" "<<h<<" "<<i<<"    |7 8 9|"<<"\n";
  cout<<"\n";
  if(a=='X')
    {if(b=='X')
      {if(c=='X')
       {cout<<"                                                PLAYER 'A' WINS"<<"\n";
                                                 N=0;
                                                 cycle=cell;
                                                 a ='*';
                                                 b ='*'; 
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*';
                                                  
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  
                                                 
       } } 
    }
  if(d=='X')
    {if(e=='X')
      {if(f=='X')
       {cout<<"                                                PLAYER 'A' WINS"<<"\n"; 
                                                 N=0;
                                                 a ='*';
                                                 b ='*';
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*'; cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  
                                                 
       
                                                 
     
       } 
      } 
        
    }
  if(g=='X')
    {if(h=='X')
      {if(i=='X')
       {cout<<"                                                PLAYER 'A' WINS"<<"\n"; 
                                                  N=0;
                                                 a ='*';
                                                 b ='*';
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*';
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
   
      } 
      }
    }
    if(a=='X')
    {if(d=='X')
      {if(g=='X')
       {cout<<"                                                PLAYER 'A' WINS"<<"\n"; 
                                                  N=0;
                                                 a ='*';
                                                 b ='*';
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*'; 
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  
       
       } 
      }
    }
   if(b=='X')
    {if(e=='X')
      {if(h=='X')
       {cout<<"                                                PLAYER 'A' WINS"<<"\n";
                                                 N=0;
                                                 a ='*';
                                                 b ='*';
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*'; 
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  
      } 
      }
    } 
    if(c=='X')
    {if(f=='X')
      {if(i=='X')
       {cout<<"                                                PLAYER 'A' WINS"<<"\n";
                                                  N=0;
                                                 a ='*';
                                                 b ='*';
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*';
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
    
           
       } 
      }
    } 
    if(a=='X')
    {if(e=='X')
      {if(i=='X')
       {cout<<"                                                PLAYER 'A' WINS"<<"\n"; 
                                                  N=0;
                                                 a ='*';
                                                 b ='*';
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*'; 
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  
           
       } 
      }
    } 
    if(c=='X')
    {if(e=='X')
      {if(g=='X')
       {cout<<"                                                PLAYER 'A' WINS"<<"\n";
                                                  N=0;
                                                 a ='*';
                                                 b ='*';
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*';
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  
        } 
      }
    } 
   if(N==9)
     {N=0;
     a ='*';
     b ='*'; 
     c ='*'; 
     d ='*'; 
     e ='*'; 
     f ='*'; 
     g ='*'; 
     h ='*'; 
     i ='*';
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  
     }
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  if(cell==500)
  {cycle=N+500;}
  cout<<"                                   PLAYER 'B' READY... "<<"\n";
  cout<<"\n";
  cout<<"                                       CELL:";
 cin>>cell;
  if(cell==500)
  {cycle=N+500;}
  N++;
 if(cell==CNum[0])
    { if(a=='X')
        {a='X';
            N--;
            cout<<"Sorry you lose your turn"<<"\n";
        }
    else{a='O';}
    }
  if(cell==CNum[1])
    { if(b=='X')
        {b='X';
            N--;
            cout<<"Sorry you lose your turn"<<"\n";}
    else{b='O';}
    }
  if(cell==CNum[2])
    { if(c=='X')
        {c='X';
             N--;
            cout<<"Sorry you lose your turn"<<"\n";}
    else{c='O';}
    }
  if(cell==CNum[3])
    { if(d=='X')
        {d='X';
            N--;
            cout<<"Sorry you lose your turn"<<"\n";
        
        }
    else{d='O';}
    }
  if(cell==CNum[4])
    { if(e=='X')
        {e='X';
            N--;
            cout<<"Sorry you lose your turn"<<"\n";}
    else{e='O';}
    }
  if(cell==CNum[5])
    { if(f=='X')
        {f='X';
            N--;
            cout<<"Sorry you lose your turn"<<"\n";}
    else{f='O';}
    }
  if(cell==CNum[6])
    { if(g=='X')
        {g='X';
            N--;
            cout<<"Sorry you lose your turn"<<"\n";}
    else{g='O';}
    }
  if(cell==CNum[7])
    { if(h=='X')
        {h='X';
            N--;
            cout<<"Sorry you lose your turn"<<"\n";}
    else{h='O';}
    }
  if(cell==CNum[8])
   { if(i=='X')
       {i='X';
            N--;
            cout<<"Sorry you lose your turn"<<"\n";}
   else{i='O';}
    } 
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                "<<a<<" "<<b<<" "<<c<<"    |1 2 3|"<<"\n";
  cout<<"                                                "<<d<<" "<<e<<" "<<f<<"    |4 5 6|"<<"\n";
  cout<<"                                                "<<g<<" "<<h<<" "<<i<<"    |7 8 9|"<<"\n";
  cout<<"\n";
  if(a=='O')
    {if(b=='O')
      {if(c=='O')
       {cout<<"                                                PLAYER 'B' WINS"<<"\n"; 
                                                 N=0;
                                                 cycle=cell;
                                                 a ='*';
                                                 b ='*'; 
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*';
                                                  
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  
       } 
      }
    }
  if(d=='O')
    {if(e=='O')
      {if(f=='O')
       {cout<<"                                                PLAYER 'B' WINS"<<"\n";
                                                 N=0;
                                                 cycle=cell;
                                                 a ='*';
                                                 b ='*'; 
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*';
                                                  
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
         } 
      } 
        
    }
  if(g=='O')
    {if(h=='O')
      {if(i=='O')
       {cout<<"                                                PLAYER 'B' WINS"<<"\n"; 
                                                 N=0;
                                                 cycle=cell;
                                                 a ='*';
                                                 b ='*'; 
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*';
                                                  
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  
       } 
      }
    }
    if(a=='O')
    {if(d=='O')
      {if(g=='O')
       {cout<<"                                                PLAYER 'B' WINS"<<"\n";
                                                 N=0;
                                                 cycle=cell;
                                                 a ='*';
                                                 b ='*'; 
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*';
                                                  
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  } 
      }
    }
   if(b=='O')
    {if(e=='O')
      {if(h=='O')
       {cout<<"                                                PLAYER 'B' WINS"<<"\n";
                                                 N=0;
                                                 cycle=cell;
                                                 a ='*';
                                                 b ='*'; 
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*';
                                                  
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  } 
      }
    } 
    if(c=='O')
    {if(f=='O')
      {if(i=='O')
       {cout<<"                                                PLAYER 'B' WINS"<<"\n";
                                                 N=0;
                                                 cycle=cell;
                                                 a ='*';
                                                 b ='*'; 
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*';
                                                  
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
  } 
      }
    } 
    if(a=='O')
    {if(e=='O')
      {if(i=='O')
       {cout<<"                                                PLAYER 'B' WINS"<<"\n";
                                                    N=0;
                                                 cycle=cell;
                                                 a ='*';
                                                 b ='*'; 
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*';
                                                  
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
      } 
      }
    } 
    if(c=='O')
    {if(e=='O')
      {if(g=='O')
       {cout<<"                                                PLAYER 'B' WINS"<<"\n";
                                                    N=0;
                                                 cycle=cell;
                                                 a ='*';
                                                 b ='*'; 
                                                 c ='*'; 
                                                 d ='*'; 
                                                 e ='*'; 
                                                 f ='*'; 
                                                 g ='*'; 
                                                 h ='*'; 
                                                 i ='*';
                                                  
  cout<<"\n";
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
      } 
      }
    } 

  if(N==9)
     {N=0;
     a ='*';
     b ='*'; 
     c ='*'; 
     d ='*'; 
     e ='*'; 
     f ='*'; 
     g ='*'; 
     h ='*'; 
     i ='*';
  cout<<"\n";
  cout<<"\n";
  cout<<"                                                * * *    |1 2 3|"<<"\n";
  cout<<"                                                * * *    |4 5 6|"<<"\n"; 
  cout<<"                                                * * *    |7 8 9|"<<"\n";
       
     }     
  }
 cout<<"\n"; 
 cout<<"      == THANK YOU FOR PLAYING THIS GAME ==";

   return 0;
}

______________________________________________________________________

    The coding is just the duplication of the similar codes and the best way to achieve success is to do what codes you modified for player A and apply for player B. 
     The secret is knowing how to 'copy and paste'

This game is 'designed' for two people. Sit side-by-side in front of the computer and enjoy the game!





     







Comments

Popular posts from this blog

C++ SOURCE CODE FOR SIRJON'S "MICRO" TIC TAC TOE GAME FOR FUN!

ENTER CORRECT PASSWORD, THREE ATTEMPTS ONLY USING C++ WHILE-IF COMBINATION

C++ SOURCE CODE FOR SIRJON'S "MICRO" TIC TAC TOE GAME FOR LAPTOPS