質問編集履歴
2
コードを```で囲みました
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
|
62
62
|
|
63
|
-
import UIKit
|
63
|
+
```import UIKit
|
64
64
|
|
65
65
|
import SpriteKit
|
66
66
|
|
@@ -558,7 +558,7 @@
|
|
558
558
|
|
559
559
|
|
560
560
|
|
561
|
-
|
561
|
+
func resetButtonHightlights() {
|
562
562
|
|
563
563
|
|
564
564
|
|
@@ -576,7 +576,7 @@
|
|
576
576
|
|
577
577
|
|
578
578
|
|
579
|
-
|
579
|
+
func disableButtons () {
|
580
580
|
|
581
581
|
for button in soundButton {
|
582
582
|
|
@@ -588,7 +588,7 @@
|
|
588
588
|
|
589
589
|
|
590
590
|
|
591
|
-
|
591
|
+
func enableButtons() {
|
592
592
|
|
593
593
|
for button in soundButton {
|
594
594
|
|
@@ -600,7 +600,7 @@
|
|
600
600
|
|
601
601
|
|
602
602
|
|
603
|
-
|
603
|
+
func didReceiveMemoryWarning(){
|
604
604
|
|
605
605
|
super.didReceiveMemoryWarning()
|
606
606
|
|
@@ -608,19 +608,7 @@
|
|
608
608
|
|
609
609
|
|
610
610
|
|
611
|
-
|
611
|
+
```
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
}
|
618
|
-
|
619
|
-
}
|
620
|
-
|
621
|
-
}
|
622
|
-
|
623
|
-
|
624
612
|
|
625
613
|
|
626
614
|
|
1
写真をエラー部分のみにし、全体のコードをコピーペーストしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
2〜
|
23
|
+
(※エラーは下記の写真(2〜3)の2箇所です)
|
24
24
|
|
25
25
|
|
26
26
|
|
@@ -30,27 +30,597 @@
|
|
30
30
|
|
31
31
|
|
32
32
|
|
33
|
+
|
34
|
+
|
33
35
|
2
|
34
36
|
|
35
|
-
![イメージ説明](
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
3
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
37
|
+
![イメージ説明](fd5fc029eccdb1f41ba299131a5f8e80.png)
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
3
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
![![イメージ説明](6772fad5d8f9dd12db11858c84c08ea0.png)]
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
import UIKit
|
64
|
+
|
65
|
+
import SpriteKit
|
66
|
+
|
67
|
+
import GameplayKit
|
68
|
+
|
69
|
+
import AVFoundation
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
class GameViewController: UIViewController,AVAudioPlayerDelegate {
|
76
|
+
|
77
|
+
@IBOutlet weak var startGameButton: UIButton!
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
@IBOutlet var soundButton: [UIButton]!
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
@IBOutlet weak var levelLabel: UILabel!
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
var sound1Player:AVAudioPlayer!
|
90
|
+
|
91
|
+
var sound2Player:AVAudioPlayer!
|
92
|
+
|
93
|
+
var sound3Player:AVAudioPlayer!
|
94
|
+
|
95
|
+
var sound4Player:AVAudioPlayer!
|
96
|
+
|
97
|
+
var PlayList = [Int]()
|
98
|
+
|
99
|
+
var currenItem = 0
|
100
|
+
|
101
|
+
var numberOfTaps = 0
|
102
|
+
|
103
|
+
var readyForUser = false
|
104
|
+
|
105
|
+
var level = 1
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
override func viewDidLoad() {
|
110
|
+
|
111
|
+
super.viewDidLoad()
|
112
|
+
|
113
|
+
setupAudioFiles()
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
func setupAudioFiles(){
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
let soundFilePath = Bundle.main.path(forResource:"1", ofType: "wav")
|
124
|
+
|
125
|
+
let soundFileURL = URL(fileURLWithPath: soundFilePath!)
|
126
|
+
|
127
|
+
let soundFilePath2 = Bundle.main.path(forResource:"2", ofType: "wav")
|
128
|
+
|
129
|
+
let soundFileURL2 = URL(fileURLWithPath: soundFilePath2!)
|
130
|
+
|
131
|
+
let soundFilePath3 = Bundle.main.path(forResource:"3", ofType: "wav")
|
132
|
+
|
133
|
+
let soundFileURL3 = URL(fileURLWithPath: soundFilePath3!)
|
134
|
+
|
135
|
+
let soundFilePath4 = Bundle.main.path(forResource:"4", ofType: "wav")
|
136
|
+
|
137
|
+
let soundFileURL4 = URL(fileURLWithPath: soundFilePath4!)
|
138
|
+
|
139
|
+
do{
|
140
|
+
|
141
|
+
sound1Player = try AVAudioPlayer(contentsOf: soundFileURL)
|
142
|
+
|
143
|
+
sound2Player = try AVAudioPlayer(contentsOf: soundFileURL2)
|
144
|
+
|
145
|
+
sound3Player = try AVAudioPlayer(contentsOf: soundFileURL3)
|
146
|
+
|
147
|
+
sound4Player = try AVAudioPlayer(contentsOf: soundFileURL4)
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
} catch {
|
152
|
+
|
153
|
+
print(error)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
sound1Player.delegate = self
|
162
|
+
|
163
|
+
sound2Player.delegate = self
|
164
|
+
|
165
|
+
sound3Player.delegate = self
|
166
|
+
|
167
|
+
sound4Player.delegate = self
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
sound1Player.numberOfLoops = 0
|
172
|
+
|
173
|
+
sound2Player.numberOfLoops = 0
|
174
|
+
|
175
|
+
sound3Player.numberOfLoops = 0
|
176
|
+
|
177
|
+
sound4Player.numberOfLoops = 0
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
@IBAction func soundButtonPressed(_ sender: AnyObject) {
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
if readyForUser {
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
let button = sender as! UIButton
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
switch button.tag {
|
198
|
+
|
199
|
+
case 1:
|
200
|
+
|
201
|
+
sound1Player.play()
|
202
|
+
|
203
|
+
checkIfCorrect(buttonPressed: 1)
|
204
|
+
|
205
|
+
case 2:
|
206
|
+
|
207
|
+
sound2Player.play()
|
208
|
+
|
209
|
+
checkIfCorrect(buttonPressed: 2)
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
case 3:
|
214
|
+
|
215
|
+
sound3Player.play()
|
216
|
+
|
217
|
+
checkIfCorrect(buttonPressed: 3)
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
case 4:
|
222
|
+
|
223
|
+
sound4Player.play()
|
224
|
+
|
225
|
+
checkIfCorrect(buttonPressed: 4)
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
break
|
232
|
+
|
233
|
+
default:
|
234
|
+
|
235
|
+
break
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
func checkIfCorrect (buttonPressed:Int){
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
if buttonPressed == PlayList[numberOfTaps] {
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
if numberOfTaps == PlayList.count - 1 { //we have arrived at the last item of the playList
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
let time = DispatchTime.now(dispatch_time_t(DISPATCH_TIME_NOW),Int64(NSEC_PER_SEC))
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
dispatch_after(time, DispatchQueue.main, {
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
self.nextRound()
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
})
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
return
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
numberOfTaps += 1
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
}else{//GAME OVER
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
resetGame()
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
func resetGame() {
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
level = 1
|
314
|
+
|
315
|
+
readyForUser = false
|
316
|
+
|
317
|
+
numberOfTaps = 0
|
318
|
+
|
319
|
+
currenItem = 0
|
320
|
+
|
321
|
+
PlayList = []
|
322
|
+
|
323
|
+
levelLabel.text = "GAME OVER"
|
324
|
+
|
325
|
+
startGameButton.isHidden = false
|
326
|
+
|
327
|
+
disableButtons()
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
func nextRound() {
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
level += 1
|
340
|
+
|
341
|
+
levelLabel.text = "level\(level)"
|
342
|
+
|
343
|
+
readyForUser = false
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
numberOfTaps = 0
|
348
|
+
|
349
|
+
currenItem = 0
|
350
|
+
|
351
|
+
disableButtons()
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
let randomNumber = Int(arc4random_uniform(4) + 1)
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
PlayList.append(randomNumber)
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
playNextItem()
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
@IBAction func startGame(_ sender: AnyObject) {
|
376
|
+
|
377
|
+
disableButtons()
|
378
|
+
|
379
|
+
levelLabel.text = "Lebel 1"
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
let randomNunber = Int(arc4random_uniform(4) + 1)
|
388
|
+
|
389
|
+
PlayList.append(randomNunber)
|
390
|
+
|
391
|
+
startGameButton.isHidden = true
|
392
|
+
|
393
|
+
playNextItem()
|
394
|
+
|
395
|
+
disableButtons()
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
if currenItem <= PlayList.count - 1{
|
410
|
+
|
411
|
+
playNextItem()
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
}else{
|
416
|
+
|
417
|
+
readyForUser = true
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
}
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
}
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
func playNextItem(){
|
432
|
+
|
433
|
+
let selectedItem = PlayList[currenItem]
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
switch selectedItem {
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
case 1:
|
442
|
+
|
443
|
+
highlightButtonWithTag (tag: 1)
|
444
|
+
|
445
|
+
sound1Player.play()
|
446
|
+
|
447
|
+
break
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
case 2:
|
452
|
+
|
453
|
+
highlightButtonWithTag (tag: 2)
|
454
|
+
|
455
|
+
sound2Player.play()
|
456
|
+
|
457
|
+
break
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
case 3:
|
462
|
+
|
463
|
+
highlightButtonWithTag (tag: 3)
|
464
|
+
|
465
|
+
sound3Player.play()
|
466
|
+
|
467
|
+
break
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
case 4:
|
472
|
+
|
473
|
+
highlightButtonWithTag (tag: 4)
|
474
|
+
|
475
|
+
sound4Player.play()
|
476
|
+
|
477
|
+
break
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
default:
|
482
|
+
|
483
|
+
break;
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
}
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
currenItem += 1
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
}
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
func highlightButtonWithTag (tag:Int){
|
504
|
+
|
505
|
+
switch tag {
|
506
|
+
|
507
|
+
case 1:
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
soundButton[tag - 1].setImage(UIImage(named:"redPressed"), for: .normal)
|
512
|
+
|
513
|
+
case 2:
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
soundButton[tag - 1].setImage(UIImage(named:"redPressed"), for: .normal)
|
518
|
+
|
519
|
+
case 3:
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
soundButton[tag - 1].setImage(UIImage(named:"redPressed"), for: .normal)
|
524
|
+
|
525
|
+
case 4:
|
526
|
+
|
527
|
+
|
528
|
+
|
529
|
+
soundButton[tag - 1].setImage(UIImage(named:"redPressed"), for: .normal)
|
530
|
+
|
531
|
+
default:
|
532
|
+
|
533
|
+
break
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
}
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
}
|
542
|
+
|
543
|
+
func resetButtonHightlights() {
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
soundButton[1].setImage(UIImage(named:"blue"),for: .normal)
|
548
|
+
|
549
|
+
soundButton[2].setImage(UIImage(named:"green"),for: .normal)
|
550
|
+
|
551
|
+
soundButton[3].setImage(UIImage(named:"red"),for: .normal)
|
552
|
+
|
553
|
+
soundButton[4].setImage(UIImage(named:"purple"),for: .normal)
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
}
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
func resetButtonHightlights() {
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
soundButton[1].setImage(UIImage(named:"bluePressed"),for: .normal)
|
566
|
+
|
567
|
+
soundButton[2].setImage(UIImage(named:"greenPressed"),for: .normal)
|
568
|
+
|
569
|
+
soundButton[3].setImage(UIImage(named:"redPressed"),for: .normal)
|
570
|
+
|
571
|
+
soundButton[4].setImage(UIImage(named:"pueplePressed"),for: .normal)
|
572
|
+
|
573
|
+
|
574
|
+
|
575
|
+
}
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
func disableButtons () {
|
580
|
+
|
581
|
+
for button in soundButton {
|
582
|
+
|
583
|
+
button.isUserInteractionEnabled = false
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
}
|
588
|
+
|
589
|
+
|
590
|
+
|
591
|
+
func enableButtons() {
|
592
|
+
|
593
|
+
for button in soundButton {
|
594
|
+
|
595
|
+
button.isUserInteractionEnabled = true
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
}
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
func didReceiveMemoryWarning(){
|
604
|
+
|
605
|
+
super.didReceiveMemoryWarning()
|
606
|
+
|
607
|
+
// Release any cached data, images, etc that aren't in use.
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
}
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
}
|
618
|
+
|
619
|
+
}
|
620
|
+
|
621
|
+
}
|
622
|
+
|
623
|
+
|
54
624
|
|
55
625
|
|
56
626
|
|