前言:
直到最近我才看到有這活動...,看大家那麼熱烈參予我也不好意思混下去..,雖然沒得參賽但我還是分享一下。
名稱:八后棋
編寫語言:Visual Basic
操作:
使用滑鼠分為左鍵右鍵
左鍵:下棋及輔助性錯誤判斷
右鍵:取消這一顆棋
編寫流程:做好外觀~>想好相關所需資訊~>使用類別編寫相關欄位~>想好相關方法~>添增程序、函數及類別~>測試~>Debug~>測試..
程式說明:(為了那正八邊形,把筆一直轉呀轉呀轉..)
關於這程式我製作了3個類別(c1主物件、c2棋、C關聯List)以方便作存取
c1主物件...(其實前面的c1是在選單的時候會比較快...)
這個類別製作出來的物件會是存取相關座標方法函數的管道。
其方法有Set_Star、Item(預設)、 CleanValue、Check、AllReShow、Win、(其餘皆是Private級),其中Set_Star是為了初始化而設立的,Item則是存取資訊的管道,CleanValue則是清除各個棋資訊Value值,AllReShow是將全部的位置換至回原本應有的圖片,Win是用來判斷是某達成目標。此類別相關內容大致上就這些了。
P.S.你會發現有個Change事件,那個你可以當作沒看到..
Option Explicit
Dim mInformation() As c2棋 '(7,7)
Event Change(M As c2棋)
Public Sub Set_Star(N() As Image)
ReDim mInformation(7, 7)
Dim i As Integer, j As Integer
For i = 0 To 7
For j = 0 To 7
Set mInformation(i, j) = New c2棋
mInformation(i, j).Set_Star Me, N(i, j), i, j
Next
Next
For i = 0 To 7
For j = 0 To 7
mInformation(i, j).Set_Star2 GetList(i, j)
Next
Next
End Sub
Private Function GetList(X As Integer, Y As Integer) As C關聯List
Dim i As Integer, j As Integer
Dim k As New C關聯List
For i = 0 To 7
If i <> Y Then
'行
k.Add Me(X, i)
End If
If i <> X Then
'列
k.Add Me(i, Y)
End If
If i <> X Then
If Checkk(i, Y - X + i) = True Then
'(1,1)
k.Add Me(i, Y - X + i)
End If
If Checkk(i, X + Y - i) = True Then
'(1,-1)
k.Add Me(i, X + Y - i)
End If
End If
Next
Set GetList = k
End Function
Private Function Checkk(X As Integer, Y As Integer) As Boolean
If X < 0 Or Y < 0 Or X > 7 Or Y > 7 Then
Else
Checkk = True
End If
End Function
Function Item(IndexX As Integer, IndexY As Integer) As c2棋
On Error GoTo DoErr:
Set Item = mInformation(IndexX, IndexY)
Exit Function
DoErr:
Err.Raise 0, , "參數錯誤"
End Function
Private Sub Class_Initialize()
ReDim mInformation(7, 7)
ReDim mShapek(6, 6)
End Sub
Private Sub Class_Terminate()
Debug.Print "C1End"
End Sub
Public Sub CleanValue()
Dim i As Integer, j As Integer
For i = 0 To 7
For j = 0 To 7
mInformation(i, j).Value = False
Next
Next
End Sub
Public Sub C2_Change(M As c2棋)
RaiseEvent Change(M)
End Sub
Public Function Check(X As Integer, Y As Integer) As Boolean
Dim k As c2棋
Set k = Me(X, Y)
Dim i As Integer
If k = True Then Exit Function
Check = True
For i = 0 To k.List.Count - 1
If k.List(i).Value = True Then
Check = False
Exit For
End If
Next
End Function
Public Sub AllReShow()
Dim i As Integer, j As Integer
For i = 0 To 7
For j = 0 To 7
Me(i, j).ReShow
Next
Next
End Sub
Public Function Win() As Boolean
Dim i As Integer, j As Integer
Dim sum As Integer
For i = 0 To 7
For j = 0 To 7
If Me(i, j).Value = True Then
sum = sum + 1
End If
Next ..
訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容