Introduction
This is my first upload. This is just a two hours project and my first submission to The Code Project, so be indulgent ~('.')~
I write this articles because I wish to share something I just learned. I remember that I am a beginner I can make a mistake. I have developed a Simple 2D game. I wrote this game program in my school days out of my interest in learning Visual Basic. I used the Visual Studio 6 for coding this.
The Game
I realize that a number of people will just want to try out the sample and see if it is worth spending the time looking at the source code. So I will first present the game, the controls, then I will explain how it works in later sections. This intermediate tutorial describes how to play Puzzle and how to Re arrange the numbers.
First, the user starts the game by clicking on OK:
Then a Main window appears. Here numbers are arranged randomly you have to arrange numbers in ordered way.
How is Puzzle played?
=> To swap a number with its adjacent empty block, just click the number. Continue this process until all numbers are arranged in a ordered way.
=>To end the game, click the icon in the upper right corner.
=>To view about the game, click the icon in the upper right corner.
=> To rearrange numbers, click button in the upper middle of screen.
Design
The code is easy to read: this is not a bunch of unreadable code lines and the game is fully functional. I think it can be interesting for beginners.
Global Variable Declaration
Dim x, Y, c As Integer
Dim bug As Integer
Dim flag As Integer
Dim
TEMP As Integer
The game is built up from a number of smaller sub-Modules. Each Module provides a distinct purpose. I have identified the Modules below.
CMD_Click( )
SWAP( )
COMPARE()
CMD_Click( )
.
.
.
If CMD(Index).Caption <> "" Then
If the Selected Block is Not in the First Row
If Index > 3 Then
If CMD(Index - 4).Caption = "" Then
Call SWAP(Index, -4)
Call COMPARE
Exit Sub
End If
End If
If the Selected Block is Not in the Last Row
If Index < 12 Then
If CMD(Index + 4).Caption = "" Then
Call SWAP(Index, 4)
Call COMPARE
Exit Sub
End If
End If
If Selected Block is Not in Last Column
If (Index + 1) Mod 4 <> 0 Then
If CMD(Index + 1).Caption = "" Then
Call SWAP(Index, 1)
Call COMPARE
Exit Sub
End If
End If
If the Selected Block is Not in the First Column
If Index Mod 4 <> 0 Then
If CMD(Index - 1).Caption = "" Then
Call SWAP(Index, -1)
Call COMPARE
Exit Sub
End If
End If
End If
.
.
.
SWAP ( )
Module to Swap Selected Number with Empty Block
TEMP = CMD(A).Caption
CMD(A).Caption = CMD(A + B).Caption
CMD(A + B).Caption = TEMP
COMPARE()
Module to Check that All Numbers are Arranged in Order or Not
If so, Show Win Screen
For x = 0 To 14
If CMD(x).Caption = x + 1 Then
flag = flag + 1
ElseIf CMD(x).Caption <> x + 1
Then
flag = 0
Exit Sub
End If
If flag = 14
Then
Load
frmwin
frmwin.Show
End If
Next x
I would like to give credit and thanks to my brother Rohit Soam for constructive criticisms and editing. Thanks, brother.
30-Jan-2001 - Initial Release of Article