Guest User

Untitled

a guest
Jan 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class board{
  6. public:
  7.     void show();
  8.     char squares [9];
  9. };
  10.  
  11.  
  12.  
  13. void board::show(){
  14.     cout << endl;
  15.  
  16.     for ( int i = 0; i < 9; i++){
  17.         if (i % 3 == 0)
  18.             cout << "  ";
  19.         cout << squares[i];
  20.  
  21.         if ( i % 3 == 0 || i ==1 || i == 4 || i == 7)
  22.             cout << " | ";
  23.    
  24.         if (i != 0 && (i+1)%3 == 0){
  25.             cout << endl;
  26.             if ( i != 8)
  27.                 cout << "  ----------";
  28.             cout << endl;
  29.         }
  30.     }
  31.     cout << endl;
  32. }  
  33.  
  34. void play(char player, unsigned int square){
  35.     board1.squares[i] = player;
  36. }
  37.  
  38.  
  39. int main(){
  40.     board board1;
  41.  
  42.     for (int i = 0; i < 9; i++)
  43.         board1.squares[i]= i+1+48;
  44.     board1.show();
  45.  
  46.     bool gameOver = 0;
  47.     unsigned int first = rand()%1 + 1;
  48.     unsigned int square;
  49.     unsigned int round = 1;
  50.     while (gameOver != 0){
  51.         if (round % 2 != 0){
  52.             cout << "It's player X's turn: " << endl << "Where do you want to play?\n";
  53.             cin >> square;
  54.             play('X',square);
  55.         }
  56.         else{
  57.             cout << "It's player O's turn: " << endl << "Where do you want to play?\n";
  58.             cin >> square;
  59.             play('O',square);
  60.         }
  61.  
  62.         cout << endl << endl;
  63.         board1.show();
  64.         round++;
  65.         if (round == 4)
  66.             gameOver = 1;
  67.     return 0;
  68. }
Add Comment
Please, Sign In to add comment