-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformMain.frm
545 lines (495 loc) · 14.5 KB
/
formMain.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
VERSION 5.00
Begin VB.Form formMain
BackColor = &H00E0E0E0&
BorderStyle = 1 'Fixed Single
Caption = "俄罗斯方块"
ClientHeight = 7080
ClientLeft = 45
ClientTop = 375
ClientWidth = 7905
FillStyle = 0 'Solid
LinkTopic = "fromMain"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 7080
ScaleWidth = 7905
StartUpPosition = 2 '屏幕中心
Begin VB.Frame manualFrame
Caption = "操作说明"
Height = 5000
Left = 5800
TabIndex = 1
Top = 600
Width = 2000
Begin VB.Label Label7
Caption = "ESC -- 退出"
Height = 300
Left = 200
TabIndex = 8
Top = 4000
Width = 1600
End
Begin VB.Label Label6
Caption = "N -- 新游戏"
Height = 300
Left = 200
TabIndex = 7
Top = 3400
Width = 1600
End
Begin VB.Label Label5
Caption = "空格 -- 暂停/继续"
Height = 300
Left = 200
TabIndex = 6
Top = 2800
Width = 1600
End
Begin VB.Label Label4
Caption = "→ -- 右移"
Height = 300
Left = 200
TabIndex = 5
Top = 2200
Width = 1400
End
Begin VB.Label Label3
Caption = "← -- 左移"
Height = 300
Left = 200
TabIndex = 4
Top = 1600
Width = 1400
End
Begin VB.Label Label2
Caption = "↓ -- 加速"
Height = 300
Left = 200
TabIndex = 3
Top = 1000
Width = 1400
End
Begin VB.Label Label1
Caption = "↑ -- 变形"
Height = 300
Left = 200
TabIndex = 2
Top = 400
Width = 1400
End
End
Begin VB.Timer Timer1
Interval = 250
Left = 480
Top = 5640
End
Begin VB.Label overLabel
Alignment = 2 'Center
BackColor = &H00C0FFC0&
Caption = "游戏结束"
BeginProperty Font
Name = "华文新魏"
Size = 36
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 900
Left = 2500
TabIndex = 9
Top = 2600
Width = 3030
End
Begin VB.Shape Shape1
FillStyle = 0 'Solid
Height = 6060
Left = 2500
Top = -10
Width = 3030
End
Begin VB.Shape Shape2
FillStyle = 0 'Solid
Height = 1800
Left = 300
Top = 0
Width = 1800
End
Begin VB.Label scoreLabel
BeginProperty Font
Name = "微软雅黑"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 360
TabIndex = 0
Top = 3240
Width = 1815
End
End
Attribute VB_Name = "formMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const KEY_LEFT = 37 '左箭头,向左移动
Const KEY_UP = 38 '上箭头,改变形状
Const KEY_RIGHT = 39 '右箭头,向右移动
Const KEY_DOWN = 40 '下箭头,加速
Const PAUSE = 32 '空格,暂停、继续
Const NEW_GAME = 78 '字母N,开始新的游戏
Const END_GAME = 27 'ESC,退出游戏
Public resize As Boolean
Dim preNum As Integer
Dim sameCount As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Timer1.Enabled = True Then
With cBox
If KeyCode = KEY_RIGHT Then
If hitright(cBox) = True Then Exit Sub
If hitbrixright(cBox) = True Then Exit Sub
clear cBox
For i = 1 To 4
.X(i) = .X(i) + boxwidth
Next i
display cBox
End If
If KeyCode = KEY_LEFT Then
If hitleft(cBox) = True Then Exit Sub
If hitbrixleft(cBox) = True Then Exit Sub
clear cBox
For i = 1 To 4
.X(i) = .X(i) - boxwidth
Next i
display cBox
End If
If KeyCode = KEY_UP Then
clear cBox
tempstate = state
state = state + 1
If state > .rot Then
state = 1
End If
If rotate(cBox, state) = False Then state = tempstate
display cBox
End If
If KeyCode = KEY_DOWN Then
For i = 1 To 7
clear cBox
If Control = True Then Exit Sub
For j = 1 To 4
.Y(j) = .Y(j) + boxwidth
Next j
display cBox
Next i
If Control = True Then Exit Sub
End If
End With
End If
If KeyCode = PAUSE Then
Timer1.Enabled = Not (Timer1.Enabled)
End If
If KeyCode = NEW_GAME Then
Form_Load
End If
If KeyCode = END_GAME Then
Form_Unload (1)
End If
End Sub
Private Sub Form_Load()
formMain.Refresh
overLabel.Visible = False
Timer1.Enabled = True
boxwidth = 300: pos = 0
fx = 2500
fy = 0
score = 0
scoreLabel.Caption = "得分 : 0"
firstBrix
display cBox
nextBox
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
Private Sub Timer1_Timer()
If resize = True Then
For i = 1 To pos
test (i)
Next i
resize = False
End If
Dim showNext As Boolean
showNext = True
With cBox
If Control = True Then Exit Sub
clear cBox
For i = 1 To 4
.Y(i) = .Y(i) + boxwidth
If .Y(i) < boxwidth Then
showNext = False
End If
Next i
display cBox
End With
If showNext Then
clearNextArea
drawBox nBox
End If
End Sub
Private Sub display(box As tempbox)
With box
For i = 1 To 4
Line (.X(i), .Y(i))-(.X(i) + boxwidth, .Y(i) + boxwidth), RGB(.r, .g, .b), BF
fill box, 0, 0, 0, i
Next i
End With
End Sub
Private Sub clear(box As tempbox)
With box
For i = 1 To 4
Line (.X(i), .Y(i))-(.X(i) + boxwidth, .Y(i) + boxwidth), RGB(0, 0, 0), BF
fill box, 0, 0, 0, i
Next i
End With
End Sub
Private Sub clearNextArea()
Line (300, 0)-(2100, 1800), RGB(0, 0, 0), BF
End Sub
Private Sub fill(box As tempbox, rd, gr, bl, j)
With box
Line (.X(j), .Y(j))-(.X(j) + boxwidth, .Y(j)), RGB(rd, gr, bl)
Line (.X(j), .Y(j))-(.X(j), .Y(j) + boxwidth), RGB(rd, gr, bl)
Line (.X(j), .Y(j) + boxwidth)-(.X(j) + boxwidth, .Y(j) + boxwidth), RGB(rd, gr, bl)
Line (.X(j) + boxwidth, .Y(j))-(.X(j) + boxwidth, .Y(j) + boxwidth), RGB(rd, gr, bl)
End With
End Sub
Private Sub border(box As tempbox)
With box
For j = 1 To 4
Line (.X(j), .Y(j))-(.X(j) + boxwidth, .Y(j)), RGB(0, 0, 0)
Line (.X(j), .Y(j))-(.X(j), .Y(j) + boxwidth), RGB(0, 0, 0)
Line (.X(j), .Y(j) + boxwidth)-(.X(j) + boxwidth, .Y(j) + boxwidth), RGB(0, 0, 0)
Line (.X(j) + boxwidth, .Y(j))-(.X(j) + boxwidth, .Y(j) + boxwidth), RGB(0, 0, 0)
Next j
End With
End Sub
Private Sub drawBox(box As tempbox)
With box
For i = 1 To 4
Line (.X(i), .Y(i))-(.X(i) + boxwidth, .Y(i) + boxwidth), RGB(.r, .g, .b), BF
Next i
End With
border box
End Sub
Public Function Control() As Boolean
With cBox
For i = 1 To 4
If .Y(i) + boxwidth = fy + (20 * boxwidth) Then
For k = 1 To 4
pos = pos + 1
old(pos).X = .X(k)
old(pos).Y = .Y(k)
old(pos).bl = True
old(pos).r = .r
old(pos).g = .g
old(pos).b = .b
Next k
display cBox
control2
newbrix
Control = True
Exit Function
End If
Next i
'****************************
For i = 1 To 4
For l = 1 To pos
If .Y(i) + boxwidth = old(l).Y And .X(i) = old(l).X Then
For k = 1 To 4
If .Y(k) = fy Then
gameover
Control = True
Exit Function
End If
pos = pos + 1
old(pos).X = .X(k)
old(pos).Y = .Y(k)
old(pos).bl = True
old(pos).r = .r
old(pos).g = .g
old(pos).b = .b
Next k
display cBox
control2
newbrix
Control = True
Exit Function
End If
Next l
Next i
Control = False
End With
End Function
Public Sub control2()
Dim fin(20)
metr = 0
For i = 1 To 20
cn = 0
For j = 1 To pos
If old(j).Y = fy + (i * boxwidth) Then
cn = cn + 1
If cn = 10 Then
metr = metr + 1
fin(metr) = old(j).Y
End If
End If
Next j
Next i
'**********************
If metr <> 0 Then
score = score + (metr * 10)
scoreLabel.Caption = "得分 : " + Str(score)
For i = 1 To metr
For j = 1 To pos
If old(j).Y = fin(i) Then
old(j).bl = False
End If
Next j
Next i
'***********************
Line (fx, fy)-(fx + (10 * boxwidth), fy + (20 * boxwidth)), RGB(0, 0, 0), BF
For j = 1 To metr
For i = 1 To pos
If old(i).bl = True And old(i).Y < fin(j) Then
old(i).Y = old(i).Y + boxwidth
End If
Next i
Next j
'************************
num = 0
For i = 1 To pos
If old(i).bl = True Then
num = num + 1
clean(num).X = old(i).X: clean(num).Y = old(i).Y
clean(num).r = old(i).r: clean(num).g = old(i).g: clean(num).b = old(i).b
test (i)
End If
Next i
'***************************
pos = num
For i = 1 To num
With old(i)
.X = clean(i).X
.Y = clean(i).Y
.bl = True
.r = clean(i).r
.g = clean(i).g
.b = clean(i).b
End With
Next i
End If
End Sub
Private Function nextNum() As Integer
While True
Randomize
rndSeek = Int(Rnd * 100)
Randomize rndSeek
nnum = Int(Rnd * 7) + 1
If nnum <> preNum Then
nextNum = nnum
sameCount = 0
preNum = nnum
Exit Function
End If
sameCount = sameCount + 1
If sameCount < 3 Then
nextNum = nnum
Exit Function
End If
Wend
End Function
Private Sub nextBox()
'Randomize
Dim nnum As Integer
'nnum = Int(Rnd * 7) + 1
nnum = nextNum
nBox.X(1) = 900
nBox.Y(1) = 300
nBox.r = Int(Rnd * 255) + 100
nBox.g = Int(Rnd * 255) + 100
nBox.b = Int(Rnd * 255) + 100
nBox.num = nnum
If nnum = 2 Then
nBox.rot = 1
ElseIf nnum = 7 Then
nBox.rot = 2
Else
nBox.rot = 4
End If
calcBox nBox, 1
'clearNextArea
'drawBox nBox
End Sub
Private Sub firstBrix()
'Randomize
Dim nnum As Integer
'nnum = Int(Rnd * 7) + 1
nnum = nextNum
With cBox
.num = nnum
.r = Int(Rnd * 255) + 100
.g = Int(Rnd * 255) + 100
.b = Int(Rnd * 255) + 100
.X(1) = fx + (4 * boxwidth)
If nnum = 2 Then
.Y(1) = fy - (2 * boxwidth)
.rot = 1
ElseIf nnum = 7 Then
.Y(1) = fy - (4 * boxwidth)
.rot = 2
Else
.Y(1) = fy - (3 * boxwidth)
.rot = 4
End If
state = 1
End With
calcBox cBox, 1
End Sub
Public Sub newbrix()
cBox = nBox
With cBox
.X(1) = fx + (4 * boxwidth)
If .num = 2 Then
.Y(1) = fy - (2 * boxwidth)
Else
If .num = 7 Then
.Y(1) = fy - (4 * boxwidth)
Else
.Y(1) = fy - (3 * boxwidth)
End If
End If
state = 1
End With
calcBox cBox, 1
nextBox
End Sub
Public Sub test(i)
With old(i)
Line (.X, .Y)-(.X + boxwidth, .Y + boxwidth), RGB(.r, .g, .b), BF
Line (.X, .Y)-(.X + boxwidth, .Y), RGB(0, 0, 0)
Line (.X, .Y)-(.X, .Y + boxwidth), RGB(0, 0, 0)
Line (.X, .Y + boxwidth)-(.X + boxwidth, .Y + boxwidth), RGB(0, 0, 0)
Line (.X + boxwidth, .Y)-(.X + boxwidth, .Y + boxwidth), RGB(0, 0, 0)
End With
End Sub
Public Sub gameover()
Timer1.Enabled = False
overLabel.Visible = True
End Sub