Public Class Form1 Dim card As clsCard Dim selcard(1) As Integer Dim selindex As Integer Dim selflg As Boolean Dim score As Integer = 0 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load card = New clsCard clsField.offset = 154 selcard(0) = -1 selcard(1) = -1 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click score = 0 nextStage() End Sub Private Sub nextStage() card.reset() card.shuffle() clsField.setup(card) selindex = 0 selflg = False selcard(0) = -1 Label1.Text = score.ToString Me.Refresh() End Sub Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown Dim xp As Integer Dim yp As Integer If clsField.isFailed Then Exit Sub Dim index As Integer = clsField.calcPos(e.X, e.Y, xp, yp) If index < 0 Then Exit Sub If Not selflg Then If clsField.cardon(index) Then selflg = True selindex = 0 selcard(0) = index Using g As Graphics = Me.CreateGraphics clsField.drawone(g, index, True) End Using End If Else If index = selcard(selindex) Then selflg = False selcard(selindex) = -1 Using g As Graphics = Me.CreateGraphics clsField.drawone(g, index, False) End Using Else Dim xx As Integer = selcard(selindex) Mod 5 Dim yy As Integer = selcard(selindex) \ 5 selindex = 1 - selindex selcard(selindex) = index If Math.Abs(xp - xx) <= 1 AndAlso Math.Abs(yp - yy) <= 1 _ AndAlso clsField.judge(selcard) Then clsField.discard(selcard) clsField.drawcard(card) selflg = False selcard(selindex) = -1 score += 3 Label1.Text = score.ToString If card.restCard() <= 0 AndAlso Not clsField.cardon(0) Then nextStage() Else clsField.checkFail() End If Me.Refresh() Else Using g As Graphics = Me.CreateGraphics clsField.drawone(g, selcard(1 - selindex), False) clsField.drawone(g, index, True) selcard(1 - selindex) = -1 End Using End If End If End If End Sub Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Using g As Graphics = Me.CreateGraphics clsField.draw(g, selcard(selindex)) End Using End Sub End Class