回答編集履歴
4
文法の修正。分かりやすさ重視
test
CHANGED
@@ -75,3 +75,8 @@
|
|
75
75
|
}
|
76
76
|
}
|
77
77
|
```
|
78
|
+
|
79
|
+

|
80
|
+
|
81
|
+
このような感じにデザイナーを使わず、ソースで表示したかったです。
|
82
|
+
多くの方に意図が伝わらず申し訳ありませんでした。
|
3
コードの部分を修正しました。
test
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
```C#
|
1
2
|
using System;
|
2
3
|
using System.Collections.Generic;
|
3
4
|
using System.ComponentModel;
|
@@ -50,14 +51,14 @@
|
|
50
51
|
{
|
51
52
|
gameBoard_P[i, j] = new PictureBox();
|
52
53
|
|
53
|
-
//壁のPictureBox
|
54
|
+
//壁のPictureBox関連
|
54
55
|
if ((i == 0 || i == length - 1) || (j == 0 || j == width - 1))
|
55
56
|
{
|
56
|
-
gameBoard_P[i, j].Size = new Size(25, 25);
|
57
|
+
gameBoard_P[i, j].Size = new Size(25, 25);//一つの画像の大きさを決める
|
57
|
-
gameBoard_P[i, j].SizeMode = PictureBoxSizeMode.StretchImage;
|
58
|
+
gameBoard_P[i, j].SizeMode = PictureBoxSizeMode.StretchImage;//画像の比率をそのままに大きさを変える
|
58
|
-
gameBoard_P[i, j].Location = new Point(j * 25, i * 25);
|
59
|
+
gameBoard_P[i, j].Location = new Point(j * 25, i * 25);//画像が表示される場所
|
59
|
-
gameBoard_P[i, j].Image = dataClass.Tetrimino;
|
60
|
+
gameBoard_P[i, j].Image = dataClass.Tetrimino;//画像を設定する
|
60
|
-
this.Controls.Add(this.gameBoard_P[i, j]);
|
61
|
+
this.Controls.Add(this.gameBoard_P[i, j]);//実際に画像をフォームに表示する
|
61
62
|
}
|
62
63
|
else if (i == LimitValue - 1 || i == length - 5)
|
63
64
|
{
|
@@ -71,11 +72,6 @@
|
|
71
72
|
}
|
72
73
|
}
|
73
74
|
}
|
74
|
-
|
75
|
-
//タイマーカウント事に呼び出されるメソッド
|
76
|
-
private void TimerCount_Tick(object sender, EventArgs e)
|
77
|
-
{
|
78
|
-
|
79
|
-
}
|
80
75
|
}
|
81
76
|
}
|
77
|
+
```
|
2
修正点があったのでさらに修正しました。
test
CHANGED
@@ -14,9 +14,9 @@
|
|
14
14
|
internal partial class Form1 : Form
|
15
15
|
{
|
16
16
|
//定数
|
17
|
-
private const byte length = 2
|
17
|
+
private const byte length = 27;//フィールド用。縦の長さ
|
18
18
|
private const byte width = 12;//フィールド用。横の長さ
|
19
|
-
internal const byte LimitValue = 2
|
19
|
+
internal const byte LimitValue = 22;//フィールド用。ゲーム終了のライン
|
20
20
|
|
21
21
|
//画面に表示するためのPictureBox
|
22
22
|
internal PictureBox[,] gameBoard_P;
|
@@ -44,7 +44,7 @@
|
|
44
44
|
this.gameBoard_P = new PictureBox[length, width];
|
45
45
|
|
46
46
|
//PictureBoxを初期盤面に設定する
|
47
|
-
for (int i = 0; i < length; i++)
|
47
|
+
for (int i = 0; i < length - 5; i++)
|
48
48
|
{
|
49
49
|
for (int j = 0; j < width; j++)
|
50
50
|
{
|
@@ -59,13 +59,23 @@
|
|
59
59
|
gameBoard_P[i, j].Image = dataClass.Tetrimino;
|
60
60
|
this.Controls.Add(this.gameBoard_P[i, j]);
|
61
61
|
}
|
62
|
-
else if(i == LimitValue - 1)
|
62
|
+
else if (i == LimitValue - 1 || i == length - 5)
|
63
63
|
{
|
64
|
+
gameBoard_P[i, j].Size = new Size(25, 25);
|
65
|
+
gameBoard_P[i, j].SizeMode = PictureBoxSizeMode.StretchImage;
|
66
|
+
gameBoard_P[i, j].Location = new Point(j * 25, i * 25);
|
67
|
+
gameBoard_P[i, j].Image = dataClass.Tetrimino;
|
64
68
|
this.Controls.Add(this.gameBoard_P[i, j]);
|
65
69
|
}
|
66
70
|
|
67
71
|
}
|
68
72
|
}
|
69
73
|
}
|
74
|
+
|
75
|
+
//タイマーカウント事に呼び出されるメソッド
|
76
|
+
private void TimerCount_Tick(object sender, EventArgs e)
|
77
|
+
{
|
78
|
+
|
79
|
+
}
|
70
80
|
}
|
71
81
|
}
|
1
これでテトリスのように表示されるようになりました。
test
CHANGED
@@ -1,2 +1,71 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
using System.ComponentModel;
|
4
|
+
using System.Data;
|
5
|
+
using System.Drawing;
|
6
|
+
using System.IO;
|
7
|
+
using System.Linq;
|
8
|
+
using System.Text;
|
9
|
+
using System.Threading.Tasks;
|
10
|
+
using System.Windows.Forms;
|
11
|
+
|
12
|
+
namespace Tetris
|
13
|
+
{
|
14
|
+
internal partial class Form1 : Form
|
15
|
+
{
|
16
|
+
//定数
|
17
|
+
private const byte length = 26;//フィールド用。縦の長さ
|
18
|
+
private const byte width = 12;//フィールド用。横の長さ
|
1
|
-
|
19
|
+
internal const byte LimitValue = 21;//フィールド用。ゲーム終了のライン
|
20
|
+
|
21
|
+
//画面に表示するためのPictureBox
|
22
|
+
internal PictureBox[,] gameBoard_P;
|
23
|
+
|
24
|
+
internal Form1()
|
25
|
+
{
|
26
|
+
InitializeComponent();
|
27
|
+
}
|
28
|
+
|
29
|
+
//DataClassをnewして呼び出して使えるようにする
|
30
|
+
private static DataClass dataClass = new DataClass();
|
31
|
+
|
32
|
+
//フォームのロード時に呼ばれるメソッド
|
33
|
+
private void Form1_Load(object sender, EventArgs e)
|
34
|
+
{
|
35
|
+
Initialization(sender, e);
|
36
|
+
}
|
37
|
+
|
2
|
-
|
38
|
+
//初期化用メソッド
|
39
|
+
private void Initialization(object sender, EventArgs e)
|
40
|
+
{
|
41
|
+
dataClass.GameBoardFormat();
|
42
|
+
|
43
|
+
//PictureBoxのインスタンス
|
44
|
+
this.gameBoard_P = new PictureBox[length, width];
|
45
|
+
|
46
|
+
//PictureBoxを初期盤面に設定する
|
47
|
+
for (int i = 0; i < length; i++)
|
48
|
+
{
|
49
|
+
for (int j = 0; j < width; j++)
|
50
|
+
{
|
51
|
+
gameBoard_P[i, j] = new PictureBox();
|
52
|
+
|
53
|
+
//壁のPictureBoxにBitMapを入れる
|
54
|
+
if ((i == 0 || i == length - 1) || (j == 0 || j == width - 1))
|
55
|
+
{
|
56
|
+
gameBoard_P[i, j].Size = new Size(25, 25);
|
57
|
+
gameBoard_P[i, j].SizeMode = PictureBoxSizeMode.StretchImage;
|
58
|
+
gameBoard_P[i, j].Location = new Point(j * 25, i * 25);
|
59
|
+
gameBoard_P[i, j].Image = dataClass.Tetrimino;
|
60
|
+
this.Controls.Add(this.gameBoard_P[i, j]);
|
61
|
+
}
|
62
|
+
else if(i == LimitValue - 1)
|
63
|
+
{
|
64
|
+
this.Controls.Add(this.gameBoard_P[i, j]);
|
65
|
+
}
|
66
|
+
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|