網路城邦
回本城市首頁 唐老鴨之家
市長:  副市長:
加入本城市推薦本城市加入我的最愛訂閱最新文章
udn城市資訊科技網路分享【唐老鴨之家】城市/討論區/
討論區Excel VBA 字體:
上一個討論主題 回文章列表 下一個討論主題
手動井字遊戲
 瀏覽513|回應0推薦0


等級:6
留言加入好友
Rem === 手動井字遊戲 ===

Rem === 兩個jpg圖檔(o.jpg和x.jpg)要放在同一目錄下 


Dim turn As Boolean


Private Sub CommandButton1_Click()

    Image1.Picture = LoadPicture()

    Image1.Enabled = True

    Image2.Picture = LoadPicture()

    Image2.Enabled = True

    Image3.Picture = LoadPicture()

    Image3.Enabled = True

    Image4.Picture = LoadPicture()

    Image4.Enabled = True

    Image5.Picture = LoadPicture()

    Image5.Enabled = True

    Image6.Picture = LoadPicture()

    Image6.Enabled = True

    Image7.Picture = LoadPicture()

    Image7.Enabled = True

    Image8.Picture = LoadPicture()

    Image8.Enabled = True

    Image9.Picture = LoadPicture()

    Image9.Enabled = True

    CommandButton2.Enabled = True

    CommandButton2.Caption = "O 先下"


    turn = True

End Sub


Private Sub commandbutton2_Click()

    If turn Then

        CommandButton2.Caption = "X 先下"

    Else

        CommandButton2.Caption = "O 先下"

    End If

    turn = Not turn

End Sub


Private Sub Image1_Click()

    o = ThisWorkbook.Path & "\O.jpg"

    X = ThisWorkbook.Path & "\X.jpg"

    CommandButton2.Enabled = False

    If turn Then

        Image1.Picture = LoadPicture(o)

    Else

        Image1.Picture = LoadPicture(X)

    End If

    turn = Not turn

    Image1.Enabled = False

End Sub


Private Sub Image2_Click()

    o = ThisWorkbook.Path & "\O.jpg"

    X = ThisWorkbook.Path & "\X.jpg"

    CommandButton2.Enabled = False

    If turn Then

        Image2.Picture = LoadPicture(o)

    Else

        Image2.Picture = LoadPicture(X)

    End If

    turn = Not turn

    Image2.Enabled = False

End Sub


Private Sub Image3_Click()

    o = ThisWorkbook.Path & "\o.jpg"

    X = ThisWorkbook.Path & "\x.jpg"

    CommandButton2.Enabled = False

    If turn Then

        Image3.Picture = LoadPicture(o)

    Else

        Image3.Picture = LoadPicture(X)

    End If

    turn = Not turn

    Image3.Enabled = False

End Sub


Private Sub Image4_Click()

    o = ThisWorkbook.Path & "\o.jpg"

    X = ThisWorkbook.Path & "\x.jpg"

    CommandButton2.Enabled = False

    If turn Then

        Image4.Picture = LoadPicture(o)

    Else

        Image4.Picture = LoadPicture(X)

    End If

    turn = Not turn

    Image4.Enabled = False

End Sub


Private Sub Image5_Click()

    o = ThisWorkbook.Path & "\o.jpg"

    X = ThisWorkbook.Path & "\x.jpg"

    CommandButton2.Enabled = False

    If turn Then

        Image5.Picture = LoadPicture(o)

    Else

        Image5.Picture = LoadPicture(X)

    End If

    turn = Not turn

    Image5.Enabled = False

End Sub



Private Sub Image6_Click()

    o = ThisWorkbook.Path & "\o.jpg"

    X = ThisWorkbook.Path & "\x.jpg"

    CommandButton2.Enabled = False

    If turn Then

        Image6.Picture = LoadPicture(o)

    Else

        Image6.Picture = LoadPicture(X)

    End If

    turn = Not turn

    Image6.Enabled = False

End Sub



Private Sub Image7_Click()

    o = ThisWorkbook.Path & "\o.jpg"

    X = ThisWorkbook.Path & "\x.jpg"

    CommandButton2.Enabled = False

    If turn Then

        Image7.Picture = LoadPicture(o)

    Else

        Image7.Picture = LoadPicture(X)

    End If

    turn = Not turn

    Image7.Enabled = False

End Sub



Private Sub Image8_Click()

    o = ThisWorkbook.Path & "\o.jpg"

    X = ThisWorkbook.Path & "\x.jpg"

    CommandButton2.Enabled = False

    If turn Then

        Image8.Picture = LoadPicture(o)

    Else

        Image8.Picture = LoadPicture(X)

    End If

    turn = Not turn

    Image8.Enabled = False

End Sub


Private Sub Image9_Click()

    o = ThisWorkbook.Path & "\o.jpg"

    X = ThisWorkbook.Path & "\x.jpg"

    CommandButton2.Enabled = False

    If turn Then

        Image9.Picture = LoadPicture(o)

    Else

        Image9.Picture = LoadPicture(X)

    End If

    turn = Not turn

    Image9.Enabled = False

End Sub
回應 回應給此人 推薦文章 列印 加入我的文摘

引用
引用網址:https://city.udn.com/forum/trackback.jsp?no=58536&aid=4896289