請問有人會寫程式語言VB2010的井字遊戲嗎?要怎麼寫加入選擇條件(If... Then)才可以連成一條線?
回答 (1)
'以下9個按鈕
'A1|A2|A3
'B1|B2|B3
'C1|C2|C3
Private Sub A1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles A1.Click
A1.Text = "O"
A1.Enabled = False
wincheck()
End Sub
'...由A1至C3
Private Sub wincheck()
If A1.Text = "X" And A2.Text = "X" And A3.Text = "X" Then
MsgBox("Congratulations", MsgBoxStyle.Information)
'...可以將9個按鈕禁用或者什麼都可以
Else If
'...
'列出所有勝出可能性,包括8個"O"及8個"X"(橫、直、斜)
ElseIf (A1.Text.Length > 0 And A2.Text.Length > 0 And ... And C3.Text.Length > 0) Then '...由A1至C3
MsgBox("Tie", MsgBoxStyle.Exclamation)
'...
'以及1次打和,共17個條件
End If
End Sub
收錄日期: 2021-04-28 13:19:49
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20200208130653AAHwWwl
檢視 Wayback Machine 備份