This mini version of the classic Reversi game demonstrates core programming concepts using Visual Basic 6. The implementation uses two-dimensional arrays to track game state and includes logic for validating moves and flipping pieces.
The game uses two 4×4 Boolean arrays:
When a piece is placed on the board, the corresponding array element is set to True. The game logic then checks adjacent positions to determine which pieces should be flipped.
The game board is implemented using an array of 16 image controls arranged in a 4×4 grid. Each square is represented by an indexed image control (Image1(0) to Image1(15)).
Players drag either the white or black piece image onto the board. The game validates each move to ensure it follows Reversi rules before updating the game state.
Using If...Then and Select Case statements, the program checks valid moves and flips trapped pieces between the newly placed piece and existing pieces of the same color.
The game continuously counts and displays the number of white and black pieces. At game end, it declares the winner based on piece count.
To create the game interface:
DragDrop method| Image1(12) | Image1(13) | Image1(14) | Image1(15) |
| Image1(8) | Image1(9) | Image1(10) | Image1(11) |
| Image1(4) | Image1(5) | Image1(6) | Image1(7) |
| Image1(0) | Image1(1) | Image1(2) | Image1(3) |
Figure 1: Image control positions on the game board
Figure 2: Reversi game in action with white and black pieces
The following subroutine checks the status of each position on the board:
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
' Check board status and update piece positions
Sub checkstatus()
k = 0
For j = 1 To 4
For i = 1 To 4
' Check for white pieces
If Image1(k).Picture = Image17.Picture Then
white(i, j) = True
Else
white(i, j) = False
End If
' Check for black pieces
If Image1(k).Picture = Image18.Picture Then
black(i, j) = True
Else
black(i, j) = False
End If
k = k + 1
Next i
Next j
End Sub
This procedure:
The core game mechanics involve:
' Example of move validation logic
If ValidMove(row, col, currentPlayer) Then
PlacePiece(row, col, currentPlayer)
FlipPieces(row, col, currentPlayer)
currentPlayer = IIf(currentPlayer = WHITE, BLACK, WHITE)
Else
MsgBox "Invalid move! Please try again."
End If