質問編集履歴

4

いただいた修正案を元に修正

2017/09/12 05:41

投稿

sumikko6210
sumikko6210

スコア138

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
 
30
30
 
31
- public static bool deleteFullRows()
31
+ bool deleteFullRows()
32
32
 
33
33
  {
34
34
 
@@ -58,11 +58,7 @@
58
58
 
59
59
  }
60
60
 
61
-
62
-
63
- // Update is called once per frame
64
-
65
- void Update () {
61
+ public void countUp() {
66
62
 
67
63
  if (deleteFullRows())
68
64
 
@@ -70,6 +66,8 @@
70
66
 
71
67
  ++deleteRowsCount;
72
68
 
69
+ RowCount.text = "消えた列:" + deleteRowsCount;
70
+
73
71
  }
74
72
 
75
73
  }
@@ -100,6 +98,8 @@
100
98
 
101
99
  private Vector3 offset;
102
100
 
101
+ private Count count;
102
+
103
103
 
104
104
 
105
105
  //座標が範囲内であるか,Gridに値があるかどうかを判定
@@ -230,9 +230,9 @@
230
230
 
231
231
  transform.position = Grid.roundVec2(currentPosition);
232
232
 
233
- //追加
233
+ //修正
234
-
234
+
235
- Count.deleteFullRows();
235
+ count.countUp();
236
236
 
237
237
  //横列と縦列を消去
238
238
 
@@ -284,32 +284,32 @@
284
284
 
285
285
  {
286
286
 
287
+ count = FindObjectOfType<Count>();
288
+
289
+ }
290
+
291
+
292
+
293
+ // Update is called once per frame
294
+
295
+ void Update()
296
+
297
+ {
298
+
299
+ if (isValidGridPos())
300
+
301
+ {
302
+
303
+ // It's valid. Update grid.
304
+
305
+ updateGrid();
306
+
307
+ }
308
+
309
+
310
+
287
311
 
288
312
 
289
- }
290
-
291
-
292
-
293
- // Update is called once per frame
294
-
295
- void Update()
296
-
297
- {
298
-
299
- if (isValidGridPos())
300
-
301
- {
302
-
303
- // It's valid. Update grid.
304
-
305
- updateGrid();
306
-
307
- }
308
-
309
-
310
-
311
-
312
-
313
313
 
314
314
 
315
315
 

3

コードを変更

2017/09/12 05:41

投稿

sumikko6210
sumikko6210

スコア138

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
 
30
30
 
31
- bool deleteFullRows()
31
+ public static bool deleteFullRows()
32
32
 
33
33
  {
34
34
 
@@ -230,6 +230,10 @@
230
230
 
231
231
  transform.position = Grid.roundVec2(currentPosition);
232
232
 
233
+ //追加
234
+
235
+ Count.deleteFullRows();
236
+
233
237
  //横列と縦列を消去
234
238
 
235
239
  Grid.deleteFullRows();

2

書式の改善

2017/09/11 08:29

投稿

sumikko6210
sumikko6210

スコア138

test CHANGED
File without changes
test CHANGED
@@ -230,6 +230,8 @@
230
230
 
231
231
  transform.position = Grid.roundVec2(currentPosition);
232
232
 
233
+ //横列と縦列を消去
234
+
233
235
  Grid.deleteFullRows();
234
236
 
235
237
  Grid.deleteFullLines();

1

コードの追加

2017/09/09 10:52

投稿

sumikko6210
sumikko6210

スコア138

test CHANGED
File without changes
test CHANGED
@@ -80,6 +80,242 @@
80
80
 
81
81
  ```
82
82
 
83
+ Group.cs
84
+
85
+ ```C#
86
+
87
+ using System.Collections;
88
+
89
+ using System.Collections.Generic;
90
+
91
+ using UnityEngine;
92
+
93
+
94
+
95
+ public class Group : MonoBehaviour
96
+
97
+ {
98
+
99
+ private Vector3 screenPoint;
100
+
101
+ private Vector3 offset;
102
+
103
+
104
+
105
+ //座標が範囲内であるか,Gridに値があるかどうかを判定
106
+
107
+ bool isValidGridPos()
108
+
109
+ {
110
+
111
+ foreach (Transform child in transform)
112
+
113
+ {
114
+
115
+ Vector2 v = Grid.roundVec2(child.position);
116
+
117
+
118
+
119
+ if (!Grid.insideBorder(v))
120
+
121
+ return false;
122
+
123
+
124
+
125
+ if (Grid.grid[(int)v.x, (int)v.y] != null &&
126
+
127
+ Grid.grid[(int)v.x, (int)v.y].parent != transform)
128
+
129
+ return false;
130
+
131
+ }
132
+
133
+ return true;
134
+
135
+ }
136
+
137
+
138
+
139
+ void updateGrid()
140
+
141
+ {
142
+
143
+ for (int y = 0; y < Grid.h; ++y)
144
+
145
+ for (int x = 0; x < Grid.w; ++x)
146
+
147
+ if (Grid.grid[x, y] != null)
148
+
149
+ if (Grid.grid[x, y].parent == transform)
150
+
151
+ Grid.grid[x, y] = null;
152
+
153
+
154
+
155
+ foreach (Transform child in transform)
156
+
157
+ {
158
+
159
+ Vector2 v = Grid.roundVec2(child.position);
160
+
161
+ Grid.grid[(int)v.x, (int)v.y] = child;
162
+
163
+ }
164
+
165
+ }
166
+
167
+
168
+
169
+ //オブジェクトをクリックする
170
+
171
+ void OnMouseDown()
172
+
173
+ {
174
+
175
+ // マウスカーソルは、スクリーン座標なので、
176
+
177
+ // 対象のオブジェクトもスクリーン座標に変換してから計算する。
178
+
179
+
180
+
181
+ // このオブジェクトの位置(transform.position)をスクリーン座標に変換。
182
+
183
+ screenPoint = Camera.main.WorldToScreenPoint(transform.position);
184
+
185
+ // ワールド座標上の、マウスカーソルと、対象の位置の差分。
186
+
187
+ offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
188
+
189
+
190
+
191
+
192
+
193
+ }
194
+
195
+
196
+
197
+ //オブジェクトをドラッグする
198
+
199
+ void OnMouseDrag()
200
+
201
+ {
202
+
203
+ Vector3 currentScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
204
+
205
+ Vector3 currentPosition = Camera.main.ScreenToWorldPoint(currentScreenPoint) + this.offset;
206
+
207
+ transform.position = currentPosition;
208
+
209
+ }
210
+
211
+
212
+
213
+ //オブジェクトをドロップする
214
+
215
+ void OnMouseUp()
216
+
217
+ {
218
+
219
+ Vector3 currentScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
220
+
221
+ Vector3 currentPosition = Camera.main.ScreenToWorldPoint(currentScreenPoint) + this.offset;
222
+
223
+
224
+
225
+ //currentPositionが範囲内であるか,Gridに値があるかどうかを判定
226
+
227
+ if (isValidGridPos())
228
+
229
+ {
230
+
231
+ transform.position = Grid.roundVec2(currentPosition);
232
+
233
+ Grid.deleteFullRows();
234
+
235
+ Grid.deleteFullLines();
236
+
237
+
238
+
239
+ //指定範囲内ではブロックの当たり判定を無くす
240
+
241
+ BoxCollider2D collider = GetComponent<BoxCollider2D>();
242
+
243
+ collider.enabled = false;
244
+
245
+
246
+
247
+ //次のブロックを呼び出す
248
+
249
+ FindObjectOfType<Spawner>().spawnNext();
250
+
251
+
252
+
253
+
254
+
255
+ }
256
+
257
+ else
258
+
259
+ {
260
+
261
+ //Spawnerオブジェクトの座標を取る
262
+
263
+ transform.position = GameObject.Find("Spawner").transform.position;
264
+
265
+ }
266
+
267
+
268
+
269
+ }
270
+
271
+
272
+
273
+
274
+
275
+ // Use this for initialization
276
+
277
+ void Start()
278
+
279
+ {
280
+
281
+
282
+
283
+ }
284
+
285
+
286
+
287
+ // Update is called once per frame
288
+
289
+ void Update()
290
+
291
+ {
292
+
293
+ if (isValidGridPos())
294
+
295
+ {
296
+
297
+ // It's valid. Update grid.
298
+
299
+ updateGrid();
300
+
301
+ }
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+ }
312
+
313
+ }
314
+
315
+
316
+
317
+ ```
318
+
83
319
 
84
320
 
85
321
  Grid.cs