Home > Software engineering >  Vb a great god, please help
Vb a great god, please help

Time:11-20

This is the code for the design of 2048 games under the great god, please help me translate what is the purpose of which is a part of several modules like this thank you
Option Explicit


Dim BoxValue (3, 3) As an Integer 'grid numerical
Dim Score As Long 'Score


'keys
Private Sub Form_KeyDown (KeyCode As an Integer, Shift the As an Integer)
The Select Case KeyCode
Case vbKeyLeft
Call MoveBox (1)
Case vbKeyRight
Call MoveBox (2)
Case vbKeyUp
Call MoveBox (3)
Case vbKeyDown
Call MoveBox (4)
Case vbKeySpace
Call NewGame
End the Select
End Sub


Private Sub Form_Load ()
Me. Width=8000
Me. Height=9000
Me. The Caption="2048"


Picture1. Move (Me) ScaleWidth - 6810)/2, 1200, 6810, 6810
Picture1. Appearance=0
Picture1. BackColor=RGB (128, 128, 128)
Picture1. FontSize=32
Picture1. AutoRedraw=True
FontSize=Picture1. FontSize


Label1. AutoSize=True
Label1. Move the Picture1. Left, Picture1. Left
Label1. FontSize=24
Label1. BorderStyle=0
Label1="score: 0
"



Call NewGame
End Sub


Game
'Private Sub NewGame ()
Dim R As an Integer, C As Integer
Dim L As an Integer, T As Integer


For R=1 To 4
For C=1 To 4
L=(C - 1) * 110 + 10
T=(R - 1) * 110 + 10
Picture1. Line (L, T) - (L + 100, + 100 T), RGB (200, 200, 200), BF
BoxValue (C - R - 1, 1)=0
Next
Next


NewBox
NewBox
End Sub


'a grid
Private Sub DrawBox (ByVal N As an Integer, ByVal R As an Integer, ByVal C As an Integer)
Dim L As an Integer, T As Integer
Dim tmpStr As String
Dim W As Integer


L=C * 110 + 10
T=R * 110 + 10


If N=0 Then
Picture1. Line (L, T) - (L + 100, + 100 T), RGB (200, 200, 200), BF
The Else
Picture1. Line (L, T) - (L + 100, + 100 T), BoxColor (N), BF
TmpStr=Trim (Str (N))
W=TextWidth (" 0 ")/Screen. TwipsPerPixelX
Picture1. CurrentX=L + (100 - TextWidth (tmpStr)/Screen. TwipsPerPixelX)/2 - W
Picture1. CurrentY=T + (100 - TextHeight (tmpStr)/Screen. TwipsPerPixelY)/2


Picture1. Print N
End the If


BoxValue (R, C)=N
End Sub

'
mobile gridPrivate Sub MoveBox (ByVal Fx As Integer)
Dim B As an Integer, N As an Integer, S As Integer
Dim R As an Integer, C As an Integer, K As Integer
Dim bMove As Boolean




If Fx & lt; 3 Then 'move around
If Fx=1 Then
B=1: N=3: S=1
The Else
B=2: N=0: S=1
End the If


For R=0 To 3
K=IIf (Fx=1, 0, 3)
For C=B To N Step S
If BoxValue (R, C) & gt; 0 Then
If (BoxValue (R, C)=BoxValue (R, K)) Then
DrawBox BoxValue (R, C) * 2, R, K
DrawBox 0, R, C
Score=+ BoxValue Score (R, K)
If BoxValue (R, K)=2048 Then
MsgBox "wow! Amazing! Admire you ~ ", vbInformation
End the If
BMove=True
The Else
If BoxValue (R, K) & gt; 0 Then
K=K + S
If K & lt;> Then C
DrawBox BoxValue (R, C), R, K
DrawBox 0, R, C
BMove=True
End the If
The Else
DrawBox BoxValue (R, C), R, K
DrawBox 0, R, C
BMove=True
End the If
End the If
End the If
Next C
Next R
Move up and down the Else '
If Fx=3 Then
B=1: N=3: S=1
The Else
B=2: N=0: S=1
End the If


For C=0 To 3
K=IIf (Fx=3, 0, 3)
For R=B To N Step S
If BoxValue (R, C) & gt; 0 Then
If BoxValue (R, C)=BoxValue (K, C) Then
DrawBox BoxValue (R, C) * 2, K, C
DrawBox 0, R, C
Score=Score + BoxValue (K, C)
If BoxValue (R, K)=2048 Then
MsgBox "wow! Amazing! Admire you ~ ", vbInformation
End the If
BMove=True
The Else
If BoxValue (K, C) & gt; 0 Then
K=K + S
If K & lt;> R Then
DrawBox BoxValue (R, C), K, C
DrawBox 0, R, C
BMove=True
End the If
The Else
DrawBox BoxValue (R, C), K, C
DrawBox 0, R, C
BMove=True
End the If
End the If
End the If
Next R
Next C
End the If


If bMove Then
Label1="score:" & amp; Score
NewBox


'check the stand-off
For R=0 To 3
For C=0 To 3
If BoxValue (R, C)=0 Then the Exit Sub
If R & lt; 3 Then If BoxValue (R, C)=BoxValue (R + 1, C) Then the Exit Sub
If C & lt; 3 Then If BoxValue (R, C)=BoxValue (R, C + 1) Then the Exit Sub
Next
Next


MsgBox "no way to go ~ ~ ~ good luck next time!" , vbInformation


Call NewGame
End the If
End Sub



'to generate new squaresPrivate Sub NewBox ()
Dim R As an Integer, C As Integer


Randomize
R=Int (Rnd * 4)
C=Int (Rnd * 4)


The Do While BoxValue (R, C) & gt; 0
R=Int (Rnd * 4)
C=Int (Rnd * 4)
Loop


BoxValue (R, C)=2
DrawBox 2, R, C
End Sub


Color 'squares
Private Function BoxColor (ByVal N As an Integer) As Long
The Select Case N
Case 2
BoxColor=& amp; HC0E0FF
Case 4
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related