-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainForm.frm
374 lines (261 loc) · 8.14 KB
/
MainForm.frm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} MainForm
Caption = "Game of Life Controls"
ClientHeight = 1695
ClientLeft = 45
ClientTop = 375
ClientWidth = 6495
OleObjectBlob = "MainForm.frx":0000
StartUpPosition = 1 'CenterOwner
End
Attribute VB_Name = "MainForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'
' Jon Conway's Game of Life
'
' Coded by Richard Kelley
'
' May 2012
'
Dim Gen_Count As Integer
Dim Grid As Variant
Dim Grid2 As Variant
Dim Speed As Integer
Dim StopNow As Boolean
Dim Model As Integer
Dim Cont As Boolean
Private Sub ContinueBox_Click()
If ContinueBox.Value = True Then
Cont = True
ElseIf ContinueBox.Value = False Then
Cont = False
End If
End Sub
Private Sub Exit_Button_Click()
Me.Hide
End Sub
Private Sub Models_Dropdown_Change()
Sheet1.Cells.ClearContents
Gen_Count = 0
Me.Display_Gen.Caption = Gen_Count
Me.Repaint
If Models_Dropdown.Value = "Glider" Then
Model = 1
ElseIf Models_Dropdown.Value = "Tumbler" Then
Model = 2
ElseIf Models_Dropdown.Value = "Shooter" Then
Model = 3
Else
Model = 0
End If
End Sub
Private Sub Next_Button_Click()
GameOfLife
Gen_Count = Gen_Count + 1
Me.Display_Gen.Caption = Gen_Count
Me.Repaint
End Sub
Private Sub Reset_Button_Click()
Sheet1.Cells.ClearContents
Gen_Count = 0
Me.Display_Gen.Caption = Gen_Count
Me.Repaint
End Sub
Private Sub Speed_DropDown_Change()
If Speed_DropDown.Value = "Slow" Then
Speed = 0
ElseIf Speed_DropDown.Value = "Medium" Then
Speed = 1
Else
Speed = 2
End If
End Sub
Private Sub Start_Button_Click()
If Cont = False Then
Gen = 100
Else
Gen = 1000000000
End If
If StopNow = True Then
Start_Button.Caption = "Stop"
StopNow = False
ElseIf StopNow = False Then
Start_Button.Caption = "Start"
StopNow = True
End If
For i = 1 To Gen
DoEvents
If StopNow Then Exit For
If Speed = 0 Then
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 2
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
ElseIf Speed = 1 Then
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 1
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
Else
'Fast is regular speed
End If
GameOfLife
Gen_Count = Gen_Count + 1
Me.Display_Gen.Caption = Gen_Count
Me.Repaint
Next i
Start_Button.Caption = "Start"
StopNow = True
End Sub
Private Sub UserForm_Initialize()
Sheet1.Cells.ClearContents
GridSize = 50
Gen_Count = 0
StopNow = True
Cont = False
ActiveSheet.Cells(1, 1).Select
Grid_Right_Corner = ActiveCell.Offset(GridSize - 1, GridSize - 1).Address
ActiveSheet.Range("A1:" & Grid_Right_Corner).Value = 0
ActiveSheet.Range("A1:" & Grid_Right_Corner).ColumnWidth = 2
ActiveSheet.Range("A1:" & Grid_Right_Corner).RowHeight = 12
ActiveCell.Range("A1:" & Grid_Right_Corner).BorderAround ColorIndex:=3, Weight:=xlThick
Speed_DropDown.AddItem "Slow"
Speed_DropDown.AddItem "Medium"
Speed_DropDown.AddItem "Fast"
Speed_DropDown.Value = "Fast"
Models_Dropdown.AddItem "None"
Models_Dropdown.AddItem "Glider"
Models_Dropdown.AddItem "Tumbler"
Models_Dropdown.AddItem "Shooter"
Models_Dropdown.Value = "None"
End Sub
Private Sub GameOfLife()
Dim Neighbors As Integer
GridSize = 50
ActiveSheet.Cells(1, 1).Select
Grid_Right_Corner = ActiveCell.Offset(GridSize - 1, GridSize - 1).Address
' Load Current display
Grid = Range("A1:" & Grid_Right_Corner)
' Load Models
If Gen_Count = 0 Then
Load_Model (Model)
End If
' Load up working grid
Grid2 = Grid
Range("A1:" & Grid_Right_Corner) = Grid2
For i = 1 To GridSize
For j = 1 To GridSize
iminus1 = i - 1
iplus1 = i + 1
jminus1 = j - 1
jplus1 = j + 1
If i - 1 <= 0 Then
iminus1 = GridSize
End If
If i + 1 >= GridSize Then
iplus1 = 1
End If
If j - 1 <= 0 Then
jminus1 = GridSize
End If
If j + 1 >= GridSize Then
jplus1 = 1
End If
Neighbors = Grid(iminus1, jminus1) + Grid(i, jminus1) + Grid(iplus1, jminus1) + Grid(iminus1, j) + Grid(iplus1, j) + Grid(iminus1, jplus1) + Grid(i, jplus1) + Grid(iplus1, jplus1)
If Grid(i, j) = 1 Then
If Neighbors <= 1 Or Neighbors >= 4 Then
Grid2(i, j) = 0
'MsgBox ("Grid" & i & " " & j & " N = " & Neighbors)
Else
Grid2(i, j) = 1
'MsgBox ("Grid" & i & " " & j & " N = " & Neighbors)
End If
Else
If Neighbors = 3 Then
Grid2(i, j) = 1
End If
End If
Next j
Next i
Range("A1:" & Grid_Right_Corner) = Grid2
Grid = Null
Grid2 = Null
End Sub
Private Sub Load_Model(Model_Choice As Integer)
If Model_Choice = 1 Then
' Small Glider
Grid(11, 10) = 1
Grid(12, 11) = 1
Grid(12, 12) = 1
Grid(11, 12) = 1
Grid(10, 12) = 1
ElseIf Model_Choice = 2 Then
'Tumbler
Grid(10, 13) = 1
Grid(10, 14) = 1
Grid(10, 15) = 1
Grid(11, 10) = 1
Grid(11, 11) = 1
Grid(11, 15) = 1
Grid(12, 10) = 1
Grid(12, 11) = 1
Grid(12, 12) = 1
Grid(12, 13) = 1
Grid(12, 14) = 1
Grid(14, 10) = 1
Grid(14, 11) = 1
Grid(14, 12) = 1
Grid(14, 13) = 1
Grid(14, 14) = 1
Grid(15, 10) = 1
Grid(15, 11) = 1
Grid(15, 15) = 1
Grid(16, 13) = 1
Grid(16, 14) = 1
Grid(16, 15) = 1
ElseIf Model_Choice = 3 Then
'Shooter
Grid(10, 12) = 1
Grid(10, 13) = 1
Grid(11, 12) = 1
Grid(11, 13) = 1
Grid(18, 13) = 1
Grid(18, 14) = 1
Grid(19, 12) = 1
Grid(19, 14) = 1
Grid(20, 12) = 1
Grid(20, 13) = 1
Grid(26, 14) = 1
Grid(26, 15) = 1
Grid(26, 16) = 1
Grid(27, 14) = 1
Grid(28, 15) = 1
Grid(32, 11) = 1
Grid(32, 12) = 1
Grid(33, 10) = 1
Grid(33, 12) = 1
Grid(34, 10) = 1
Grid(34, 11) = 1
Grid(34, 22) = 1
Grid(34, 23) = 1
Grid(35, 22) = 1
Grid(35, 24) = 1
Grid(36, 22) = 1
Grid(44, 10) = 1
Grid(44, 11) = 1
Grid(45, 10) = 1
Grid(45, 11) = 1
Grid(45, 17) = 1
Grid(45, 18) = 1
Grid(45, 19) = 1
Grid(46, 17) = 1
Grid(47, 18) = 1
Else
' Do nothing
End If
End Sub