2009年3月5日 星期四

○×遊戲 - 雛型版

image

'○×遊戲 - 雛型版
Public Class Form1
    Dim btn(9) As Button
    Dim i
    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)
                .Height = .Width
                .Text = ""
                .Font = New Font("新細明體", 50)
                .Left = 15 + ((i - 1) Mod 3) * .Width
                .Top = 15 + ((i - 1) \ 3) * .Height
            End With
        Next
    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
        If oxFlag = True Then
            CType(sender, Button).Text = "○"
        Else
            CType(sender, Button).Text = "×"
        End If
        If Button1.Text = "○" And Button2.Text = "○" And Button3.Text = "○" Then Label1.Text = "○贏了!"
        If Button4.Text = "○" And Button5.Text = "○" And Button6.Text = "○" Then Label1.Text = "○贏了!"
        If Button7.Text = "○" And Button8.Text = "○" And Button9.Text = "○" Then Label1.Text = "○贏了!"

        If Button1.Text = "○" And Button4.Text = "○" And Button7.Text = "○" Then Label1.Text = "○贏了!"
        If Button2.Text = "○" And Button5.Text = "○" And Button8.Text = "○" Then Label1.Text = "○贏了!"
        If Button3.Text = "○" And Button6.Text = "○" And Button9.Text = "○" Then Label1.Text = "○贏了!"

        If Button1.Text = "○" And Button5.Text = "○" And Button9.Text = "○" Then Label1.Text = "○贏了!"
        If Button3.Text = "○" And Button5.Text = "○" And Button7.Text = "○" Then Label1.Text = "○贏了!"

        If Button1.Text = "×" And Button2.Text = "×" And Button3.Text = "×" Then Label1.Text = "×贏了!"
        If Button4.Text = "×" And Button5.Text = "×" And Button6.Text = "×" Then Label1.Text = "×贏了!"
        If Button7.Text = "×" And Button8.Text = "×" And Button9.Text = "×" Then Label1.Text = "×贏了!"

        If Button1.Text = "×" And Button4.Text = "×" And Button7.Text = "×" Then Label1.Text = "×贏了!"
        If Button2.Text = "×" And Button5.Text = "×" And Button8.Text = "×" Then Label1.Text = "×贏了!"
        If Button3.Text = "×" And Button6.Text = "×" And Button9.Text = "×" Then Label1.Text = "×贏了!"

        If Button1.Text = "×" And Button5.Text = "×" And Button9.Text = "×" Then Label1.Text = "×贏了!"
        If Button3.Text = "×" And Button5.Text = "×" And Button7.Text = "×" Then Label1.Text = "×贏了!"

        oxFlag = Not oxFlag
    End Sub
End Class

沒有留言:

張貼留言