Hi.
I'm new to wxWidget and I'm trying to build a Tic Tac Toe program by using wxWidget.
I can set the buttons to "X" using pointer->setLabel("X") on a buttonClick event, but how would I be able to retrieve the information by using getLabel?
For example, if on every buttonClick event, I can set a label, how would I be able to use the same event to get the label of other buttons and use the tic-tac-toe logic to see how many "X" and "O"s have been clicked?
Thank you
wxWidget Tic Tac Toe?
Re: wxWidget Tic Tac Toe?
There are ways to access the other buttons, e.g. to find them by id, or store their pointers in an array when they are created.
But the better solution is to separate the data from the gui. Just have a 3x3 array that stores the current state for each field. When a button is clicked, change the corresponding array entry. And there you can also access the state of the other fields.
But the better solution is to separate the data from the gui. Just have a 3x3 array that stores the current state for each field. When a button is clicked, change the corresponding array entry. And there you can also access the state of the other fields.
Use the source, Luke!
Re: wxWidget Tic Tac Toe?
Thanks for the reply.
How would you save "states" in wxWidget?
Since getLabel returns a wxString, do I need to make an array of strings?
How would you save "states" in wxWidget?
Since getLabel returns a wxString, do I need to make an array of strings?
Re: wxWidget Tic Tac Toe?
No. I would use an array of integers. 0=empty, 1=O, 2=X
Use the source, Luke!