shuffle 게임

네크 2014.10.22 22:46:24 *: 폼1
Public Class Form1

Public count As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

CheckButton(Button1, Button2)
CheckButton(Button1, Button5)

CheckSolved()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'
CheckButton(Button2, Button1)
CheckButton(Button2, Button3)
CheckButton(Button2, Button6)

CheckSolved()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

CheckButton(Button3, Button2)
CheckButton(Button3, Button7)
CheckButton(Button3, Button4)

CheckSolved()

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
CheckButton(Button4, Button3)
CheckButton(Button4, Button8)

CheckSolved()

End Sub


Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
CheckButton(Button5, Button1)
CheckButton(Button5, Button5)
CheckButton(Button5, Button9)

CheckSolved()

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
CheckButton(Button6, Button2)
CheckButton(Button6, Button5)
CheckButton(Button6, Button10)
CheckButton(Button6, Button7)

CheckSolved()

End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
CheckButton(Button7, Button3)
CheckButton(Button7, Button6)
CheckButton(Button7, Button11)
CheckButton(Button7, Button8)

CheckSolved()

End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
CheckButton(Button8, Button6)
CheckButton(Button8, Button9)
CheckButton(Button8, Button12)

CheckSolved()

End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
CheckButton(Button9, Button10)
CheckButton(Button9, Button4)
CheckButton(Button9, Button14)

CheckSolved()

End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
CheckButton(Button10, Button11)
CheckButton(Button10, Button1)
CheckButton(Button10, Button8)

CheckSolved()

End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
CheckButton(Button11, Button9)
CheckButton(Button11, Button5)

CheckSolved()

End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
CheckButton(Button12, Button7)
CheckButton(Button12, Button2)
CheckButton(Button12, Button5)

CheckSolved()

End Sub

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
CheckButton(Button13, Button9)
CheckButton(Button13, Button4)

CheckSolved()

End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
CheckButton(Button14, Button13)
CheckButton(Button14, Button10)
CheckButton(Button14, Button15)

CheckSolved()

End Sub

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
CheckButton(Button15, Button14)
CheckButton(Button15, Button11)
CheckButton(Button15, Button16)

CheckSolved()

End Sub

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
CheckButton(Button15, Button12)
CheckButton(Button15, Button15)

CheckSolved()

End Sub

Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
Me.Close()
End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

Dim x = MsgBox("Do you want to Exit ? ", vbYesNo + vbQuestion)
If (x = Windows.Forms.DialogResult.No) Then
e.Cancel = True
End If
End Sub

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
shuffle()
End Sub
End Class

--------------------------------------------------------------------------------
모쥴

Module Module1
Sub CheckButton(ByRef Butt1 As Button, ByRef Butt2 As Button)
If Butt2.Text = "" Then
Butt2.Text = Butt1.Text
Butt1.Text = ""
End If
End Sub

Sub CheckSolved()

If Form1.Button1.Text = "1" And Form1.Button2.Text = "2" And Form1.Button3.Text = "3" And
Form1.Button4.Text = "4" And Form1.Button5.Text = "5" And Form1.Button6.Text = "6" And
Form1.Button7.Text = "7" And Form1.Button8.Text = "8" And Form1.Button9.Text = "9" And
Form1.Button10.Text = "10" And Form1.Button11.Text = "11" And Form1.Button12.Text = "12" And
Form1.Button13.Text = "13" And Form1.Button14.Text = "14" And Form1.Button15.Text = "15" Then
MsgBox("wow , you did it in" & Form1.count & vbInformation, "shuffle")
End If

Form1.count = Form1.count + 1
Form1.Text = "shufle" & Form1.count & "click"
End Sub

Sub shuffle()

Dim a(15), i, j, RN As Integer
Dim flag As Boolean

flag = False
i = 1
a(j) = 1

Do While i <= 15
Randomize()
RN = CInt(Int((15 * Rnd()) + 1))

For j = 1 To i
If (a(j) = RN) Then
flag = True
Exit For
End If
Next

If flag = True Then
flag = False
Else
a(i) = RN
i = i + 1
End If
Loop

Form1.Button1.Text = a(1)
Form1.Button2.Text = a(2)
Form1.Button3.Text = a(3)
Form1.Button4.Text = a(4)
Form1.Button5.Text = a(5)

Form1.Button6.Text = a(6)
Form1.Button7.Text = a(7)
Form1.Button8.Text = a(8)
Form1.Button9.Text = a(9)
Form1.Button10.Text = a(10)

Form1.Button11.Text = a(11)
Form1.Button12.Text = a(12)
Form1.Button13.Text = a(13)
Form1.Button14.Text = a(14)
Form1.Button15.Text = a(15)
Form1.Button16.Text = ""

End Sub
End Module

숫자 빈칸 하나를 이용해 숫자를 차례대로 배열하는 게입 입니다.

 

단순 중복 코드가 상당히 많습니다.

간단하게 줄여서 사용해 보세여.

 

shuffle게임.png