オセロのゲーム
@@ -0,0 +1,25 @@ | ||
1 | +Public Class FormDispacher | |
2 | + | |
3 | + Private Shared _instance As New FormDispacher | |
4 | + Public Shared Function GetInstance() As FormDispacher | |
5 | + Return _instance | |
6 | + End Function | |
7 | + | |
8 | + | |
9 | + Private WithEvents _frmCode As frmCodes | |
10 | + | |
11 | + Public Sub ShowCode(ByVal board As Board) | |
12 | + If _frmCode Is Nothing Then | |
13 | + _frmCode = New frmCodes | |
14 | + _frmCode.Show() | |
15 | + End If | |
16 | + _frmCode.Board = board | |
17 | + _frmCode.ShowCodes() | |
18 | + | |
19 | + End Sub | |
20 | + | |
21 | + Private Sub _frmCode_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles _frmCode.FormClosed | |
22 | + _frmCode = Nothing | |
23 | + End Sub | |
24 | + | |
25 | +End Class |
@@ -1,6 +1,6 @@ | ||
1 | 1 | Public Class frmMain |
2 | 2 | Private Property CellSize As Integer = 40 |
3 | - Private _frmCode As New frmCodes | |
3 | + | |
4 | 4 | Private _nowBoard As New Board |
5 | 5 | Private _computerAIPlayer1 As computerPlayer |
6 | 6 | Private _computerAIPlayer2 As computerPlayer |
@@ -82,10 +82,8 @@ | ||
82 | 82 | End Sub |
83 | 83 | |
84 | 84 | Private Sub frmReflesh() |
85 | - If _nowBoard IsNot Nothing AndAlso _frmCode IsNot Nothing AndAlso Not _frmCode.IsDisposed Then | |
86 | - _frmCode.Board = _nowBoard | |
87 | - _frmCode.ShowCodes() | |
88 | - End If | |
85 | + | |
86 | + FormDispacher.GetInstance.ShowCode(_nowBoard) | |
89 | 87 | PictureBox1.Invalidate() |
90 | 88 | End Sub |
91 | 89 | Private Sub TurnChangeAndDecideGameWinner() |
@@ -117,7 +115,7 @@ | ||
117 | 115 | |
118 | 116 | |
119 | 117 | Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load |
120 | - _frmCode.Board = _nowBoard | |
118 | + FormDispacher.GetInstance.ShowCode(_nowBoard) | |
121 | 119 | _computerAIPlayer1 = New computerPlayer |
122 | 120 | _computerAIPlayer2 = New computerPlayer |
123 | 121 |
@@ -209,7 +207,7 @@ | ||
209 | 207 | |
210 | 208 | Private Sub btnCodes_Click(sender As System.Object, e As System.EventArgs) Handles btnCodes.Click |
211 | 209 | |
212 | - _frmCode.Show() | |
210 | + FormDispacher.GetInstance.ShowCode(_nowBoard) | |
213 | 211 | |
214 | 212 | End Sub |
215 | 213 | End Class |
@@ -8,7 +8,11 @@ | ||
8 | 8 | End Sub |
9 | 9 | |
10 | 10 | Public Sub ShowCodes() |
11 | - lstCodes.DataSource = Board.History | |
11 | + Dim history As IList(Of Point) = New List(Of Point) | |
12 | + If Board IsNot Nothing Then | |
13 | + history = Board.History | |
14 | + End If | |
15 | + lstCodes.DataSource = history | |
12 | 16 | lstCodes.DisplayMember = "ToString" |
13 | 17 | End Sub |
14 | 18 |