This is the mini version of the typical reversi game. In this program, we use two sets of two-dimensional arrays (4x4)and declare them as Boolean , one
represent the white pieces and the other one represent the black pieces. If a white piece or a black piece occupies a square, the variable becomes true , otherwise it is false.
By using this concept, the program can check how many white and black pieces appear on the reversi board and which positions they occupy. we use If...Then and Select Case.... End Select statements to check
for conditions whether a white piece or a black piece can be put in a certain
position so that the pieces trapped in between will change colour. We also added
a procedure to display the number of white pieces and the number of black pieces
at any one time and also who is the winner.
To design the interface, we need to insert an image control and then copy and paste the image repeatedly to form a 4x4 array of images. Each image is defined by its index. For example, Image1(0) is the first image Image1(1) is the second image, Image1(2) is the third image and so on. The positions of the images are shown in the diagram below:
Next we need to create two images, a white solid circle and a black solid circle, save them as jpeg files. Load them into two image controls on the form. You can use whatever name for the two images, we use image17 to denote the while solid circle and image18 to denote the black circle. The two images are very important as we will later use the dragdrop method to enable the user to drag and drop the images into the circles.
Option Base 1
Dim white(4, 4) As Boolean
Dim black(4, 4) As Boolean
Dim i, j, k, w, b As Integer
Dim imgtag As String
'The following subroutine is to check for the number and
of the white and black pieces on the board. Image17 is a white button
image18 is a black button.
k = 0
For j = 1 To 4
For i = 1 To 4
If Image1(k).Picture = Image17.Picture Then
white(i, j) = True
Else: white(i, j) = False
If Image1(k).Picture = Image18.Picture Then
black(i, j) = True
black(i, j) = False
k = k + 1