Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. class Connect4
  6. {
  7. private:
  8.     int rows;
  9.     int columns;
  10.     int * * board;
  11.     char piece;
  12.    
  13. //    bool GameOver()
  14. //    {
  15. //
  16. //    }
  17. //    char Winner()
  18. //    {
  19. //
  20. //        //if user wins, game ends and winner is declared
  21. //
  22. //    }
  23. //    int getAiMove()
  24. //    {
  25. //
  26. //    }
  27.  
  28.  
  29.    
  30. public:
  31.     Connect4()
  32.     {
  33.         rows = 6;
  34.         columns = 7;
  35.         board = new int*[rows];
  36.         for (int i = 0; i < rows; i++)
  37.         {
  38.             board[i] = new int[columns];
  39.         }
  40.        
  41.         }
  42.    
  43.     Connect4(int numRows, int numColumns)
  44.     {
  45.         rows = numRows;
  46.         columns = numColumns;
  47.         board = new int*[rows];
  48.         for (int i = 0; i < rows; i++)
  49.         {
  50.             board[i] = new int[columns];
  51.         }
  52.     }
  53.    
  54.     void DrawBoard()
  55.     {
  56.         cout << setw(5);
  57.         for (int i = 0; i < columns; i++)
  58.         {
  59.             cout << i << " ";
  60.         }
  61.         cout << endl;
  62.         for (int i = 0; i < rows; i++)
  63.         {
  64.  
  65.             cout << i << " | " << setw(columns*2) << "|" << endl;
  66.  
  67.         }
  68.         cout << "  ________________";
  69.  
  70. //        }
  71.  
  72.         //print contents of the board
  73.         for (int i = 0; i < rows; i++)
  74.         {
  75.             for (int j = 0; j < columns; j++)
  76.             {
  77.                 cout << " " ;
  78.             }
  79.             cout << endl;
  80.         }
  81.        
  82.     }
  83.    
  84.     int drop(int piece, int column)
  85.     {
  86.         if (column < 0 || column > 6)
  87.         {
  88.             int choice;
  89.             cout << "Error! Please select a column between 0 and " << columns << endl;
  90.             cin >> choice;
  91.             column = choice;
  92.         }
  93.        
  94.         for (int i = 5; i >= 0; i--)
  95.         {
  96.             if(board[i][column] == ' ')
  97.             {
  98.                 board[i][column] = piece;
  99.                 break;
  100.                 return i;
  101.             }
  102.         }
  103.        
  104.         return 0;
  105.     }
  106.  
  107.    
  108.  
  109. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement