Help with Buttons

Hello,
I am working on this program that simulates a fox and hounds game. In this program there are four buttons, each controlling one piece to any of the four diagonal directions. If it gets to the edge, the corresponding buttons will hide. I am currently having trouble with some functions. But I think im not using the right command. Here is my code for the class corresponding to the game window. Forgive me for the mess, this was just a prototype.

struct game_Window : Window {

game_Window(Point xy, int w, int h, const string& title)
:Window(xy,w,h,title),
button_pushed(false),
fox(Point(175,375),20),
W_crew1(Point(25,25),20),
W_crew2(Point(125,25),20),
W_crew3(Point(225,25),20),
W_crew4(Point(325,25),20),
time_out(Point(400,250), 100, 50, "Quit Game", out),
move1Point(400,100),50,50, "1", m1),
move2(Point(450,100),50,50, "2", m2),
move3(Point(400,150),50,50, "3", m3),
move4(Point(450,150),50,50, "4", m4)
{
attach(move1);
attach(move2);
attach(move3);
attach(move4);
attach(time_out);
for(int i=0;i<8;++i)
for(int j=0;j<8;++j){
board.push_back(new Rectangle(Point(i*50,j*50),50,50));
if((j+i)%2)
board[board.size()-1].set_fill_color(Color::green);
else{ board[board.size()-1].set_fill_color(Color::dark_green);}
attach(board[board.size()-1]);
}
fox.set_fill_color(253);
attach(fox);
W_crew1.set_fill_color(Color::dark_red);
attach(W_crew1);
W_crew2.set_fill_color(Color::dark_red);
attach(W_crew2);
W_crew3.set_fill_color(Color::dark_red);
attach(W_crew3);
W_crew4.set_fill_color(Color::dark_red);
attach(W_crew4);
}
Vector_ref<Rectangle>board;
Circle fox;
Circle W_crew1;
Circle W_crew2;
Circle W_crew3;
Circle W_crew4;
Button time_out;
Button move1;
Button move2;
Button move3;
Button move4;
void wait(){while(!button_pushed) Fl::wait(); button_pushed=false; Fl::redraw();}
private:
bool button_pushed;
static void out(Address, Address addr)
{
static_cast<game_Window*>(addr)->half_time();
}
static void m1(Address a, Address addr)
{
static_cast<game_Window*>(addr)->move_1(a);
}
static void m2(Address a, Address addr)
{
static_cast<game_Window>(addr)->move_2(a);
}
static void m3(Address a, Address addr)
{
static_cast<game_Window>(addr)->move_3(a);
}
static void m4(Address a, Address addr)
{
static_cast<game_Window>(addr)->move_4(a);
}
void half_time(){button_pushed = true;}
void move_1(Address a){if(x==25 || y==25){m1.hide();}else{fox.move(-50,-50);redraw();}};
void move_2(Address a){if(x==25 || y==25){m2.hide();}else{fox.move(50,-50);redraw();}};
void move_3(Address a){if(x==375 || y==375){m3.hide();}else{fox.move(-50,50);redraw();}};
void move_4(Address a){if(x==375 || y==375){m4.hide();}else{fox.move(50,50); redraw();}};
};

I am using the xwin.32 application, and using GUI FLTK library.
Please enclose your code with [ code ] [ /code ]. Makes it a lot easier to quickly catch up on your code.

Otherwise, state what specifically is your problem. Saying
I am currently having trouble with some functions.

is very vague.

From general inspection. I can see a logic fault in your move functions. Don't have an if-else statement. Rather place the if function at the end of the code after the move and redraw. That way the player may still be able to legally move and at the end of that move. The program will determine whether he can carry on moving in that direction or not. If not, the button will become hidden.

right, sorry about that, and thanks, ill fix that.
but this is the part that i am having trouble with
1
2
3
4
5
6

void move_1(Address a){if(x==25 || y==25){m1.hide();}else{fox.move(-50,-50);redraw();}};
void move_2(Address a){if(x==25 || y==25){m2.hide();}else{fox.move(50,-50);redraw();}};
void move_3(Address a){if(x==375 || y==375){m3.hide();}else{fox.move(-50,50);redraw();}};
void move_4(Address a){if(x==375 || y==375){m4.hide();}else{fox.move(50,50); redraw();}};


It was working fine when all i had in the function was the move and redraw, but when i put the .hide in it, it tells me this

error: invalid use of member (did you forget the & ?)
error: request for member 'hide' in game_Window::m1, which is of non-class type void()(void * void*)
I am really confused about this, any help please?
You can't hide the function "m1". You want to hide the button "move1". So:

move1.hide();
Last edited on
I can't believe I overlooked that! Thank you!
Topic archived. No new replies allowed.