0% found this document useful (0 votes)
48 views

Bab I

This document provides instructions on how to create a puzzle game in Visual Basic 6 (VB6). It includes details on setting up the VB6 project, designing the user interface with 9 command buttons and labels, and includes the full source code to initialize the puzzle, randomly shuffle the tiles, and enable clicking and swapping of tiles to solve the puzzle. The code demonstrates how to track the number of moves and change button colors as tiles are moved.

Uploaded by

Adam Ahmadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Bab I

This document provides instructions on how to create a puzzle game in Visual Basic 6 (VB6). It includes details on setting up the VB6 project, designing the user interface with 9 command buttons and labels, and includes the full source code to initialize the puzzle, randomly shuffle the tiles, and enable clicking and swapping of tiles to solve the puzzle. The code demonstrates how to track the number of moves and change button colors as tiles are moved.

Uploaded by

Adam Ahmadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

ChanelPacitan.blogspot.

com
Menyediakan Informasi dan
Pengetahuan
Seputar dunia TIK
BAB I Kunjngi Ya.....
mailto:[email protected]?subject=I
Visual Basic 6 nformasi dan Pengetahuan

Launching ChanelPacitan
Sekarang kita akan belajar cara membuat Game Puzzle dengan VB6
Full Versio / Portable sama saja

Buka VB6.exe
Klik New Project
Beri nama Project nya (PrjPuzzle)

Next Step
Tambahkan 1 Form beri nama FrmPuzzle
Rincian Form di bawah

Komponen Name Caption Keterangan Lain


Form1 frmPuzzle Puzzle -
Command1 P1 - -
Command2 P2 - -
Command3 P3 - -
Command4 P4 - -
Command5 P5 - -
Command6 P6 - -
Command7 P7 - -
Command8 P8 - -
Command9 P9 - -
PictureBox1 Picture1 - Wrna Background
&H00C0FFFF&
Label1 Label Jmlh Pindah Warna Merah
Label2 LblJmlPIndah 0 -
Command10 CmdAcak Acak -
Module ModFunction

Untuk Penataan Form Kurang lebih seperti Gambar di bawah


Untuk kode Bisa di lihat bawah ini
Source Code untuk Form
Sebelum anda memasukkan Code di bawah kepada Form pastikan name
nya sudah cocok pada yang di atas

Private Sub CmdAcak_Click()


LblJmlPIndah.Caption = 0
Dim a, b, c, d, e, f, g, h, i As Variant
a = arr(0, 1)
b = arr(1, 1)
c = arr(0, 2)
d = arr(1, 2)
e = arr(2, 1)
f = arr(2, 2)
g = arr(1, 0)
h = arr(2, 0)
i = arr(0, 0)

arr(0, 0) = f
arr(2, 2) = h
arr(0, 1) = c
arr(1, 2) = a
arr(2, 0) = g
arr(1, 1) = d
arr(2, 1) = b
arr(0, 2) = i
arr(1, 0) = e

P1.Caption = arr(0, 0)
P2.Caption = arr(0, 1)
P3.Caption = arr(0, 2)
P4.Caption = arr(1, 0)
P5.Caption = arr(1, 1)
P6.Caption = arr(1, 2)
P7.Caption = arr(2, 0)
P8.Caption = arr(2, 1)
P9.Caption = arr(2, 2)

If P1.Caption = "" Then P1.BackColor = &HFF& Else P1.BackColor =


&H8000000F
If P2.Caption = "" Then P2.BackColor = &HFF& Else P2.BackColor =
&H8000000F
If P3.Caption = "" Then P3.BackColor = &HFF& Else P3.BackColor =
&H8000000F
If P4.Caption = "" Then P4.BackColor = &HFF& Else P4.BackColor =
&H8000000F
If P5.Caption = "" Then P5.BackColor = &HFF& Else P5.BackColor =
&H8000000F
If P6.Caption = "" Then P6.BackColor = &HFF& Else P6.BackColor =
&H8000000F
If P7.Caption = "" Then P7.BackColor = &HFF& Else P7.BackColor =
&H8000000F
If P8.Caption = "" Then P8.BackColor = &HFF& Else P8.BackColor =
&H8000000F
If P9.Caption = "" Then P9.BackColor = &HFF& Else P9.BackColor =
&H8000000F

End Sub

Private Sub P1_Click()


If P2.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Kanan(P1, P2)

End If
If P4.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Bawah(P1, P4)
End If
End Sub

Private Sub P2_Click()


If P1.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Kiri(P1, P2)
End If
If P3.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Kanan(P2, P3)
End If
If P5.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Bawah(P2, P5)
End If
End Sub

Private Sub P3_Click()


If P2.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Kiri(P2, P3)
End If
If P6.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Bawah(P3, P6)
End If
End Sub

Private Sub P4_Click()


If P5.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Kanan(P4, P5)
End If
If P1.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Atas(P1, P4)
End If
If P7.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Bawah(P4, P7)
End If
End Sub

Private Sub P5_Click()


If P2.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Atas(P2, P5)
End If
If P8.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Bawah(P5, P8)
End If
If P4.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Kiri(P4, P5)
End If
If P6.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Kanan(P5, P6)
End If
End Sub

Private Sub P6_Click()


If P5.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Kiri(P5, P6)
End If
If P3.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Atas(P3, P6)
End If
If P9.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Bawah(P6, P9)
End If
End Sub

Private Sub P7_Click()


If P8.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Kanan(P7, P8)
End If
If P4.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Atas(P4, P7)
End If
End Sub

Private Sub P8_Click()


If P7.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Kiri(P7, P8)
End If
If P9.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Kanan(P8, P9)
End If
If P5.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Atas(P5, P8)
End If
End Sub

Private Sub P9_Click()


If P8.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Kiri(P8, P9)
End If
If P6.Caption = "" Then
LblJmlPIndah.Caption = LblJmlPIndah.Caption + 1
Call Pindah_Atas(P6, P9)
End If
End Sub
Private Sub Form_Load()
LblJmlPIndah.Caption = 0
arr(0, 0) = 1
arr(0, 1) = 2
arr(0, 2) = 3
arr(1, 0) = 4
arr(1, 1) = 5
arr(1, 2) = 6
arr(2, 0) = 7
arr(2, 1) = 8
arr(2, 2) = ""

P1.Caption = arr(0, 0)
P2.Caption = arr(0, 1)
P3.Caption = arr(0, 2)
P4.Caption = arr(1, 0)
P5.Caption = arr(1, 1)
P6.Caption = arr(1, 2)
P7.Caption = arr(2, 0)
P8.Caption = arr(2, 1)
P9.Caption = arr(2, 2)

P9.BackColor = &HFF&
End Sub

Klik dua kali Pada Module dan isikan Code di bawah ini ke Module
Public arr(0 To 2, 0 To 2) As Variant
Function Pindah_Kiri(P1 As CommandButton, P2 As CommandButton)
P1.Caption = P2.Caption
P2.Caption = ""
P2.BackColor = &HFF&
P1.BackColor = &H8000000F
End Function
Function Pindah_Kanan(P1 As CommandButton, P2 As CommandButton)
P2.Caption = P1.Caption
P1.Caption = ""
P1.BackColor = &HFF&
P2.BackColor = &H8000000F
End Function
Function Pindah_Atas(P3 As CommandButton, P4 As CommandButton)
P3.Caption = P4.Caption
P4.Caption = ""
P4.BackColor = &HFF&
P3.BackColor = &H8000000F
End Function
Function Pindah_Bawah(P3 As CommandButton, P4 As CommandButton)
P4.Caption = P3.Caption
P3.Caption = ""
P3.BackColor = &HFF&
P4.BackColor = &H8000000F
End Function

Apabila terjadi debug dapat bertanya atau berkomentar di


ChanelPacitan.blogspot.com

You might also like