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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with hangman controller.

Help with hangman controller.

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++game-devhelpquestion
12 Posts 4 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.
  • D djrasa

    I have to create a class called controller. I do not know what I need to include in this class: attributes and methods/getters/setters/operations?????? I understand the other classes involved in hangman, but not this one????? Demonstrate the use of a class. It is strongly recommended that you choose a class to implement from the Hangman Tutorial, such as the Controller class. Class must have a constructor. Class must have two class member variables of different data types and getters and setters to access these variables. Program must have 3 files, one header file, one .cpp file for that class and one Main.cpp. #ifndef CONTROLLER_H #define CONTROLLER _H #include <string> using namespace std; class Controller { private: string filename; // stores name of file where words are stored // Add other member variables here public: Controller(); void start(); // Add accessor and mutator methods here for your member values }; #endif // CONTROLLER_H Now add the source file (Controller.cpp) & code the constructor. #include "Controller.h" Controller::Controller(string filename) { cout << "Inside the Controller Default Constructor << endl; } // Finish implementing methods here First compile and execute the project to make sure you have typed everything correctly. Then modify your main() function to access your Controller class and use all methods. Here is an example main() function*: int main(int argc, char *argv[]) { Controller controller; // Call accessor and mutator methods for setting filename // Start the game return 0; } The Menu is not part of the actual hangman game itself, but rather allows us to add words to the game, play the game, and exit so it is a good candidate for its own class. The game itself can be a separate class so that we are not writing all of the code in main(). As a matter of a fact, let's plan on having very little code in main(), and let a separate class manage the interactions between the menu, game and the dictionary. We will call this class "Controller".

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #2

    djrasa wrote:

    Class must have two class member variables of different data types and getters and setters to access these variables.

    For example:

    class Controller
    {
    public:
    void setFilename( const char *s ) { filename = s; }
    string getFilename( void ) { return filename; }
    };

    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

    D 1 Reply Last reply
    0
    • D djrasa

      I have to create a class called controller. I do not know what I need to include in this class: attributes and methods/getters/setters/operations?????? I understand the other classes involved in hangman, but not this one????? Demonstrate the use of a class. It is strongly recommended that you choose a class to implement from the Hangman Tutorial, such as the Controller class. Class must have a constructor. Class must have two class member variables of different data types and getters and setters to access these variables. Program must have 3 files, one header file, one .cpp file for that class and one Main.cpp. #ifndef CONTROLLER_H #define CONTROLLER _H #include <string> using namespace std; class Controller { private: string filename; // stores name of file where words are stored // Add other member variables here public: Controller(); void start(); // Add accessor and mutator methods here for your member values }; #endif // CONTROLLER_H Now add the source file (Controller.cpp) & code the constructor. #include "Controller.h" Controller::Controller(string filename) { cout << "Inside the Controller Default Constructor << endl; } // Finish implementing methods here First compile and execute the project to make sure you have typed everything correctly. Then modify your main() function to access your Controller class and use all methods. Here is an example main() function*: int main(int argc, char *argv[]) { Controller controller; // Call accessor and mutator methods for setting filename // Start the game return 0; } The Menu is not part of the actual hangman game itself, but rather allows us to add words to the game, play the game, and exit so it is a good candidate for its own class. The game itself can be a separate class so that we are not writing all of the code in main(). As a matter of a fact, let's plan on having very little code in main(), and let a separate class manage the interactions between the menu, game and the dictionary. We will call this class "Controller".

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #3

      Thank you for posting your course assignment. We enjoy keeping abreast of the current CIS curriculum.

      led mike

      1 Reply Last reply
      0
      • D David Crow

        djrasa wrote:

        Class must have two class member variables of different data types and getters and setters to access these variables.

        For example:

        class Controller
        {
        public:
        void setFilename( const char *s ) { filename = s; }
        string getFilename( void ) { return filename; }
        };

        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        D Offline
        D Offline
        djrasa
        wrote on last edited by
        #4

        I do not see how this will control the menu, dictionary, and game/ and no attributes (I am trying to understand, not trying to imply that it is incorrect{you would know before me : ) }). I thought that I needed two attributes (eg. int, char) and two functions for each to manipulate them. Sorry I am pretty new to this (retorical). Thank you for the fast response, much abliged.

        D 1 Reply Last reply
        0
        • D djrasa

          I do not see how this will control the menu, dictionary, and game/ and no attributes (I am trying to understand, not trying to imply that it is incorrect{you would know before me : ) }). I thought that I needed two attributes (eg. int, char) and two functions for each to manipulate them. Sorry I am pretty new to this (retorical). Thank you for the fast response, much abliged.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #5

          djrasa wrote:

          I do not see how this will control the menu, dictionary, and game...

          It won't. I was just providing you an example of how to add "getters and setters" to your existing class.

          djrasa wrote:

          I thought that I needed two attributes (eg. int, char) and two functions for each to manipulate them.

          Which is what I showed you, only using the single member variable you already had.

          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          D 1 Reply Last reply
          0
          • D David Crow

            djrasa wrote:

            I do not see how this will control the menu, dictionary, and game...

            It won't. I was just providing you an example of how to add "getters and setters" to your existing class.

            djrasa wrote:

            I thought that I needed two attributes (eg. int, char) and two functions for each to manipulate them.

            Which is what I showed you, only using the single member variable you already had.

            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            D Offline
            D Offline
            djrasa
            wrote on last edited by
            #6

            I guess my real question is what is the point of the controller class (what has to be in it)?? What actions of the menu, dictionary, and game will it(controller class) control (won't these classes control there own actions???) It seems to me that you would not need this class (if not for assignment). Sorry, thanks for the response, I am just having a hard time understanding this class (for the most part I understand the menu, game, and dictionary classes). Thanks again for being patient with me, and answering my questions.

            M 1 Reply Last reply
            0
            • D djrasa

              I guess my real question is what is the point of the controller class (what has to be in it)?? What actions of the menu, dictionary, and game will it(controller class) control (won't these classes control there own actions???) It seems to me that you would not need this class (if not for assignment). Sorry, thanks for the response, I am just having a hard time understanding this class (for the most part I understand the menu, game, and dictionary classes). Thanks again for being patient with me, and answering my questions.

              M Offline
              M Offline
              Member 754960
              wrote on last edited by
              #7

              You are given a clue about the controller class in main: "Start the game" If you are the game controller and I tell you "Start the game" what do you need to do?

              D 1 Reply Last reply
              0
              • M Member 754960

                You are given a clue about the controller class in main: "Start the game" If you are the game controller and I tell you "Start the game" what do you need to do?

                D Offline
                D Offline
                djrasa
                wrote on last edited by
                #8

                call the function/method to display game board/word. This is what I have come up with so far, need to add variables to methods still. Is this close????? class Controller //Class for Controller. { public: void getgame(); void setgame (); Controller(); void getmenuinput(); void setmenuinput (); }; #endif //CONTROLLER_H

                M 1 Reply Last reply
                0
                • D djrasa

                  call the function/method to display game board/word. This is what I have come up with so far, need to add variables to methods still. Is this close????? class Controller //Class for Controller. { public: void getgame(); void setgame (); Controller(); void getmenuinput(); void setmenuinput (); }; #endif //CONTROLLER_H

                  M Offline
                  M Offline
                  Member 754960
                  wrote on last edited by
                  #9

                  Normally I would say "Stop trying to write code until you understand what you are trying to accomplish." However, here that is the only way you can demonstrate effort. When you know what you are tying to do it will be easier to see how the various classes/objects function. Maybe I'd like to start a new game. Maybe I'd like to quit the program. Maybe I'd like to save the game I'm in. Maybe... Who displays these to the user? When? Who gets the user selection? When? So, controller says,

                  While not quit
                  	Display menu
                  	Get menu selection
                  

                  Where are all these menu things located?

                  D 1 Reply Last reply
                  0
                  • M Member 754960

                    Normally I would say "Stop trying to write code until you understand what you are trying to accomplish." However, here that is the only way you can demonstrate effort. When you know what you are tying to do it will be easier to see how the various classes/objects function. Maybe I'd like to start a new game. Maybe I'd like to quit the program. Maybe I'd like to save the game I'm in. Maybe... Who displays these to the user? When? Who gets the user selection? When? So, controller says,

                    While not quit
                    	Display menu
                    	Get menu selection
                    

                    Where are all these menu things located?

                    D Offline
                    D Offline
                    djrasa
                    wrote on last edited by
                    #10

                    in the controller class? something like this? class Controller { private: string filename; //Store filename. int Menu; //Store Menu. public: void setFilename(const char *s); //Method to set filename. string getFilename(void); //Method to get filename. int getmenu(int choice); //Method to get menu. void setmenu(const int m); //Method to set menu. Controller(); //Default constructor. }; #endif

                    D 1 Reply Last reply
                    0
                    • D djrasa

                      in the controller class? something like this? class Controller { private: string filename; //Store filename. int Menu; //Store Menu. public: void setFilename(const char *s); //Method to set filename. string getFilename(void); //Method to get filename. int getmenu(int choice); //Method to get menu. void setmenu(const int m); //Method to set menu. Controller(); //Default constructor. }; #endif

                      D Offline
                      D Offline
                      djrasa
                      wrote on last edited by
                      #11

                      Controller.cpp file #include "Controller.h" Controller::Controller() { Menu = 0; } int Controller::getmenu(int choice) { return Menu; } void Controller::setmenu(const int m) { Menu = m; } string Controller::getFilename() { return filename; } void Controller::setFilename(const char *s) { filename = s; }

                      D 1 Reply Last reply
                      0
                      • D djrasa

                        Controller.cpp file #include "Controller.h" Controller::Controller() { Menu = 0; } int Controller::getmenu(int choice) { return Menu; } void Controller::setmenu(const int m) { Menu = m; } string Controller::getFilename() { return filename; } void Controller::setFilename(const char *s) { filename = s; }

                        D Offline
                        D Offline
                        djrasa
                        wrote on last edited by
                        #12

                        Main.cpp #include <iostream> #include "Controller.h" //include controller header file using namespace std; int main() { int choice; //To hold screen to display message, until menu class is added. int menu = 0; const char *word = "Hangman"; Controller controller; Controller display; display.setmenu(menu); //Method to set the menu. display.getmenu(menu); //Method to get the menu. controller.setFilename(word); //Set filename to Hangman. cout << "Coming soon - " << controller.getFilename() << endl; //Display temporary message. cout << "To be continued......" << endl; cout << endl; cout << "Please click X in top right corner to exit." << endl; cin >> choice; //Hold screen to display message. return 0; }

                        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