‘RIGHT = 1
‘LEFT = 2
‘TOP = 3
‘DOWN = 4
‘
‘The logic for movement should be that the direction and movement of front
‘block must be inherited to the following block
‘
‘The top most element of the Block(Array) should be the head and the element of
‘the Block will be Block(0)
‘
‘The length controls of Block And Direction are always equal ie. Length’Note:
‘=====
‘ In the two player mode, nothing happens when the two snakes
‘ collide. It is so set because, in such a situation, the chance
‘ of one player is lost due to the other.
‘ If this is to be changed just put a nested loop with outer loop counting
‘ the body of one snake and the inner loop counting the other. Then check, whether
‘ the two blocks meet.’=================================================================================
Dim Block(899) As Integer ‘ Snake Blocks
Dim Direction(899) As Integer ‘ Direction Of Each Block
Dim Mode As Boolean ‘ True for Campaign ; False for Classic
Dim Level As Integer ‘ Determines the present level ;
‘ 1 => Classic Mode
‘ 1 – 7 => Campaign Modes
Dim IsObs(899) As Boolean ‘ Determines whether a block is an Obstacle
Dim Head As Integer ‘ The Front Block a.k.a. Snake Head
Dim Length As Integer ‘ Length Of Snake a.k.a. No Of Blocks
Dim TempI As Integer ‘ A Temporary Variable
Dim TempD As Double ‘ Another Temporary Varaible
Dim Food As Integer ‘ Block Containing Food
Dim Score As Single ‘ Displays Score
Dim Eaten As Integer ‘ The No Of Foods Eaten
Dim Game As Boolean ‘ True=> 1 Player ; False => 2 Player
Dim Block2(899) As Integer ‘ Snake Blocks For Player 2
Dim Direction2(899) As Integer ‘ Direction Of Each Block For Player 2
Dim Head2 As Integer ‘ The Front Block a.k.a. Snake Head For Player 2
Dim Length2 As Integer ‘ Length Of Snake a.k.a. No Of Blocks For Player 2
Dim Score2 As Single ‘ Displays Score For Player 2
Dim Eaten2 As Integer ‘ The No Of Foods Eaten For Player 2Function Reset()
For i = 0 To 899
Block(i) = -1 ‘ The values of Block and direction arrays are set
Direction(i) = -1 ‘ to values that is never attainable
Next i
Length = 5
Head = 105
Label1.Caption = Score
Label2.Caption = Score2
For i = 0 To Length
Block(i) = Head – (Length – i)
Direction(i) = 1
Next i
If Game = False Then ‘ Player two settinhs
For i = 0 To 899
Block2(i) = -1 ‘ The values of Block and direction arrays are set
Direction2(i) = -1 ‘ to values that is never attainable
Next i
Length2 = 5
Head2 = 165
For i = 0 To Length2
Block2(i) = Head2 – (Length2 – i)
Direction2(i) = 1
Next i
End If
DrawSnake
MakeFood
Eaten = 0
Eaten2 = 0
If Game = False Then
Image4.Visible = True
Label2.Visible = True
Else
Image4.Visible = False
Label2.Visible = False
End If
End Function
Function SetObstacles() ‘ To Initialise The Obstacles for varoius levels
For i = 0 To 899
IsObs(i) = False
Next i
Select Case (Level) ‘ Obstacles For Level 2
Case 2:
For i = 0 To 29
IsObs(i) = True
IsObs(i + 870) = True
Next i
For i = 0 To 870 Step 30
IsObs(i) = True
IsObs(i + 29) = True
Next
Case 3: ‘ Obstacles For Level 3
For i = 0 To 29
IsObs(i) = True
IsObs(i + 870) = True
Next i
For i = 0 To 870 Step 30
IsObs(i) = True
IsObs(i + 29) = True
Next
For i = 124 To 145
IsObs(i) = True
IsObs(i + 30) = True
IsObs(i + 630) = True
IsObs(i + 600) = True
Next i
Case 4: ‘ Obstacles For Level 4
For i = 0 To 29
IsObs(i) = True
IsObs(i + 870) = True
Next i
For i = 0 To 870 Step 30
IsObs(i) = True
IsObs(i + 29) = True
Next
For i = 124 To 129
IsObs(i) = True
IsObs(i + 16) = True
Next i
For i = 124 To 754 Step 30
IsObs(i) = True
IsObs(i + 21) = True
Next
For i = 754 To 775
IsObs(i) = True
Next i
Case 5: ‘ Obstacles For Level 5
For i = 0 To 29
IsObs(i) = True
IsObs(i + 870) = True
Next i
For i = 0 To 870 Step 30
IsObs(i) = True
IsObs(i + 29) = True
Next
For i = 7 To 427 Step 30
IsObs(i) = True
IsObs(i + 15) = True
Next
For i = 464 To 884 Step 30
IsObs(i) = True
IsObs(i + 1) = True
Next
Case 6:
For i = 0 To 29
IsObs(i) = True
IsObs(i + 870) = True
Next i
For i = 0 To 870 Step 30
IsObs(i) = True
IsObs(i + 29) = True
Next
For i = 270 To 285
IsObs(i) = True
Next i
For i = 732 To 749
IsObs(i) = True
Next i
For i = 285 To 675 Step 30
IsObs(i) = True
Next i
For i = 462 To 732 Step 30
IsObs(i) = True
Next i
Case 7:
For i = 93 To 783 Step 30
IsObs(i + 2) = True
IsObs(i + 4) = True
IsObs(i + 19) = True
IsObs(i + 21) = True
IsObs(i + 23) = True
IsObs(i) = True
Next i
For i = 219 To 230
IsObs(i) = True
IsObs(i + 480) = True
Next i
For i = 0 To 29
IsObs(i) = True
IsObs(i + 870) = True
Next i
For i = 0 To 870 Step 30
IsObs(i) = True
IsObs(i + 29) = True
Next
End Select
For i = 0 To 899
If IsObs(i) = True Then
TableBlock(i).Picture = Obs.Picture
End If
Next i
End Function
Function TABLE() ‘ The function paints the table
For i = 0 To 899
If (i <> Food) And (IsObs(i) = False) Then
TableBlock(i).Picture = BBlock.Picture
End If
Next i
End Function
Function DrawSnake() ‘ The function paints the snake
For i = 0 To Length
TableBlock(Block(i)).Picture = SBlock.Picture
Next i
‘===========================================================================
If Game = False Then
For i = 0 To Length2
TableBlock(Block2(i)).Picture = IM2P.Picture
Next i
End If
End Function
Function MoveSnake() ‘ The function moves the snake in the table
Select Case (Direction(Length))
Case 1
For i = 0 To (Length – 1)
Block(i) = Block(i + 1)
Direction(i) = Direction(i + 1)
Next i
Block(Length) = Block(Length) + 1
TempI = Block(Length) / 30
TempD = Block(Length) / 30
TempD = TempD – TempI
If TempD = 0 Then
Block(Length) = Block(Length) – 30
End If
Case 2
For i = 0 To (Length – 1)
Block(i) = Block(i + 1)
Direction(i) = Direction(i + 1)
Next i
Block(Length) = Block(Length) – 1
TempI = (Block(Length) + 1) / 30
TempD = (Block(Length) + 1) / 30
TempD = TempD – TempI
If TempD = 0 Then
Block(Length) = Block(Length) + 30
End If
Case 3
For i = 0 To (Length – 1)
Block(i) = Block(i + 1)
Direction(i) = Direction(i + 1)
Next i
Block(Length) = Block(Length) – 30
If (Block(Length) + 30) < 30 Then
Block(Length) = Block(Length) + 900
End If
Case 4
For i = 0 To (Length – 1)
Block(i) = Block(i + 1)
Direction(i) = Direction(i + 1)
Next i
Block(Length) = Block(Length) + 30
If (Block(Length) – 30) > 869 Then
Block(Length) = Block(Length) – 900
End If
End Select
‘==========================================================================
If Game = False Then ‘ Two Player Controls
Select Case (Direction2(Length2))
Case 1
For i = 0 To (Length2 – 1)
Block2(i) = Block2(i + 1)
Direction2(i) = Direction2(i + 1)
Next i
Block2(Length2) = Block2(Length2) + 1
TempI = Block2(Length2) / 30
TempD = Block2(Length2) / 30
TempD = TempD – TempI
If TempD = 0 Then
Block2(Length2) = Block2(Length2) – 30
End If
Case 2
For i = 0 To (Length2 – 1)
Block2(i) = Block2(i + 1)
Direction2(i) = Direction2(i + 1)
Next i
Block2(Length2) = Block2(Length2) – 1
TempI = (Block2(Length2) + 1) / 30
TempD = (Block2(Length2) + 1) / 30
TempD = TempD – TempI
If TempD = 0 Then
Block2(Length2) = Block2(Length2) + 30
End If
Case 3
For i = 0 To (Length2 – 1)
Block2(i) = Block2(i + 1)
Direction2(i) = Direction2(i + 1)
Next i
Block2(Length2) = Block2(Length2) – 30
If (Block2(Length2) + 30) < 30 Then
Block2(Length2) = Block2(Length2) + 900
End If
Case 4
For i = 0 To (Length2 – 1)
Block2(i) = Block2(i + 1)
Direction2(i) = Direction2(i + 1)
Next i
Block2(Length2) = Block2(Length2) + 30
If (Block2(Length2) – 30) > 869 Then
Block2(Length2) = Block2(Length2) – 900
End If
End Select
End If
End Function
Private Sub E_Click()
End
End Sub
Private Sub E_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
E.Picture = ED.Picture
End Sub
Private Sub E_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
E.Picture = EU.Picture
End Sub
Private Sub classic_Click()
classic.Checked = True
Mode = False
Level = 1
cpn.Checked = False
SetObstacles
Score = 0
Score2 = 0
Reset
End Sub
Private Sub cpn_Click()
cpn.Checked = True
Mode = True Lanjutkan membaca