wxWidget Tic Tac Toe?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
monjinko
In need of some credit
In need of some credit
Posts: 5
Joined: Sun Nov 12, 2017 12:50 am

wxWidget Tic Tac Toe?

Post by monjinko »

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
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWidget Tic Tac Toe?

Post by doublemax »

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.
Use the source, Luke!
monjinko
In need of some credit
In need of some credit
Posts: 5
Joined: Sun Nov 12, 2017 12:50 am

Re: wxWidget Tic Tac Toe?

Post by monjinko »

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?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWidget Tic Tac Toe?

Post by doublemax »

No. I would use an array of integers. 0=empty, 1=O, 2=X
Use the source, Luke!
Post Reply