Howdy I am writing a program that acts as a 15 puzzle game. I am having trouble with the function that switches the labels of the buttons. I confused on how to access the vector that initializes the array in the function and changing it to fit my needs .
-------------------------------------------------------------------------------
Bellow is the code im having trouble with.
Im getting erros such as vector v is not defined in the scope. and
vector is not defined in std.
void button_cb( Fl_Widget* obj , void* )
{
//switch label with the label empty label button
//int spaceposition=15; original position of empty label.
std::vector<int> myvec(v, v + sizeof(v) / sizeof(v[0]) );
int pos = std::find(myvec.begin(), myvec.end(), obj->label) - myvec.begin();
//code above should give me the position of the label in my original v vector.
if (pos=spaceposition4
||pos=spaceposition+4||pos=spacepositon+1||pos=spaceposition-1)
//code that switches labels or positions of the buttons corresponding // values and ubdates the vector position of the space.
obj->redraw();
}
Overall I am asking how does one access each object and switch their labels while updating the original vector v with the condition that the object is 4 or one spaces away from the empty space " ".
but -> callback( ( Fl_Callback* ) button_cb );
Why do you call this function ?
Normally this callback function is called from the button when it is clicked.
No this is actually correct.
std::vector<int> myvec(v, v + sizeof(v) / sizeof(v[0]) );
v is defined in make_window() so you can't access it outside the function. If you need it outside you can declare it global - global constants are ok.
1 2
if (pos=spaceposition4
||pos=spaceposition+4||pos=spacepositon+1||pos=spaceposition-1)
= is the assignment operator, do you mean == ?
It seems you want to find the button in the vector, but why when you have it already? void button_cb( Fl_Widget* obj , void* )
obj is the button that was clicked.