Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. so confused!

so confused!

Scheduled Pinned Locked Moved C / C++ / MFC
c++game-devregexquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ISUstudent
    wrote on last edited by
    #1

    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() { }

    H R 2 Replies Last reply
    0
    • I ISUstudent

      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() { }

      H Offline
      H Offline
      Hardy_Smith
      wrote on last edited by
      #2

      You have to return a value in the bool-Method. return true; Hardy.

      1 Reply Last reply
      0
      • I ISUstudent

        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() { }

        R Offline
        R Offline
        rotu
        wrote on last edited by
        #3

        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()); }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups