Ok I have this tutorial for creating a hangman game. I started writing down what I needed to do. The only thing that sucks is I don't have the slightest idea on how to create a hangman game. I read over this tutorial like 3 times followed along with it and get to the point where it says now you need to start adding all the other classes before you compile again. Is there anyway I can get help with like a base example of what it should follow, not the actual code for hangman. I really just don't see how I get 11 files for this.
Here is the tutorial:
Functional Architectural Prototype
This section is designed to jump start your Functional Architectural prototype. If you have brought up your source code editor or IDE and have sat there staring at a blank screen for an hour or two, unsure of how to proceed, then you've come to the right place.
You should already be familiar with how to start a new project using the Visual Studio.NET IDE. If you have difficulty with this, please contact your instructor immediately.
Change the #include statement to include iostream instead of stdio.h. Add an #include for stdlib.h (for the system call). Add a cout statement to display your name or "Hello World". Next add the line system("PAUSE"); before the return statement. Click Execute->Compile and Run. Type 'Main' in the Save File dialog, and click save. You should see a Console window that displays your message, and "Press any key to continue". Press a key and click the Continue button.
Right click on 'Term Project' and select 'New unit in project'. Declare the Menu class.
#ifndef _MENU_
#define _MENU_
#include <string>
using namespace std;
class Menu
{
public:
Menu(string filename);
};
#endif _MENU_
Now add the source file (Menu.cpp) & code the constructor.
#include "Menu.h"
Menu::Menu(string filename)
{
cout << "The file name is..." << endl;
}
First compile and execute the project to make sure you have typed everything correctly. Then modify your main() function to create and start your game. Note that you will have to add the rest of your classes and stub out their interfaces before you will be able to compile again.
Here is an example main() function. Note that the Game Constructor takes a Menu as an argument, so you will have to #include "Menu.h" in that class declaration.
Note: This code sample does not include the required header declarations.
int main(int argc, char *argv[])
{
Menu myMenu("hangman.txt");
Game myGame(myMenu);
Controller myController(myGame);
myController.start(); // Start the application
return 0;
}
The Controller
In order to tie all of these classes together in a meaningful way, it is useful to add a little code into the Controller class; particularly in the start method. The Controller manages the behavior of the entire application. In our main() function (above) the Menu class was constructed with the name of the file that will be used to load/save our Hangman database. The Game class is constructed with a reference to the Menu that administers it, and the Controller was constructed with a reference to the Game class.
Next main() passes control to the Controller by calling it's start() method. So what happens in Controller::start()? This Object Interaction diagram (below) will hopefully shed some light on that question.
The Controller asks the Game for it's Menu and then enters a while loop, repeating the loop as long as the menu terminate() method returns false. Each time through the loop, the Controller displays the Menu (Menu::display()) which returns a char command. The Controller takes that char command and calls it's internal processCommand() method. Finally, processCommand() calls the Game::play() method. Later on, you will add code to processCommand() to add, search, delete, play, etc., based upon the results returned from the Menu.
Hopefully, this section will provide you with enough information to allow you to complete your Functional Architectural Prototype. Do not limit your Prototype to these few classes. Think through how the Hangman game will work, and create the additional classes to support that functionality.
Once you do get your prototype working, it would be a very good idea for you to set your work aside somewhere safe, and start over from scratch (without using the tutorial). Try to draw yourself a complete Object Model first. With an understanding of the requirements and design, you should be able to code this handful of classes & make them interact appropriately without any help.
Hints
Here is a list of files you should now (at a minimum) have in your project if you are following the tutorial. They should each define the shell of a class, and each method should print a simple line of debug output to the Console.
Main.cpp // Entry point for main() function
Controller.h // Controller header file
Controller.cpp // Controller source file
Game.h // Game header file
Game.cpp // Game source file
HangmanGame.h // Hangman Game header file
HangmanGame.cpp // Hangman Game source file
Menu.h // Menu header file
Menu.cpp // Menu source file
HangmanMenu.h // HangmanMenu header file
HangmanMenu.cpp // HangmanMenu source file
If you have completed the tutorial successfully so far, when you run your program, you will see some console output indicating several methods are being called in our various classes. If you look closely at the output, you may find that the HangmanGame and HangmanMenu methods are not being called. Why not?
Well, because we haven't constructed instances of those objects yet, that's why. Let's update our main() function and try again.
int main(int argc, char *argv[])
{
HangmanMenu myMenu("hangman.txt");
HangmanGame myGame(myMenu);
Controller myController(myGame);
myController.start(); // Start the application
return 0;
}
Now, if you have overridden the virtual method Game::play() in HangmanGame, then you should see that HangmanGame::play() is now being called. You will have to add the beginnings of a switch statement to Controller::processCommand() for this to work.
void Controller::processCommand(char command)
{
cout << "(debug) Controller::processCommand()" << endl;
switch(command)
{
case 'p':
theGame.play();
break;
default:
cout << "I do not understand that command" << endl;
}
Now to display the Menu, put the (q)uit functionality in Menu::display(), and the other menu options in HangmanMenu::display(). We call up to the base class explicitly in HangmanMenu.
char HangmanMenu::display()
{
cout << "(debug) HangmanMenu::display()" << endl;
// Add the other menu options her
// (a)dd, (r)emove, (s)earch, (e)dit, (p)lay
return Menu::display();
}
If you've made it this far, you should be able to run your application, interact with the menu, and confirm the correct method HangmanGame::play() is being invoked when you choose (p)lay from the menu. Now you can go back and add the 'meat' to your application.