Mata Kuliah pemrograman Komputer with Bapak R. Hengki Rahmanto, ST.M.Eng

game sederhana yang bisa mengasah ketelitian serta otak kita :

Cara pembuatan seperti dibawah ini :

tic tac toe

Yang perlu diperhatikan dalam pembuatannya :

Ada timer 2 yaitu timer1 dan timer2 dengan interval 100

Ada label 5 yaitu label pemain, label score, nama game

Ada image 9 yaitu image1 sampai image9

Ada command button 2 yaitu reset dan exit

Buat folder dalam penyimpanana dg nama “gbr” kemudian buat 2 image ukuran 97 x 87 picsell dengan format .gif

Berikut ini source kodenya

Dim PemainA, M1, M2, M3, M4, M5, M6, M7, M8, M9 As Boolean

Dim PemainB, H1, H2, H3, H4, H5, H6, H7, H8, H9 As Boolean

Dim Poin_A As Integer

Dim Poin_B As Integer

Function ResetAll()

Image1.Enabled = True: Image1.Picture = Nothing

Image2.Enabled = True: Image2.Picture = Nothing

Image3.Enabled = True: Image3.Picture = Nothing

Image4.Enabled = True: Image4.Picture = Nothing

Image5.Enabled = True: Image5.Picture = Nothing

Image6.Enabled = True: Image6.Picture = Nothing

Image7.Enabled = True: Image7.Picture = Nothing

Image8.Enabled = True: Image8.Picture = Nothing

Image9.Enabled = True: Image9.Picture = Nothing

M1 = False: M2 = False: M3 = False: M4 = False

M5 = False: M6 = False: M7 = False: M8 = False: M9 = False

H1 = False: H2 = False: H3 = False: H4 = False

H5 = False: H6 = False: H7 = False: H8 = False: H9 = False

PemainA = True

PemainB = False

End Function

Private Sub Command1_Click()

ResetAll

Poin_A = 0

Poin_B = 0

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Form_Load()

PemainA = True

PemainB = False

End Sub

Private Sub Image1_Click()

If PemainA = True Then

Image1.Picture = LoadPicture(App.Path & “\gbr\a.gif”)

Image1.Enabled = False

M1 = True

PemainB = True

PemainA = False

Exit Sub

End If

If PemainB = True Then

Image1.Picture = LoadPicture(App.Path & “\gbr\b.gif”)

Image1.Enabled = False

H1 = True

PemainA = True

PemainB = False

Exit Sub

End If

End Sub

Private Sub Image2_Click()

If PemainA = True Then

Image2.Picture = LoadPicture(App.Path & “\gbr\a.gif”)

Image2.Enabled = False

M2 = True

PemainB = True

PemainA = False

Exit Sub

End If

If PemainB = True Then

Image2.Picture = LoadPicture(App.Path & “\gbr\b.gif”)

Image2.Enabled = False

H2 = True

PemainA = True

PemainB = False

Exit Sub

End If

End Sub

Private Sub Image3_Click()

If PemainA = True Then

Image3.Picture = LoadPicture(App.Path & “\gbr\a.gif”)

Image3.Enabled = False

M3 = True

PemainB = True

PemainA = False

Exit Sub

End If

If PemainB = True Then

Image3.Picture = LoadPicture(App.Path & “\gbr\b.gif”)

Image3.Enabled = False

H3 = True

PemainA = True

PemainB = False

Exit Sub

End If

End Sub

Private Sub Image4_Click()

If PemainA = True Then

Image4.Picture = LoadPicture(App.Path & “\gbr\a.gif”)

Image4.Enabled = False

M4 = True

PemainB = True

PemainA = False

Exit Sub

End If

If PemainB = True Then

Image4.Picture = LoadPicture(App.Path & “\gbr\b.gif”)

Image4.Enabled = False

H4 = True

PemainA = True

PemainB = False

Exit Sub

End If

End Sub

Private Sub Image5_Click()

If PemainA = True Then

Image5.Picture = LoadPicture(App.Path & “\gbr\a.gif”)

Image5.Enabled = False

M5 = True

PemainB = True

PemainA = False

Exit Sub

End If

If PemainB = True Then

Image5.Picture = LoadPicture(App.Path & “\gbr\b.gif”)

Image5.Enabled = False

H5 = True

PemainA = True

PemainB = False

Exit Sub

End If

End Sub

Private Sub Image6_Click()

If PemainA = True Then

Image6.Picture = LoadPicture(App.Path & “\gbr\a.gif”)

Image6.Enabled = False

M6 = True

PemainB = True

PemainA = False

Exit Sub

End If

If PemainB = True Then

Image6.Picture = LoadPicture(App.Path & “\gbr\b.gif”)

Image6.Enabled = False

H6 = True

PemainA = True

PemainB = False

Exit Sub

End If

End Sub

Private Sub Image7_Click()

If PemainA = True Then

Image7.Picture = LoadPicture(App.Path & “\gbr\a.gif”)

Image7.Enabled = False

M7 = True

PemainB = True

PemainA = False

Exit Sub

End If

If PemainB = True Then

Image7.Picture = LoadPicture(App.Path & “\gbr\b.gif”)

Image7.Enabled = False

H7 = True

PemainA = True

PemainB = False

Exit Sub

End If

End Sub

Private Sub Image8_Click()

If PemainA = True Then

Image8.Picture = LoadPicture(App.Path & “\gbr\a.gif”)

Image8.Enabled = False

M8 = True

PemainB = True

PemainA = False

Exit Sub

End If

If PemainB = True Then

Image8.Picture = LoadPicture(App.Path & “\gbr\b.gif”)

Image8.Enabled = False

H8 = True

PemainA = True

PemainB = False

Exit Sub

End If

End Sub

Private Sub Image9_Click()

If PemainA = True Then

Image9.Picture = LoadPicture(App.Path & “\gbr\a.gif”)

Image9.Enabled = False

M9 = True

PemainB = True

PemainA = False

Exit Sub

End If

If PemainB = True Then

Image9.Picture = LoadPicture(App.Path & “\gbr\b.gif”)

Image9.Enabled = False

H9 = True

PemainA = True

PemainB = False

Exit Sub

End If

End Sub

Private Sub Timer1_Timer()

If M1 = True And M2 = True And M3 = True Then

MsgBox “Pemain A Menang Broww…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_A = Poin_A + 1

Timer1.Enabled = True

End If

If M4 = True And M5 = True And M6 = True Then

MsgBox “Pemain A Menang Broww…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_A = Poin_A + 1

Timer1.Enabled = True

End If

If M7 = True And M8 = True And M9 = True Then

MsgBox “Pemain A Menang Broww…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_A = Poin_A + 1

Timer1.Enabled = True

End If

If M1 = True And M5 = True And M9 = True Then

MsgBox “Pemain A Menang Broww…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_A = Poin_A + 1

Timer1.Enabled = True

End If

If M1 = True And M4 = True And M7 = True Then

MsgBox “Pemain A Menang Broww…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_A = Poin_A + 1

Timer1.Enabled = True

End If

If M3 = True And M5 = True And M7 = True Then

MsgBox “Pemain A Menang Broww…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_A = Poin_A + 1

Timer1.Enabled = True

End If

If M3 = True And M6 = True And M9 = True Then

MsgBox “Pemain A Menang broww…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_A = Poin_A + 1

Timer1.Enabled = True

End If

If M2 = True And M5 = True And M8 = True Then

MsgBox “Pemain A Menang Broww…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_A = Poin_A + 1

Timer1.Enabled = True

End If

If H1 = True And H2 = True And H3 = True Then

MsgBox “Pemain B Menang Broww…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_B = Poin_B + 1

Timer1.Enabled = True

End If

If H4 = True And H5 = True And H6 = True Then

MsgBox “Pemain B Menang Broww…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_B = Poin_B + 1

Timer1.Enabled = True

End If

If H7 = True And H8 = True And H9 = True Then

MsgBox “Pemain B WIN…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_B = Poin_B + 1

Timer1.Enabled = True

End If

If H1 = True And H5 = True And H9 = True Then

MsgBox “Pemain B WIN…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_B = Poin_B + 1

Timer1.Enabled = True

End If

If H1 = True And H4 = True And H7 = True Then

MsgBox “Pemain B WIN…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_B = Poin_B + 1

Timer1.Enabled = True

End If

If H3 = True And H5 = True And H7 = True Then

MsgBox “Pemain B WIN…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_B = Poin_B + 1

Timer1.Enabled = True

End If

If H3 = True And H6 = True And H9 = True Then

MsgBox “Pemain B WIN…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_B = Poin_B + 1

Timer1.Enabled = True

End If

If H2 = True And H5 = True And H8 = True Then

MsgBox “Pemain B Menang BROWW…!”, vbOKOnly

Timer1.Enabled = False

ResetAll

Poin_B = Poin_B + 1

Timer1.Enabled = True

End If

End Sub

Private Sub Timer2_Timer()

lblA.Caption = Poin_A

lblB.Caption = Poin_B

End Sub

Semoga bermanfaat.