2009年3月9日 星期一

井字遊戲 2009/03/09版

image

image

'2009/03/09版

Public Class Form1
    Dim btn(9) As Button, i As Integer
    Dim oxFlag As Boolean
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        oxFlag = True
        btn(1) = Button1
        btn(2) = Button2
        btn(3) = Button3
        btn(4) = Button4
        btn(5) = Button5
        btn(6) = Button6
        btn(7) = Button7
        btn(8) = Button8
        btn(9) = Button9

        For i = 1 To 9
            With btn(i)
                .Text = Mid((btn(i).Name), Len((btn(i).Name)), 1)
                .Height = .Width
                .Font = New Font("Arial", 20)
                .Left = 10 + .Width * ((i - 1) Mod 3)
                .Top = 10 + .Height * ((i - 1) \ 3)
            End With
        Next

        Me.Width = 3 * btn(1).Width + 30
        Label1.Top = 3 * btn(1).Height + 30

        Button10.Top = 3 * btn(1).Height + 30

        Me.Height = 3 * btn(1).Height + 100
        Button10.Left = Me.Width - Button10.Width - 20
        Button10.Text = "重新開始"
    End Sub

    Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click
        Dim no = Mid(CType(sender, Button).Name, Len(CType(sender, Button).Name), 1)
        If oxFlag = True Then
            btn(no).Text = "○"
        Else
            btn(no).Text = "×"
        End If
        oxFlag = Not oxFlag
    End Sub
End Class

沒有留言:

張貼留言