質問編集履歴
4
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,7 +4,6 @@
|
|
4
4
|
実現したいことは、猫をうえ、した、ひだり、みぎのボタンを押した際に動かすのではなく、「スタートボタン」を押した際に、「プログラムの流れ」欄に表示された通りに猫を動かし、ダイアログを発生させることです。
|
5
5
|
データベースを用いる必要はあるのか…
|
6
6
|
|
7
|
-

|
8
7
|
|
9
8
|
```java
|
10
9
|
public class MainActivity extends AppCompatActivity implements Animator.AnimatorListener {
|
3
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|

|
8
8
|
|
9
9
|
```java
|
10
|
-
public class MainActivity extends AppCompatActivity {
|
10
|
+
public class MainActivity extends AppCompatActivity implements Animator.AnimatorListener {
|
11
11
|
final static float TRANSLATE_X = 310.0f; // 1回の操作でX軸方向にいくつ動かすか
|
12
12
|
final static float TRANSLATE_Y = 310.0f; // 1回の操作でY軸方向にいくつ動かすか
|
13
13
|
|
@@ -15,6 +15,7 @@
|
|
15
15
|
private int x = 0;
|
16
16
|
private int y = 0;
|
17
17
|
private String text;
|
18
|
+
private ArrayList<Integer> arrayList ;
|
18
19
|
|
19
20
|
@Override
|
20
21
|
protected void onCreate(Bundle savedInstanceState) {
|
@@ -26,102 +27,85 @@
|
|
26
27
|
Button btn3 = (Button) findViewById(R.id.button3); // ひだり
|
27
28
|
Button btn4 = (Button) findViewById(R.id.button4); // みぎ
|
28
29
|
Button btn5 = (Button) findViewById(R.id.button5); // やりなおし
|
30
|
+
Button btn6 = (Button) findViewById(R.id.button6); // スタート
|
29
31
|
|
30
32
|
text = "";
|
31
33
|
final TextView result = (TextView) findViewById(R.id.result);
|
32
34
|
result.setText("");
|
33
35
|
|
36
|
+
arrayList = new ArrayList<>();
|
34
37
|
|
38
|
+
|
35
39
|
btn1.setOnClickListener(new View.OnClickListener() {
|
36
40
|
@Override
|
37
41
|
public void onClick(View v) {
|
42
|
+
arrayList.add(upAnimation();
|
38
43
|
// 「うえ」を押したときの処理
|
39
44
|
if (y > -3) {
|
40
|
-
float start = TRANSLATE_Y * y;
|
41
|
-
float end = start - TRANSLATE_Y;
|
42
|
-
animationImageView("translationY", start, end);
|
43
|
-
y--;
|
44
|
-
|
45
45
|
TextView result = (TextView) findViewById(R.id.result);
|
46
46
|
text += "<font color=#98fb98>↑</font>";
|
47
47
|
result.setText(Html.fromHtml(text));
|
48
|
-
|
49
|
-
encountDog();
|
50
48
|
}
|
51
49
|
}
|
52
50
|
});
|
53
51
|
btn2.setOnClickListener(new View.OnClickListener() {
|
54
52
|
@Override
|
55
53
|
public void onClick(View v) {
|
54
|
+
arrayList.add(downAnimation();
|
56
55
|
// 「した」を押したときの処理
|
57
56
|
if (y < 0) {
|
58
|
-
float start = TRANSLATE_Y * y;
|
59
|
-
float end = start + TRANSLATE_Y;
|
60
|
-
animationImageView("translationY", start, end);
|
61
|
-
y++;
|
62
|
-
|
63
57
|
TextView result = (TextView) findViewById(R.id.result);
|
64
58
|
text += "<font color=#fffacd>↓</font>";
|
65
59
|
result.setText(Html.fromHtml(text));
|
66
|
-
|
67
|
-
encountDog();
|
68
60
|
}
|
69
61
|
}
|
70
62
|
});
|
71
63
|
btn3.setOnClickListener(new View.OnClickListener() {
|
72
64
|
@Override
|
73
65
|
public void onClick(View v) {
|
66
|
+
arrayList.add(leftAnimation();
|
74
67
|
// 「ひだり」を押したときの処理
|
75
68
|
if (x > 0) {
|
76
|
-
float start = TRANSLATE_X * x;
|
77
|
-
float end = start - TRANSLATE_X;
|
78
|
-
animationImageView("translationX", start, end);
|
79
|
-
x--;
|
80
|
-
|
81
69
|
TextView result = (TextView) findViewById(R.id.result);
|
82
70
|
text += "<font color=#ffc0cb>←</font>";
|
83
71
|
result.setText(Html.fromHtml(text));
|
84
|
-
|
85
|
-
encountDog();
|
86
72
|
}
|
87
73
|
}
|
88
74
|
});
|
89
75
|
btn4.setOnClickListener(new View.OnClickListener() {
|
90
76
|
@Override
|
91
77
|
public void onClick(View v) {
|
78
|
+
arrayList.add(rightAnimation();
|
92
79
|
// 「みぎ」を押したときの処理
|
93
80
|
if (x < 2) {
|
94
|
-
float start = TRANSLATE_X * x;
|
95
|
-
float end = start + TRANSLATE_X;
|
96
|
-
animationImageView("translationX", start, end);
|
97
|
-
x++;
|
98
|
-
|
99
81
|
TextView result = (TextView) findViewById(R.id.result);
|
100
82
|
text += "<font color=#afeeee>→</font>";
|
101
83
|
result.setText(Html.fromHtml(text));
|
102
|
-
|
103
|
-
encountDog();
|
104
84
|
}
|
105
85
|
}
|
106
86
|
});
|
107
87
|
btn5.setOnClickListener(new View.OnClickListener() {
|
108
88
|
@Override
|
109
89
|
public void onClick(View v) {
|
110
|
-
x = 0;
|
111
|
-
y = 0;
|
112
|
-
animationImageReset();
|
113
|
-
|
114
90
|
text = "";
|
115
91
|
TextView result = (TextView) findViewById(R.id.result);
|
116
92
|
result.setText("");
|
117
93
|
}
|
118
94
|
});
|
95
|
+
btn6.setOnClickListener(new View.OnClickListener(){
|
96
|
+
@Override
|
97
|
+
public void onClick(View v) {
|
98
|
+
for(int i=0; i< arrayList.size(); i++){
|
99
|
+
}
|
100
|
+
}
|
101
|
+
});
|
119
102
|
}
|
120
103
|
|
121
104
|
private void animationImageView(String property, float start, float end) {
|
122
105
|
ImageView imageView = (ImageView) findViewById(MyCat);
|
123
106
|
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, property, start, end);
|
124
107
|
animator.setDuration(1000);
|
108
|
+
animator.addListener(this);
|
125
109
|
animator.start();
|
126
110
|
}
|
127
111
|
|
@@ -167,5 +151,62 @@
|
|
167
151
|
dl.show();
|
168
152
|
}
|
169
153
|
}
|
154
|
+
@Override
|
155
|
+
public void onAnimationStart(Animator animation) {
|
156
|
+
}
|
157
|
+
|
158
|
+
@Override
|
159
|
+
public void onAnimationEnd(Animator animation) {
|
160
|
+
// アニメーションが終了するとここが実行される
|
161
|
+
}
|
162
|
+
|
163
|
+
@Override
|
164
|
+
public void onAnimationCancel(Animator animation) {
|
165
|
+
}
|
166
|
+
|
167
|
+
@Override
|
168
|
+
public void onAnimationRepeat(Animator animation) {
|
169
|
+
}
|
170
|
+
|
171
|
+
private void upAnimation(){
|
172
|
+
// 「うえ」を押したときの処理
|
173
|
+
if (y > -3) {
|
174
|
+
float start = TRANSLATE_Y * y;
|
175
|
+
float end = start - TRANSLATE_Y;
|
176
|
+
animationImageView("translationY", start, end);
|
177
|
+
y--;
|
178
|
+
encountDog();
|
179
|
+
}
|
180
|
+
}
|
181
|
+
private void downAnimation(){
|
182
|
+
// 「した」を押したときの処理
|
183
|
+
if (y < 0) {
|
184
|
+
float start = TRANSLATE_Y * y;
|
185
|
+
float end = start + TRANSLATE_Y;
|
186
|
+
animationImageView("translationY", start, end);
|
187
|
+
y++;
|
188
|
+
encountDog();
|
189
|
+
}
|
190
|
+
}
|
191
|
+
private void leftAnimation(){
|
192
|
+
// 「ひだり」を押したときの処理
|
193
|
+
if (x > 0) {
|
194
|
+
float start = TRANSLATE_X * x;
|
195
|
+
float end = start - TRANSLATE_X;
|
196
|
+
animationImageView("translationX", start, end);
|
197
|
+
x--;
|
198
|
+
encountDog();
|
199
|
+
}
|
200
|
+
}
|
201
|
+
private void rightAnimation(){
|
202
|
+
// 「みぎ」を押したときの処理
|
203
|
+
if (x < 2) {
|
204
|
+
float start = TRANSLATE_X * x;
|
205
|
+
float end = start + TRANSLATE_X;
|
206
|
+
animationImageView("translationX", start, end);
|
207
|
+
x++;
|
208
|
+
encountDog();
|
209
|
+
}
|
210
|
+
}
|
170
211
|
}
|
171
212
|
```
|
2
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
画面右側は問題、操作画面(上下左右)、左側でねこが動きます。現段階では、操作ボタン(button1…うえ、button2…した、button3…ひだり、button4…みぎ)を押したら猫が一マスずつ移動します。また、障害物である犬の位置に到達すると初期位置に戻るためのダイアログが発生し、家に到達すると「せいかい!」のダイアログが発生します。さらに、ボタンを押した際、プログラムの流れの欄に矢印マーク(↑↓→←)が順番に表示されます。
|
2
2
|
ここでは、猫の位置を管理するために変数xと変数yを使用しています。
|
3
3
|
|
4
|
-
実現したいことは、猫をうえ、した、ひだり、みぎのボタンを押した際に動かすのではなく、「スタートボタン」を押した際に、プログラムの流れ通りに猫を動かし、ダイアログを発生させることです。
|
4
|
+
実現したいことは、猫をうえ、した、ひだり、みぎのボタンを押した際に動かすのではなく、「スタートボタン」を押した際に、「プログラムの流れ」欄に表示された通りに猫を動かし、ダイアログを発生させることです。
|
5
5
|
データベースを用いる必要はあるのか…
|
6
6
|
|
7
7
|

|
1
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
画面右側は問題、操作画面(上下左右)、左側でねこが動きます。現段階では、操作ボタン(button1…うえ、button2…した、button3…ひだり、button4…みぎ)を押したら猫が一マスずつ移動します。また、障害物である犬の位置に到達すると初期位置に戻るためのダイアログが発生し、家に到達すると「せいかい!」のダイアログが発生します。さらに、ボタンを押した際、プログラムの流れの欄に矢印マーク(↑↓→←)が順番に表示されます。
|
2
2
|
ここでは、猫の位置を管理するために変数xと変数yを使用しています。
|
3
3
|
|
4
|
-
実現したいことは、猫をうえ、した、ひだり、みぎのボタンを押した際に動かすのではなく、「スタートボタン」
|
4
|
+
実現したいことは、猫をうえ、した、ひだり、みぎのボタンを押した際に動かすのではなく、「スタートボタン」を押した際に、プログラムの流れ通りに猫を動かし、ダイアログを発生させることです。
|
5
5
|
データベースを用いる必要はあるのか…
|
6
6
|
|
7
7
|

|