This product is no longer in stock
A player chooses to be the X or the O. In each turn he can only place one in order to get 3 in a row on a vertical, horizontal or diagonal line.
The game ends once all 3 in a row are achieved or when all the spaces are filled, ending in a draw if none of them manages to link three of their pieces in a row.
Some examples of combinations:
Do not use sprites for the board elements, or for the board given their simplicity. GDI + is used for this painting job.
As we are painting on the bottom of the form immediately, it is necessary to enable the doublebuffer of the form to avoid flickering.
Basically two objects are programmed.
- Board: General container.
- Cell: Manage the behavior of each cell on the board.
- FormPrincipal: The form where objects are painted.
To search for the winning player, use a bit marking scheme, using two 32-bit integer registers.
As you can see in the previous image, each box is a bit of weight of an integer register, only use 9 bits of the 32 that make up the register.
The program goes through the boxes and dials the corresponding bit if you get the icon in the box.
Once this is done, a masking is made for the possible winning combinations and the winner is determined.
It is simple and fast. An example is seen below:
Note that bits 0, 4 and 8 of the 32-bit integer array are on.
To better see everything I explain here, below I leave the link to download the entire project in Visual Basic .NET
Download source code
NO registration required!
If the question you have has not yet been answered here, use the form below to ask something about this addon.