How should I define the next() fucntion- LINE 69.
For now the get_string isnt even fetching the string from the In_box
//09030032 at lums
//======================================
//Stroustrup Interface Libray files
//======================================
#include "Simple_window.h"
#include "Graph.h"
#include "GUI.h"
#include "Window.h"
#include "../std_lib_facilities.h"
//======================================
//Load neccessary header files
//======================================
#include <fstream> //to load words from file
#include <sstream> //for text
#include <iostream> //to use getline function
#include <vector> //to save word and hint list
#include <cstdlib> //for rand();
#include <cstring>
using namespace std;
using namespace Graph_lib;
//////////////////////////////////////////////////////////////////////
//HANG MAN WINDOW CLASS
/////////////////////////////////////////////////////////////////////
struct Hangman_window : Window {
Button next_button; // Input word
Button quit_button;
In_box next_x;
////////////////////////////////////////////////////////////////////////
//CONSTRUCTOR: create window, quit button, next button
////////////////////////////////////////////////////////////////////////
Hangman_window(Point xy, int w, int h, const string& title,Image& background)
:Window(xy,w,h,title),
next_button( Point(200,y_max()-50) , 70, 20, "Enter", cb_next),
quit_button( Point(x_max()-100,y_max()-50), 70, 20, "Quit", cb_quit),
next_x(Point(100,y_max()-50), 50, 20, "Guess a letter:")
{
attach(background);
attach(next_button);
attach(quit_button);
attach(next_x);}
//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
void quit()
{ hide();}
static void cb_quit(Address, Address pw) // callback for quit_button
{ reference_to<Hangman_window>(pw).quit();}
////////////////////////////////////////////////////////////////////////////
static void cb_next(Address, Address pw) // callback for next_button
{reference_to<Hangman_window>(pw).next();}
void next()
{
string str=next_x.get_string(); }
/* char c=s[0];
Text t(Point(640,480), s);
attach(t);
redraw();
CHECK IF LETTER IS IN THE STRING
DISPLAY IF IT IS.
OR ELSE RECEDE MASK !!!!!!!!!!
redraw();
*/
};
//========================================================================
// Draw spaces/blanks
//========================================================================
void drawSpaces ( Hangman_window& win, int num, Lines& LX)
{ int x=10, y=400;
for (int f=0; f<num; f++)
{ LX.add( Point(x,y),Point(x+50,y) );
x=x+60;}
win.attach(LX);
}
//========================================================================
int main ()
{
//**************************************************************************
//create a 1024*768 window with a white background
Point tl(100,100);
Image bkgrnd(Point(0,0),"background.jpg");
Hangman_window win (tl,1024,768,"Canvas",bkgrnd);
//**************************************************************************
//Instructions & Credits
Text t1(Point(700,20), "Hangman v1.0 - created by __________ Inc.");
Text t2(Point(50,50), "Guess the word, before you're hanged to death. Enter a letter in the box");
t2.set_color(Color::blue);
Rectangle box(Point(30,20),600,40);
win.attach(box);
win.attach(t1);
win.attach(t2);
//Hangman Guy comes in the Window
int mask=50; //value by which mask will recede (a 50 pixel drop down)
Image alive(Point(700,50),"alive.jpg");
alive.set_mask(Point(0,0),570,mask);
win.attach(alive);
//***************************************************************************
//Load word list and hints into vectors. Then choose a word to use in the game.
//***************************************************************************
vector<string> words;
vector<string> hints;
ifstream readfile("hint_wordlist.txt"); //open file
while (!readfile.eof()) //loop to load hints and words into their vectors
{ string s;
getline(readfile,s,'\n');
words.push_back(s);
getline(readfile,s,'\n');
hints.push_back(s);
} readfile.close(); //close file
string word; //randomly chosen word to use in game
string hint; //along with its hint
int random;
do //loop to randomly choose the right word for the game
{
random=rand();
if (random<words.size())
{ word=words[random];
hint=hints[random];}
} while ( random<words.size() );
//***************************************************************************
//Draw Spaces/Blanks
//***************************************************************************
Lines LX;
drawSpaces(win,word.size(),LX);
//***************************************************************************
return gui_main();
}