質問するログイン新規登録

回答編集履歴

1

コードの論理を変更

2018/03/17 01:26

投稿

KSwordOfHaste
KSwordOfHaste

スコア18406

answer CHANGED
@@ -24,35 +24,38 @@
24
24
  }
25
25
 
26
26
  function draw() {
27
+ if (stage <= 3) {
27
- // 背景をクリア
28
+ // 背景をクリア
28
- fill(220)
29
+ fill(220)
29
- noStroke()
30
+ noStroke()
30
- rect(0, 0, 400, 400)
31
+ rect(0, 0, 400, 400)
31
- // 三角形を描画
32
- stroke(0)
33
- triangle(50, 250, 350, 250, x, y)
34
32
 
33
+ // 三角形を描画
34
+ stroke(0)
35
+ triangle(50, 250, 350, 250, x, y)
36
+
35
- // 頂点座標を段階に応じて移動
37
+ // 頂点座標を段階に応じて移動
36
- switch (stage) {
38
+ switch (stage) {
37
- case 1:
39
+ case 1:
38
- if (y >= 100) {
40
+ if (y >= 100) {
39
- y--
41
+ y--
40
- break
42
+ break
41
- }
43
+ }
42
- stage++
44
+ stage++
43
- case 2:
45
+ case 2:
44
- if (x <= 200) {
46
+ if (x <= 200) {
45
- x++
47
+ x++
46
- break
48
+ break
47
- }
49
+ }
48
- stage++
50
+ stage++
49
- case 3:
51
+ case 3:
50
- if (x >= 50 && y <= 250) {
52
+ if (x >= 50 && y <= 250) {
51
- x--
53
+ x--
52
- y++
54
+ y++
53
- break
55
+ break
54
- }
56
+ }
55
- stage++
57
+ stage++
58
+ }
56
59
  }
57
60
  }
58
61
  ```
@@ -70,9 +73,12 @@
70
73
  ...
71
74
 
72
75
  function draw() {
76
+ if (stage < operations.length) {
77
+ // 描画など
73
- ...
78
+ ...
74
- if (stage < operations.length && !operations[stage]()) {
79
+ if (!operations[stage]()) {
75
- stage++
80
+ stage++
81
+ }
76
82
  }
77
83
  }
78
84