- このページの著者ZISIRUが練習用に書いたコードです。
- 他で公開、配布、販売、使用する場合は変数名等、一部でもいいので改変して公開してください。
- 上記に違反しない限り私はすべての権利を主張しません。ご自由にお使いください。
- 本コードの使用において、この文章の表記、著者名の表記は不要です。
- 本コードは「現状のまま」提供され、明示または黙示を問わず、商品性、特定目的への適合性、非侵害に対する保証を含むがこれらに限定されない、いかなる種類の保証もありません。いかなる場合も、著者または著作権保有者は、契約行為、不法行為、またはその他の行為にかかわらず、本コード、または本コードの使用もしくはその他の取り扱いから生じる、またはそれに関連するいかなる請求、損害、またはその他の責任についても責任を負わないものとします。
- The code on this page was written by the author, ZISIRU, for practice purposes.
- If you wish to publish, distribute, or sell the code elsewhere, please modify it, even if only in terms of variable names, before making it public.
- As long as the above is not violated, I do not claim any rights and you are free to use it.
- There is no need to include this statement or the author’s name when using this code.
- This code is provided “as is”, and no warranties of any kind are offered, including but not limited to warranties of merchantability, fitness for a particular purpose, or non-infringement, whether expressed or implied. In no event shall the author or copyright holder be liable for any claims, damages, or other liabilities arising from or related to the use of this code, regardless of whether they are based on contract, tort, or other legal theory.
VBAクラスモジュール、オブジェクト名:ブロック_
内容は、まずランダムで出た目でブロックを形状を決めます。
次にメインからセルの位置rowとcolumnを受け取り、そこに連想配列のitemに回転毎のブロックの形状、keyに回転数(ストレートの棒なら縦と横2パターン)を格納しています。
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 |
Option Explicit Private 形状_ As Dictionary Private R_ As Long Private C_ As Long Property Let R(ByVal rrr As Long) R_ = rrr End Property Property Let C(ByVal ccc As Long) C_ = ccc End Property Property Get 形状() As Dictionary Set 形状 = 形状_ End Property Private Sub Class_Initialize() Set 形状_ = New Dictionary End Sub Sub 生成() Dim ランダム As Long Randomize ランダム = Int((7 - 1 + 1) * Rnd + 1) Select Case ランダム Case 1 'I字 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(0, -1), GAME.Cells(R_, C_).Offset(0, 1), GAME.Cells(R_, C_).Offset(0, 2)), 0 形状_.Keys(0).Borders.LineStyle = xlContinuous 形状_.Keys(0).Interior.ColorIndex = 17 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(-1, 0), GAME.Cells(R_, C_).Offset(-2, 0), GAME.Cells(R_, C_).Offset(1, 0)), 1 Case 2 'L字1 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(0, -1), GAME.Cells(R_, C_).Offset(-1, -1), GAME.Cells(R_, C_).Offset(0, 1)), 0 形状_.Keys(0).Borders.LineStyle = xlContinuous 形状_.Keys(0).Interior.ColorIndex = 9 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(-1, 0), GAME.Cells(R_, C_).Offset(-1, 1), GAME.Cells(R_, C_).Offset(1, 0)), 1 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(0, -1), GAME.Cells(R_, C_).Offset(0, 1), GAME.Cells(R_, C_).Offset(1, 1)), 2 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(-1, 0), GAME.Cells(R_, C_).Offset(1, 0), GAME.Cells(R_, C_).Offset(1, -1)), 3 Case 3 'L字2 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(0, -1), GAME.Cells(R_, C_).Offset(1, -1), GAME.Cells(R_, C_).Offset(0, 1)), 0 形状_.Keys(0).Borders.LineStyle = xlContinuous 形状_.Keys(0).Interior.ColorIndex = 9 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(-1, 0), GAME.Cells(R_, C_).Offset(-1, -1), GAME.Cells(R_, C_).Offset(1, 0)), 1 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(0, -1), GAME.Cells(R_, C_).Offset(0, 1), GAME.Cells(R_, C_).Offset(-1, 1)), 2 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(-1, 0), GAME.Cells(R_, C_).Offset(1, 1), GAME.Cells(R_, C_).Offset(1, 0)), 3 Case 4 'T字 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(0, -1), GAME.Cells(R_, C_).Offset(-1, 0), GAME.Cells(R_, C_).Offset(0, 1)), 0 形状_.Keys(0).Borders.LineStyle = xlContinuous 形状_.Keys(0).Interior.ColorIndex = 46 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(-1, 0), GAME.Cells(R_, C_).Offset(1, 0), GAME.Cells(R_, C_).Offset(0, 1)), 1 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(0, -1), GAME.Cells(R_, C_).Offset(1, 0), GAME.Cells(R_, C_).Offset(0, 1)), 2 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(0, -1), GAME.Cells(R_, C_).Offset(1, 0), GAME.Cells(R_, C_).Offset(-1, 0)), 3 Case 5 'Z字1 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(-1, -1), GAME.Cells(R_, C_).Offset(-1, 0), GAME.Cells(R_, C_).Offset(0, 1)), 0 形状_.Keys(0).Borders.LineStyle = xlContinuous 形状_.Keys(0).Interior.ColorIndex = 4 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(-1, 0), GAME.Cells(R_, C_).Offset(0, -1), GAME.Cells(R_, C_).Offset(1, -1)), 1 Case 6 'Z字2 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(0, -1), GAME.Cells(R_, C_).Offset(-1, 0), GAME.Cells(R_, C_).Offset(-1, 1)), 0 形状_.Keys(0).Borders.LineStyle = xlContinuous 形状_.Keys(0).Interior.ColorIndex = 4 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(-1, 0), GAME.Cells(R_, C_).Offset(0, 1), GAME.Cells(R_, C_).Offset(1, 1)), 1 Case 7 形状_.Add Union(GAME.Cells(R_, C_), GAME.Cells(R_, C_).Offset(-1, 0), GAME.Cells(R_, C_).Offset(0, 1), GAME.Cells(R_, C_).Offset(-1, 1)), 0 形状_.Keys(0).Borders.LineStyle = xlContinuous 形状_.Keys(0).Interior.ColorIndex = 53 End Select End Sub |
コメント