so confused!
-
Hey guys...How would I go about writing this in the .cpp file? MOSTLY THE BOOL METHODS I AM HAVING TROUBLE WITH This is what I have for the Menu.h file #ifndef CONNECTFOUR_H #define CONNECTFOUR_H #include "Menu.h"//includes Menu header file using namespace std; class ConnectFour { private: //date members int board[12][13]; int numChips[7]; public: ConnectFour(); //default constructor bool playTurn(); /*gives a player the opportunity to place a chip into the board. This should be a Boolean function to return true if this turn produces a winner (otherwise false should be the return value).*/ void displayBoard(); /*places 2 different kinds of markers on the board (one for each player) and displays some kind of marker for empty slots. Be sure your choices are easy to see. */ void dropChip(); //places a chip into the board and looks for a winner void checkWinner(); //should call 4 helper functions (you choose the names) to check the 4 possible winning moves – 4 in a row vertically, horizontally, or diagonally. These helper functions should look only at possible wins produced by this last move – they should not check the entire board! void verticalwin(); //this method checks to see if 4 colors match to win the game vertically void horizontalwin(); //this method checks to see if 4 colors match to win the game horizonatally void diagonalwin1(); //this method checks to see if 4 colors match to win the game diagonally one way void diagonalwin2(); //this method checks to see if 4 colors match to win the game diagonally the second way bool determineDraw(); //method determines if the game is a draw (full board with no winner). This method returns true if the game is a draw and false if not. }; #endif //ends ConnectFour.h All I have left for my ConnectFour.cpp is ... #include #include #include "ConnectFour.h"//includes ConnectFour header file //default constructor will initialize zero to the data private members (variables) ConnectFour::ConnectFour() { board[12][13] = 0; numChips[7] = 0; for(int i=0; i < 12; i++) { for(int j=0; j<13; j++) { board[i][j] = 0; } } for(int i=0; i<7; i++) { numChips[i]= 0; } } bool ConnectFour::playTurn() { }
-
Hey guys...How would I go about writing this in the .cpp file? MOSTLY THE BOOL METHODS I AM HAVING TROUBLE WITH This is what I have for the Menu.h file #ifndef CONNECTFOUR_H #define CONNECTFOUR_H #include "Menu.h"//includes Menu header file using namespace std; class ConnectFour { private: //date members int board[12][13]; int numChips[7]; public: ConnectFour(); //default constructor bool playTurn(); /*gives a player the opportunity to place a chip into the board. This should be a Boolean function to return true if this turn produces a winner (otherwise false should be the return value).*/ void displayBoard(); /*places 2 different kinds of markers on the board (one for each player) and displays some kind of marker for empty slots. Be sure your choices are easy to see. */ void dropChip(); //places a chip into the board and looks for a winner void checkWinner(); //should call 4 helper functions (you choose the names) to check the 4 possible winning moves – 4 in a row vertically, horizontally, or diagonally. These helper functions should look only at possible wins produced by this last move – they should not check the entire board! void verticalwin(); //this method checks to see if 4 colors match to win the game vertically void horizontalwin(); //this method checks to see if 4 colors match to win the game horizonatally void diagonalwin1(); //this method checks to see if 4 colors match to win the game diagonally one way void diagonalwin2(); //this method checks to see if 4 colors match to win the game diagonally the second way bool determineDraw(); //method determines if the game is a draw (full board with no winner). This method returns true if the game is a draw and false if not. }; #endif //ends ConnectFour.h All I have left for my ConnectFour.cpp is ... #include #include #include "ConnectFour.h"//includes ConnectFour header file //default constructor will initialize zero to the data private members (variables) ConnectFour::ConnectFour() { board[12][13] = 0; numChips[7] = 0; for(int i=0; i < 12; i++) { for(int j=0; j<13; j++) { board[i][j] = 0; } } for(int i=0; i<7; i++) { numChips[i]= 0; } } bool ConnectFour::playTurn() { }
You have to return a value in the bool-Method. return true; Hardy.
-
Hey guys...How would I go about writing this in the .cpp file? MOSTLY THE BOOL METHODS I AM HAVING TROUBLE WITH This is what I have for the Menu.h file #ifndef CONNECTFOUR_H #define CONNECTFOUR_H #include "Menu.h"//includes Menu header file using namespace std; class ConnectFour { private: //date members int board[12][13]; int numChips[7]; public: ConnectFour(); //default constructor bool playTurn(); /*gives a player the opportunity to place a chip into the board. This should be a Boolean function to return true if this turn produces a winner (otherwise false should be the return value).*/ void displayBoard(); /*places 2 different kinds of markers on the board (one for each player) and displays some kind of marker for empty slots. Be sure your choices are easy to see. */ void dropChip(); //places a chip into the board and looks for a winner void checkWinner(); //should call 4 helper functions (you choose the names) to check the 4 possible winning moves – 4 in a row vertically, horizontally, or diagonally. These helper functions should look only at possible wins produced by this last move – they should not check the entire board! void verticalwin(); //this method checks to see if 4 colors match to win the game vertically void horizontalwin(); //this method checks to see if 4 colors match to win the game horizonatally void diagonalwin1(); //this method checks to see if 4 colors match to win the game diagonally one way void diagonalwin2(); //this method checks to see if 4 colors match to win the game diagonally the second way bool determineDraw(); //method determines if the game is a draw (full board with no winner). This method returns true if the game is a draw and false if not. }; #endif //ends ConnectFour.h All I have left for my ConnectFour.cpp is ... #include #include #include "ConnectFour.h"//includes ConnectFour header file //default constructor will initialize zero to the data private members (variables) ConnectFour::ConnectFour() { board[12][13] = 0; numChips[7] = 0; for(int i=0; i < 12; i++) { for(int j=0; j<13; j++) { board[i][j] = 0; } } for(int i=0; i<7; i++) { numChips[i]= 0; } } bool ConnectFour::playTurn() { }
Hello, void verticalwin(); void horizontalwin(); void diagonalwin1(); void diagonalwin2(); I think these functions should also return boolean datatypes, like determineDraw function. If you will do this, you can just check if any of these functions returned a true value. And hence, determine if there has been a winner. maybe like this: bool ConnectFour::playTurn() { // TODO: // Get the column input here return (verticalwin() || horizontalwin() || diagonalwin1() || diagonalwin2()); }