Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- class Connect4
- {
- private:
- int rows;
- int columns;
- int * * board;
- char piece;
- // bool GameOver()
- // {
- //
- // }
- // char Winner()
- // {
- //
- // //if user wins, game ends and winner is declared
- //
- // }
- // int getAiMove()
- // {
- //
- // }
- public:
- Connect4()
- {
- rows = 6;
- columns = 7;
- board = new int*[rows];
- for (int i = 0; i < rows; i++)
- {
- board[i] = new int[columns];
- }
- }
- Connect4(int numRows, int numColumns)
- {
- rows = numRows;
- columns = numColumns;
- board = new int*[rows];
- for (int i = 0; i < rows; i++)
- {
- board[i] = new int[columns];
- }
- }
- void DrawBoard()
- {
- cout << setw(5);
- for (int i = 0; i < columns; i++)
- {
- cout << i << " ";
- }
- cout << endl;
- for (int i = 0; i < rows; i++)
- {
- cout << i << " | " << setw(columns*2) << "|" << endl;
- }
- cout << " ________________";
- // }
- //print contents of the board
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < columns; j++)
- {
- cout << " " ;
- }
- cout << endl;
- }
- }
- int drop(int piece, int column)
- {
- if (column < 0 || column > 6)
- {
- int choice;
- cout << "Error! Please select a column between 0 and " << columns << endl;
- cin >> choice;
- column = choice;
- }
- for (int i = 5; i >= 0; i--)
- {
- if(board[i][column] == ' ')
- {
- board[i][column] = piece;
- break;
- return i;
- }
- }
- return 0;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement