Public Class clsField Private Const CARD_WIDTH As Integer = 80 Private Const CARD_HEIGHT As Integer = 120 Public Shared offset As Integer = 0 Private Shared field(24) As clsCard.typCard Private Shared nonbrush As Drawing.Brush = Drawing.Brushes.LimeGreen Private Shared selpen As Drawing.Pen = New Pen(Color.Red, 3.0) Private Shared failed As Boolean = False Shared Sub setup(ByVal card As clsCard) failed = False Dim index As Integer = 0 For y As Integer = 0 To 4 For x As Integer = 0 To 4 field(index) = card.nextCard index += 1 Next Next End Sub Shared Sub draw(ByVal g As Graphics, ByVal selpnt As Integer) Dim idx As Integer = 0 Dim yp As Integer = 10 Dim xp As Integer For y As Integer = 0 To 4 xp = 10 For x As Integer = 0 To 4 If field(idx).num > 0 Then g.DrawImage(field(idx).img, New Rectangle(xp + offset, yp, CARD_WIDTH, CARD_HEIGHT)) End If xp += 84 idx += 1 Next yp += 124 Next If selpnt <> -1 Then xp = (selpnt Mod 5) * CARD_WIDTH + 10 yp = (selpnt \ 5) * CARD_HEIGHT + 10 g.DrawRectangle(selpen, xp - 2 + offset, yp - 2, CARD_WIDTH + 4, CARD_HEIGHT + 4) End If If failed Then drawFailed(g) End If End Sub Shared Sub drawFailed(ByVal g As Graphics) g.DrawString("FAILED!!", New Font("Arial Black", 48), Brushes.Yellow, New Point(offset + 60, 280)) End Sub Shared Sub discard(ByVal pnt() As Integer) Dim tmp As Integer = pnt(0) If pnt(1) < pnt(0) Then pnt(0) = pnt(1) pnt(1) = tmp End If Dim i As Integer For i = pnt(1) To 23 field(i) = field(i + 1) Next field(24).num = -1 For i = pnt(0) To 23 field(i) = field(i + 1) Next field(24).num = -1 End Sub Shared Sub drawcard(ByVal card As clsCard) For i As Integer = 23 To 24 field(i) = card.nextCard Next End Sub Shared Function judge(ByVal pnt() As Integer) As Boolean Dim ret As Boolean = False If field(pnt(0)).num = field(pnt(1)).num Then ret = True End If Return ret End Function Shared Function isFailed() As Boolean Return failed End Function Shared Function checkFail() As Boolean Dim tmp(6, 6) As Integer Dim idx As Integer Dim x As Integer = 1 Dim y As Integer = 1 Dim n As Integer idx = 0 For y = 1 To 5 For x = 1 To 5 tmp(x, y) = field(idx).num idx += 1 Next Next For y = 1 To 5 For x = 1 To 5 n = tmp(x, y) If n <= 0 Then failed = True Return True End If If n = tmp(x - 1, y) OrElse n = tmp(x + 1, y) _ OrElse n = tmp(x - 1, y - 1) OrElse n = tmp(x, y - 1) OrElse n = tmp(x + 1, y - 1) _ OrElse n = tmp(x - 1, y + 1) OrElse n = tmp(x, y + 1) OrElse n = tmp(x + 1, y + 1) Then Return False End If Next Next failed = True Return True End Function Shared Sub drawone(ByVal g As Graphics, ByVal idx As Integer, ByVal sel As Boolean) Dim xp As Integer = (idx Mod 5) * (CARD_WIDTH + 4) + 10 Dim yp As Integer = (idx \ 5) * (CARD_HEIGHT + 4) + 10 g.FillRectangle(nonbrush, xp - 3 + offset, yp - 3, CARD_WIDTH + 6, CARD_HEIGHT + 6) If field(idx).num > 0 Then g.DrawImage(field(idx).img, New Rectangle(xp + offset, yp, CARD_WIDTH, CARD_HEIGHT)) If sel Then g.DrawRectangle(selpen, xp - 1 + offset, yp - 1, CARD_WIDTH + 1, CARD_HEIGHT + 1) End If End If End Sub