-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module1.vba
1258 lines (1120 loc) · 40 KB
/
Module1.vba
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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'(3,33):플레이 시간, (8,33):레벨, (8,35):경험치(1줄에 10%)
'(10,33):점수, (12,33):콤보, (14,33):최고점수, (14,34):최고점수 때 플레이시간
'(3,42):도형 행, (3,43):도형 열, (3,44):도형 종류, (3,45):회전 종류, (3,46):그림자 행
'(3,47):쌓인 블록의 최상단 행, (5,42):게임 재생 여부
'(5,43):다음 호출 예약 시간, (5,44):다음 블록, (5,45):보관 블록, (5,46):줄 올라온 시간
Sub Selectarea(r, c, btype, bturn)
'그리거나 지우는 영역 선택
Set center = Cells(r, c)
'블록의 기준점
Select Case btype
Case 1
If bturn = 1 Then
Range(center.Offset(0, -1), center.Offset(0, 2)).Select
ElseIf bturn = 2 Then
Range(center.Offset(-1, 0), center.Offset(2, 0)).Select
End If
Case 2
If bturn = 1 Then
Union(Range(center.Offset(1, -1), center.Offset(1, 1)), center.Offset(0, -1)).Select
ElseIf bturn = 2 Then
Union(Range(center.Offset(-1, 1), center.Offset(1, 1)), center.Offset(1, 0)).Select
ElseIf bturn = 3 Then
Union(Range(center.Offset(-1, -1), center.Offset(-1, 1)), center.Offset(0, 1)).Select
ElseIf bturn = 4 Then
Union(Range(center.Offset(-1, -1), center.Offset(1, -1)), center.Offset(-1, 0)).Select
End If
Case 3
If bturn = 1 Then
Union(Range(center.Offset(1, -1), center.Offset(1, 1)), center.Offset(0, 1)).Select
ElseIf bturn = 2 Then
Union(Range(center.Offset(-1, 1), center.Offset(1, 1)), center.Offset(-1, 0)).Select
ElseIf bturn = 3 Then
Union(Range(center.Offset(-1, -1), center.Offset(-1, 1)), center.Offset(0, -1)).Select
ElseIf bturn = 4 Then
Union(Range(center.Offset(-1, -1), center.Offset(1, -1)), center.Offset(1, 0)).Select
End If
Case 4
If bturn = 1 Then
Union(center.Offset(0, -1), center, center.Offset(1, 0), center.Offset(1, 1)).Select
ElseIf bturn = 2 Then
Union(center, center.Offset(1, 0), center.Offset(-1, 1), center.Offset(0, 1)).Select
End If
Case 5
If bturn = 1 Then
Union(center.Offset(0, 1), center, center.Offset(1, 0), center.Offset(1, -1)).Select
ElseIf bturn = 2 Then
Union(center, center.Offset(-1, 0), center.Offset(1, 1), center.Offset(0, 1)).Select
End If
Case 6
If bturn = 1 Then
Union(Range(center.Offset(1, -1), center.Offset(1, 1)), center).Select
ElseIf bturn = 2 Then
Union(Range(center.Offset(-1, 1), center.Offset(1, 1)), center).Select
ElseIf bturn = 3 Then
Union(Range(center.Offset(-1, -1), center.Offset(-1, 1)), center).Select
ElseIf bturn = 4 Then
Union(Range(center.Offset(-1, -1), center.Offset(1, -1)), center).Select
End If
Case 7
Range(center.Offset(0, -1), center.Offset(1, 0)).Select
End Select
End Sub
Sub drawblock(r, c, btype, bturn)
'블록 그리기
Dim color(6)
color(0) = RGB(0, 255, 255)
color(1) = RGB(101, 101, 255)
color(2) = RGB(255, 165, 0)
color(3) = RGB(255, 0, 0)
color(4) = RGB(0, 255, 0)
color(5) = RGB(170, 0, 255)
color(6) = RGB(229, 229, 0)
Call Selectarea(r, c, btype, bturn)
On Error Resume Next
Selection.Interior.ColorIndex = xlNone
' Selection.Interior.color = color(Cells(3, 44) - 1)
With Selection.Interior
.Pattern = xlPatternRectangularGradient
.Gradient.RectangleLeft = 0.5
.Gradient.RectangleRight = 0.5
.Gradient.RectangleTop = 0.5
.Gradient.RectangleBottom = 0.5
.Gradient.ColorStops.Clear
End With
With Selection.Interior.Gradient.ColorStops.Add(0)
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With Selection.Interior.Gradient.ColorStops.Add(1)
.color = color(btype - 1)
.TintAndShade = 0
End With
Cells(48, 48).Select
End Sub
Sub drawother(i, btype)
'i=0이면 다음 블록, i=1이면 보관 블록 그리기
If btype > 0 Then
If btype = 1 Then
r = 7 + i * 8
c = 25
ElseIf btype = 7 Then
r = 6 + i * 8
c = 26
Else
r = 6 + i * 8
c = 25
End If
Call drawblock(r, c, btype, 1)
End If
End Sub
Sub Eraseblock()
'블록 지우는 함수
Call Selectarea(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
On Error Resume Next
Selection.Interior.ColorIndex = xlNone
Cells(48, 48).Select
End Sub
Function checkleft()
'왼쪽 이동 가능한지 검사
Set center = Cells(Cells(3, 42), Cells(3, 43))
Select Case Cells(3, 44)
Case 1
If Cells(3, 45) = 1 Then
center.Offset(0, -2).Select
ElseIf Cells(3, 45) = 2 Then
Range(center.Offset(-1, -1), center.Offset(2, -1)).Select
End If
Case 2
If Cells(3, 45) = 1 Then
Range(center.Offset(0, -2), center.Offset(1, -2)).Select
ElseIf Cells(3, 45) = 2 Then
Union(center.Offset(-1, 0), center, center.Offset(1, -1)).Select
ElseIf Cells(3, 45) = 3 Then
Union(center.Offset(-1, -2), center).Select
ElseIf Cells(3, 45) = 4 Then
Range(center.Offset(-1, -2), center.Offset(1, -2)).Select
End If
Case 3
If Cells(3, 45) = 1 Then
Union(center, center.Offset(1, -2)).Select
ElseIf Cells(3, 45) = 2 Then
Union(center, center.Offset(1, 0), center.Offset(-1, -1)).Select
ElseIf Cells(3, 45) = 3 Then
Range(center.Offset(-1, -2), center.Offset(0, -2)).Select
ElseIf Cells(3, 45) = 4 Then
Range(center.Offset(-1, -2), center.Offset(1, -2)).Select
End If
Case 4
If Cells(3, 45) = 1 Then
Union(center.Offset(0, -2), center.Offset(1, -1)).Select
ElseIf Cells(3, 45) = 2 Then
Union(center.Offset(0, -1), center.Offset(1, -1), center.Offset(-1, 0)).Select
End If
Case 5
If Cells(3, 45) = 1 Then
Union(center.Offset(0, -1), center.Offset(1, -2)).Select
ElseIf Cells(3, 45) = 2 Then
Union(center.Offset(-1, -1), center.Offset(0, -1), center.Offset(1, 0)).Select
End If
Case 6
If Cells(3, 45) = 1 Then
Union(center.Offset(0, -1), center.Offset(1, -2)).Select
ElseIf Cells(3, 45) = 2 Then
Union(center.Offset(-1, 0), center.Offset(0, -1), center.Offset(1, 0)).Select
ElseIf Cells(3, 45) = 3 Then
Union(center.Offset(-1, -2), center.Offset(0, -1)).Select
ElseIf Cells(3, 45) = 4 Then
Range(center.Offset(-1, -2), center.Offset(1, -2)).Select
End If
Case 7
Range(center.Offset(0, -2), center.Offset(1, -2)).Select
End Select
If Selection.Interior.ColorIndex = xlNone Then
checkleft = True
Else
checkleft = False
End If
Cells(48, 48).Select
End Function
Function checkright()
'오른쪽 이동 가능한지 검사
Set center = Cells(Cells(3, 42), Cells(3, 43))
Select Case Cells(3, 44)
Case 1
If Cells(3, 45) = 1 Then
center.Offset(0, 3).Select
ElseIf Cells(3, 45) = 2 Then
Range(center.Offset(-1, 1), center.Offset(2, 1)).Select
End If
Case 2
If Cells(3, 45) = 1 Then
Union(center, center.Offset(1, 2)).Select
ElseIf Cells(3, 45) = 2 Then
Range(center.Offset(-1, 2), center.Offset(1, 2)).Select
ElseIf Cells(3, 45) = 3 Then
Range(center.Offset(-1, 2), center.Offset(0, 2)).Select
ElseIf Cells(3, 45) = 4 Then
Union(center, center.Offset(1, 0), center.Offset(-1, 1)).Select
End If
Case 3
If Cells(3, 45) = 1 Then
Range(center.Offset(0, 2), center.Offset(1, 2)).Select
ElseIf Cells(3, 45) = 2 Then
Range(center.Offset(-1, 2), center.Offset(1, 2)).Select
ElseIf Cells(3, 45) = 3 Then
Union(center, center.Offset(-1, 2)).Select
ElseIf Cells(3, 45) = 4 Then
Union(center, center.Offset(-1, 0), center.Offset(1, 1)).Select
End If
Case 4
If Cells(3, 45) = 1 Then
Union(center.Offset(0, 1), center.Offset(1, 2)).Select
ElseIf Cells(3, 45) = 2 Then
Union(center.Offset(-1, 2), center.Offset(0, 2), center.Offset(1, 1)).Select
End If
Case 5
If Cells(3, 45) = 1 Then
Union(center.Offset(0, 2), center.Offset(1, 1)).Select
ElseIf Cells(3, 45) = 2 Then
Union(center.Offset(0, 2), center.Offset(1, 2), center.Offset(-1, 1)).Select
End If
Case 6
If Cells(3, 45) = 1 Then
Union(center.Offset(0, 1), center.Offset(1, 2)).Select
ElseIf Cells(3, 45) = 2 Then
Range(center.Offset(-1, 2), center.Offset(1, 2)).Select
ElseIf Cells(3, 45) = 3 Then
Union(center.Offset(-1, 2), center.Offset(0, 1)).Select
ElseIf Cells(3, 45) = 4 Then
Union(center.Offset(-1, 0), center.Offset(0, 1), center.Offset(1, 0)).Select
End If
Case 7
Range(center.Offset(0, 1), center.Offset(1, 1)).Select
End Select
If Selection.Interior.ColorIndex = xlNone Then
checkright = True
Else
checkright = False
End If
Cells(48, 48).Select
End Function
Function checkdown(r)
'아래쪽 이동 가능한지 검사
Set center = Cells(r, Cells(3, 43))
Select Case Cells(3, 44)
Case 1
If Cells(3, 45) = 1 Then
Range(center.Offset(1, -1), center.Offset(1, 2)).Select
ElseIf Cells(3, 45) = 2 Then
center.Offset(3, 0).Select
End If
Case 2
If Cells(3, 45) = 1 Then
Range(center.Offset(2, -1), center.Offset(2, 1)).Select
ElseIf Cells(3, 45) = 2 Then
Range(center.Offset(2, 0), center.Offset(2, 1)).Select
ElseIf Cells(3, 45) = 3 Then
Union(center.Offset(0, -1), center, center.Offset(1, 1)).Select
ElseIf Cells(3, 45) = 4 Then
Union(center, center.Offset(2, -1)).Select
End If
Case 3
If Cells(3, 45) = 1 Then
Range(center.Offset(2, -1), center.Offset(2, 1)).Select
ElseIf Cells(3, 45) = 2 Then
Union(center, center.Offset(2, 1)).Select
ElseIf Cells(3, 45) = 3 Then
Union(center.Offset(0, 1), center, center.Offset(1, -1)).Select
ElseIf Cells(3, 45) = 4 Then
Range(center.Offset(2, -1), center.Offset(2, 0)).Select
End If
Case 4
If Cells(3, 45) = 1 Then
Union(center.Offset(2, 0), center.Offset(2, 1), center.Offset(1, -1)).Select
ElseIf Cells(3, 45) = 2 Then
Union(center.Offset(2, 0), center.Offset(1, 1)).Select
End If
Case 5
If Cells(3, 45) = 1 Then
Union(center.Offset(2, -1), center.Offset(2, 0), center.Offset(1, 1)).Select
ElseIf Cells(3, 45) = 2 Then
Union(center.Offset(1, 0), center.Offset(2, 1)).Select
End If
Case 6
If Cells(3, 45) = 1 Then
Range(center.Offset(2, -1), center.Offset(2, 1)).Select
ElseIf Cells(3, 45) = 2 Then
Union(center.Offset(1, 0), center.Offset(2, 1)).Select
ElseIf Cells(3, 45) = 3 Then
Union(center.Offset(0, -1), center.Offset(1, 0), center.Offset(0, 1)).Select
ElseIf Cells(3, 45) = 4 Then
Union(center.Offset(2, -1), center.Offset(1, 0)).Select
End If
Case 7
Range(center.Offset(2, -1), center.Offset(2, 0)).Select
End Select
emptycnt = 0
allcnt = 0
For Each x In Selection
'for each를 selection에 적용해 개별셀 접근
If x.Interior.ColorIndex = xlNone Or x.Interior.Pattern = xlPatternDown Then
'그림자랑 겹칠수도 있으므로 그림자 패턴에도 개수 증가
emptycnt = emptycnt + 1
End If
allcnt = allcnt + 1
Next x
If emptycnt = allcnt Then
checkdown = True
'아래쪽 영역이 그림자 또는 빈칸이면 이동가능 지역
Else
checkdown = False
End If
Cells(48, 48).Select
End Function
Function checkrclockturn()
'반시계 방향 회전 가능한지 검사
If Cells(3, 42) = 3 Then
Call godown
Call ActiveSheet.Unprotect("Tkdlqjrj")
End If
Set center = Cells(Cells(3, 42), Cells(3, 43))
beforec = Cells(3, 43)
Select Case Cells(3, 44)
Case 1
If Cells(3, 45) = 1 Then
Union(center.Offset(1, 0), center.Offset(2, 0), center.Offset(-1, 0)).Select
ElseIf Cells(3, 45) = 2 Then
If Cells(3, 43) = 3 Then
Call goright
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
ElseIf Cells(3, 43) > 16 Then
For i = 1 To (Cells(3, 43) - 16)
Call goleft
Call ActiveSheet.Unprotect("Tkdlqjrj")
Next i
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Union(center.Offset(0, 1), center.Offset(0, 2), center.Offset(0, -1)).Select
End If
Case 2
If Cells(3, 45) = 1 Then
Range(center.Offset(-1, 1), center.Offset(0, 1)).Select
ElseIf Cells(3, 45) = 2 Then
If Cells(3, 43) = 3 Then
Call goright
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(-1, -1), center.Offset(-1, 0)).Select
ElseIf Cells(3, 45) = 3 Then
Range(center.Offset(0, -1), center.Offset(1, -1)).Select
ElseIf Cells(3, 45) = 4 Then
If Cells(3, 43) = 18 Then
Call goleft
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(1, 0), center.Offset(1, 1)).Select
End If
Case 3
If Cells(3, 45) = 1 Then
Range(center.Offset(-1, 0), center.Offset(-1, 1)).Select
ElseIf Cells(3, 45) = 2 Then
If Cells(3, 43) = 3 Then
Call goright
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(-1, -1), center.Offset(0, -1)).Select
ElseIf Cells(3, 45) = 3 Then
Range(center.Offset(1, -1), center.Offset(1, 0)).Select
ElseIf Cells(3, 45) = 4 Then
If Cells(3, 43) = 18 Then
Call goleft
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(0, 1), center.Offset(1, 1)).Select
End If
Case 4
If Cells(3, 45) = 1 Then
Range(center.Offset(-1, 1), center.Offset(0, 1)).Select
ElseIf Cells(3, 45) = 2 Then
If Cells(3, 43) = 3 Then
Call goright
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Union(center.Offset(0, -1), center.Offset(1, 1)).Select
End If
Case 5
If Cells(3, 45) = 1 Then
Union(center.Offset(-1, 0), center.Offset(1, 1)).Select
ElseIf Cells(3, 45) = 2 Then
If Cells(3, 43) = 3 Then
Call goright
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(1, -1), center.Offset(1, 0)).Select
End If
Case 6
If Cells(3, 45) = 1 Then
Range(center.Offset(-1, 1), center.Offset(0, 1)).Select
ElseIf Cells(3, 45) = 2 Then
If Cells(3, 43) = 3 Then
Call goright
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(-1, -1), center.Offset(-1, 0)).Select
ElseIf Cells(3, 45) = 3 Then
Range(center.Offset(0, -1), center.Offset(1, -1)).Select
ElseIf Cells(3, 45) = 4 Then
If Cells(3, 43) = 18 Then
Call goleft
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(1, 0), center.Offset(1, 1)).Select
End If
End Select
emptycnt = 0
allcnt = 0
For Each x In Selection
'for each를 selection에 적용해 개별셀 접근
If x.Interior.ColorIndex = xlNone Or x.Interior.Pattern = xlPatternDown Then
'그림자랑 겹칠수도 있으므로 그림자 패턴에도 개수 증가
emptycnt = emptycnt + 1
End If
allcnt = allcnt + 1
Next x
If emptycnt = allcnt Then
checkrclockturn = True
Else
If beforec <> Cells(3, 43) Then
Call Eraseshadow
Call Eraseblock
Cells(3, 43) = beforec
Call drawshadow
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
End If
checkrclockturn = False
End If
Cells(48, 48).Select
End Function
Function checkclockturn()
'시계 방향 회전 가능한지 검사
If Cells(3, 42) = 3 Then
Call godown
Call ActiveSheet.Unprotect("Tkdlqjrj")
End If
Set center = Cells(Cells(3, 42), Cells(3, 43))
beforec = Cells(3, 43)
Select Case Cells(3, 44)
Case 1, 4, 5
checkclockturn = checkrclockturn
Exit Function
Case 2
If Cells(3, 45) = 1 Then
Range(center.Offset(-1, -1), center.Offset(-1, 0)).Select
ElseIf Cells(3, 45) = 2 Then
If Cells(3, 43) = 3 Then
Call goright
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(0, -1), center.Offset(1, -1)).Select
ElseIf Cells(3, 45) = 3 Then
Range(center.Offset(1, 0), center.Offset(1, 1)).Select
ElseIf Cells(3, 45) = 4 Then
If Cells(3, 43) = 18 Then
Call goleft
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(-1, 1), center.Offset(0, 1)).Select
End If
Case 3
If Cells(3, 45) = 1 Then
Range(center.Offset(-1, -1), center.Offset(0, -1)).Select
ElseIf Cells(3, 45) = 2 Then
If Cells(3, 43) = 3 Then
Call goright
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(1, -1), center.Offset(1, 0)).Select
ElseIf Cells(3, 45) = 3 Then
Range(center.Offset(0, 1), center.Offset(1, 1)).Select
ElseIf Cells(3, 45) = 4 Then
If Cells(3, 43) = 18 Then
Call goleft
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(-1, 1), center.Offset(-1, 0)).Select
End If
Case 6
If Cells(3, 45) = 1 Then
Range(center.Offset(-1, -1), center.Offset(0, -1)).Select
ElseIf Cells(3, 45) = 2 Then
If Cells(3, 43) = 3 Then
Call goright
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(1, -1), center.Offset(1, 0)).Select
ElseIf Cells(3, 45) = 3 Then
Range(center.Offset(0, 1), center.Offset(1, 1)).Select
ElseIf Cells(3, 45) = 4 Then
If Cells(3, 43) = 18 Then
Call goleft
Call ActiveSheet.Unprotect("Tkdlqjrj")
Set center = Cells(Cells(3, 42), Cells(3, 43))
End If
Range(center.Offset(-1, 0), center.Offset(-1, 1)).Select
End If
End Select
emptycnt = 0
allcnt = 0
For Each x In Selection
'for each를 selection에 적용해 개별셀 접근
If x.Interior.ColorIndex = xlNone Or x.Interior.Pattern = xlPatternDown Then
'그림자랑 겹칠수도 있으므로 그림자 패턴에도 개수 증가
emptycnt = emptycnt + 1
End If
allcnt = allcnt + 1
Next x
If emptycnt = allcnt Then
checkclockturn = True
Else
If beforec <> Cells(3, 43) Then
Call Eraseshadow
Call Eraseblock
Cells(3, 43) = beforec
Call drawshadow
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
End If
checkclockturn = False
End If
Cells(48, 48).Select
End Function
Sub hold()
Call ActiveSheet.Unprotect("Tkdlqjrj")
Application.ScreenUpdating = False
Cells(3, 33) = Cells(3, 33) + 6 / 100
Call makingline
If Cells(5, 45) = 0 Then '블록 보관하기
Call Eraseshadow
Call Eraseblock
For i = 0 To 1
Range(Cells(4 + 8 * i, 23), Cells(9 + 8 * i, 28)).Interior.ColorIndex = xlNone
Next i
'현재 블록 보관하기
Cells(5, 45) = -Cells(3, 44)
Call drawother(1, -Cells(5, 45))
'다음 블록 등장시키기
Cells(3, 42) = 3
Cells(3, 43) = 11
Cells(3, 45) = 1
Call proceedprd
Call drawother(0, Cells(5, 44))
Call drawshadow
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
ElseIf (Cells(5, 45) > 0 And Cells(5, 48) < 8) And (Cells(5, 45) <> Cells(3, 44)) Then '블록 꺼내기
Call Eraseshadow
Call Eraseblock
Range(Cells(4 + 8, 23), Cells(9 + 8, 28)).Interior.ColorIndex = xlNone
'보관 블록과 현재 블록 교환하기
tmp = Cells(3, 44)
Cells(3, 44) = Cells(5, 45)
Cells(5, 45) = -tmp
Call drawother(1, -Cells(5, 45))
'보관 블록 등장시키기
Cells(3, 42) = 3
Cells(3, 43) = 11
Cells(3, 45) = 1
Call drawshadow
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
End If
Call ActiveSheet.Protect("Tkdlqjrj", False, True)
End Sub
Sub goleft()
Call ActiveSheet.Unprotect("Tkdlqjrj")
Application.ScreenUpdating = False
Cells(3, 33) = Cells(3, 33) + 6 / 100
Call makingline
If checkleft Then
Call Eraseshadow
Call Eraseblock
Cells(3, 43) = Cells(3, 43) - 1
Call drawshadow
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
End If
Call ActiveSheet.Protect("Tkdlqjrj", False, True)
End Sub
Sub goright()
Call ActiveSheet.Unprotect("Tkdlqjrj")
Application.ScreenUpdating = False
Cells(3, 33) = Cells(3, 33) + 6 / 100
Call makingline
If checkright Then
Call Eraseshadow
Call Eraseblock
Cells(3, 43) = Cells(3, 43) + 1
Call drawshadow
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
End If
Call ActiveSheet.Protect("Tkdlqjrj", False, True)
End Sub
Sub godown()
Call ActiveSheet.Unprotect("Tkdlqjrj")
Application.ScreenUpdating = False
Cells(3, 33) = Cells(3, 33) + 6 / 100
Call makingline
If checkdown(Cells(3, 42)) Then
Call Eraseblock
Cells(3, 42) = Cells(3, 42) + 1
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
End If
Call ActiveSheet.Protect("Tkdlqjrj", False, True)
End Sub
Sub gobottom()
'하드드롭 함수
Call ActiveSheet.Unprotect("Tkdlqjrj")
Application.ScreenUpdating = False
Cells(3, 33) = Cells(3, 33) + 6 / 100
Call makingline
If Cells(3, 42) > 2 Then
Call Eraseshadow
Call Eraseblock
End If
Cells(3, 42) = Cells(3, 46)
'그림자 위치로 옮기는 것과 같음
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
Call nextstatus(0)
Call ActiveSheet.Protect("Tkdlqjrj", False, True)
End Sub
Sub clockturn()
'시계방향 회전
Call ActiveSheet.Unprotect("Tkdlqjrj")
Application.ScreenUpdating = False
Cells(3, 33) = Cells(3, 33) + 6 / 100
Call makingline
If Cells(3, 44) <> 7 Then
If checkclockturn Then
Call Eraseshadow
Call Eraseblock
Cells(3, 45) = Cells(3, 45) - 1
If (Cells(3, 44) = 1 Or Cells(3, 44) = 4 Or Cells(3, 44) = 5) And Cells(3, 45) = 0 Then
Cells(3, 45) = 2
ElseIf (Cells(3, 44) = 2 Or Cells(3, 44) = 3 Or Cells(3, 44) = 6) And Cells(3, 45) = 0 Then
Cells(3, 45) = 4
End If
Call drawshadow
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
End If
End If
Call ActiveSheet.Protect("Tkdlqjrj", False, True)
End Sub
Sub rclockturn()
'반시계방향 회전
Call ActiveSheet.Unprotect("Tkdlqjrj")
Application.ScreenUpdating = False
Cells(3, 33) = Cells(3, 33) + 6 / 100
Call makingline
If Cells(3, 44) <> 7 Then
If checkrclockturn Then
Call Eraseshadow
Call Eraseblock
Cells(3, 45) = Cells(3, 45) + 1
If ((Cells(3, 44) = 1 Or Cells(3, 44) = 4 Or Cells(3, 44) = 5) And Cells(3, 45) = 3) Or _
((Cells(3, 44) = 2 Or Cells(3, 44) = 3 Or Cells(3, 44) = 6) And Cells(3, 45) = 5) Then
Cells(3, 45) = 1
End If
Call drawshadow
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
End If
End If
Call ActiveSheet.Protect("Tkdlqjrj", False, True)
End Sub
Sub makeperiod()
Dim blockarr(6)
For i = 0 To 6
blockarr(i) = i + 1
Next i
For i = 0 To 6
r = Int(Rnd * 7)
tmp = blockarr(i)
blockarr(i) = blockarr(r)
blockarr(r) = tmp
Next i
If blockarr(0) = Cells(3, 44) Then
tmp = blockarr(0)
blockarr(0) = blockarr(1)
blockarr(1) = tmp
End If
For i = 0 To 6
Cells(5 + i, 44) = blockarr(i)
Next i
End Sub
Sub proceedprd()
Cells(3, 44) = Cells(5, 44)
If Cells(6, 44) = "" Then
Call makeperiod
Else
For i = 0 To 6
If Cells(5 + i, 44) = "" Then
Exit For
End If
Cells(5 + i, 44) = Cells(6 + i, 44)
Next i
End If
End Sub
Sub nextstatus(ismain)
Call calhigh
Call Eraseline
Cells(3, 42) = 3
Cells(3, 43) = 11
Cells(3, 45) = 1
Call proceedprd
If Cells(5, 45) < 0 Then
Cells(5, 45) = -Cells(5, 45)
End If
Range(Cells(4, 23), Cells(9, 28)).Interior.ColorIndex = xlNone
If Cells(3, 47) > 3 And checkdown(Cells(3, 42)) Then
Call drawother(0, Cells(5, 44))
Call drawshadow
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
Application.ScreenUpdating = True
If ismain = 1 Then
veltmp = 31 - Cells(8, 33)
If veltmp < 5 Then
veltmp = 5
End If
'가변속도 알고리즘
Cells(5, 43) = "=NOW()+""00:00:0" & CStr(veltmp / 100) & """"
Cells(3, 33) = Cells(3, 33) + veltmp / 100
Application.OnTime Cells(5, 43), "gameloop"
End If
Exit Sub
Else
If Cells(3, 47) > 3 Then
Cells(3, 42) = 2
If checkdown(Cells(3, 42)) Then
Cells(3, 42) = 3
End If
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
End If
Application.ScreenUpdating = True
MsgBox "GAME OVER!!!!" & vbNewLine & Cells(10, 33) & "점을 달성하였습니다." & _
vbNewLine & "플레이 시간 : " & Int(Cells(3, 33) + 0.5) & "초", 64, "테트리스"
'Range(Cells(2, 3), Cells(2, 18)).Interior.color = RGB(128, 128, 128)
With Range(Cells(2, 3), Cells(2, 18)).Interior
.Pattern = xlPatternLinearGradient
.Gradient.Degree = 90
.Gradient.ColorStops.Clear
End With
With Range(Cells(2, 3), Cells(2, 18)).Interior.Gradient.ColorStops.Add(0)
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With Range(Cells(2, 3), Cells(2, 18)).Interior.Gradient.ColorStops.Add(1)
.color = RGB(128, 128, 128)
.TintAndShade = 0
End With
Call resetgame
Exit Sub
End If
End Sub
Sub Eraseline()
Call ActiveSheet.Unprotect("Tkdlqjrj")
ercnt = 0
'지운 줄의 수
score = 0
'얻은 점수
For i = WorksheetFunction.Min(30, Cells(3, 42) + 2) To Cells(3, 47) Step -1
cnt = 0
'줄에서 채워진 블록의 수
For j = 3 To 18
If Cells(i, j).Interior.ColorIndex <> xlNone Then
cnt = cnt + 1
End If
Next
If cnt = 16 Then
Range(Cells(Cells(3, 47) - 1, 3), Cells(i - 1, 18)).Copy Range(Cells(Cells(3, 47), 3), Cells(i, 18))
Application.CutCopyMode = False
ercnt = ercnt + 1
Cells(3, 47) = Cells(3, 47) + 1
i = i + 1
End If
Next i
If Cells(12, 33) > 0 Then
score = Cells(8, 33) * 10 * (Cells(12, 30) + 50)
End If
'콤보점수 반영
If ercnt = 0 Then
Cells(12, 33) = 0
Else
Cells(12, 33) = Cells(12, 33) + 1
Cells(8, 35) = Cells(8, 35) + ercnt
If ercnt = 1 Then
score = score + Cells(8, 33) * 1000
ElseIf ercnt = 2 Then
score = score + Cells(8, 33) * 3000
ElseIf ercnt = 3 Then
score = score + Cells(8, 33) * 5000
ElseIf ercnt = 4 Then
score = score + Cells(8, 33) * 8000
End If
'퍼펙트 클리어 판정
If Range(Cells(3, 3), Cells(30, 18)).Interior.ColorIndex = xlNone Then
score = score + Cells(8, 33) * 30000
End If
If Cells(8, 35) > 9 Then
Cells(8, 33) = Cells(8, 33) + 1
Cells(8, 35) = Cells(8, 35) - 10
End If
'레벨업 시스템
End If
Cells(10, 33) = Cells(10, 33) + score
If Cells(14, 33) < Cells(10, 33) Then
Cells(14, 33) = Cells(10, 33)
Cells(14, 34) = Cells(3, 33)
ActiveWorkbook.Save
End If
End Sub
Sub calhigh()
'최상단 행 계산
hightmp = 0
Select Case Cells(3, 44)
Case 1
Select Case Cells(3, 45)
Case 1
hightmp = Cells(3, 42)
Case 2
hightmp = Cells(3, 42) - 1
End Select
Case 2
Select Case Cells(3, 45)
Case 1
hightmp = Cells(3, 42)
Case 2, 3, 4
hightmp = Cells(3, 42) - 1
End Select
Case 3
Select Case Cells(3, 45)
Case 1
hightmp = Cells(3, 42)
Case 2, 3, 4
hightmp = Cells(3, 42) - 1
End Select
Case 4
Select Case Cells(3, 45)
Case 1
hightmp = Cells(3, 42)
Case 2
hightmp = Cells(3, 42) - 1
End Select
Case 5
Select Case Cells(3, 45)
Case 1
hightmp = Cells(3, 42)
Case 2
hightmp = Cells(3, 42) - 1
End Select
Case 6
Select Case Cells(3, 45)
Case 1
hightmp = Cells(3, 42)
Case 2, 3, 4
hightmp = Cells(3, 42) - 1
End Select
Case 7
hightmp = Cells(3, 42)
End Select
If Cells(3, 47) > hightmp Then
Cells(3, 47) = hightmp
End If
End Sub
Sub makingline()
Timeterm = 81 - Cells(8, 33)
If Timeterm < 60 Then
Timeterm = 60
End If
'줄 올라온 시간이 됐을 때
If Cells(3, 42) > 2 And Int(Cells(3, 33) - Cells(5, 46)) >= Timeterm Then
Cells(5, 46) = Int(Cells(3, 33))
Call Eraseshadow
Call Eraseblock
Call panaltyline
If Cells(3, 47) > 3 Then
If Cells(3, 45) = 1 Then
Cells(3, 46) = 3
Else
Cells(3, 46) = 4
End If
Call drawshadow
If Cells(3, 42) < Cells(3, 46) Then
'원래 위치
Call drawblock(Cells(3, 42), Cells(3, 43), Cells(3, 44), Cells(3, 45))
Else
If checkdown(Cells(3, 42)) Then