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

質問編集履歴

1

ballクラス(ボール)とHoleクラス(ゴール地点)についてのコードを追記しました。

2020/05/19 10:35

投稿

handlehandle
handlehandle

スコア2

title CHANGED
File without changes
body CHANGED
@@ -147,6 +147,48 @@
147
147
 
148
148
  ```
149
149
 
150
+ ```Java
151
+ public class Ball extends View {
152
+ int x, y, radius;
153
+ float vx, vy;
154
+ Paint paint;
155
+
156
+ public Ball(Context context) {
157
+ super(context);
158
+ radius = 90;
159
+ vx = vy = x = y = 0;
160
+ paint = new Paint();
161
+ paint.setColor(Color.WHITE);
162
+ paint.setStyle(Paint.Style.FILL);
163
+ }
164
+ protected void onDraw(Canvas canvas){
165
+ super.onDraw(canvas);
166
+ canvas.drawCircle(x, y, radius, paint);
167
+ }
168
+ }
169
+ ```
170
+ ```Java
171
+ public class Hole extends View {
172
+ int x, y, r;
173
+ Paint p;
174
+
175
+ public Hole(Context context){
176
+ super(context);
177
+ x = y = 0;
178
+ r = 100;
179
+ p = new Paint();
180
+ p.setColor(Color.BLACK);
181
+ p.setStyle(Paint.Style.FILL);
182
+ p.setAntiAlias(true);
183
+ }
184
+ protected void onDraw(Canvas canvas) {
185
+ super.onDraw(canvas);
186
+ canvas.drawCircle(x, y, r, p);
187
+ }
188
+ }
189
+ ```
190
+
191
+
150
192
  ```Java(activity_main.xml)
151
193
  <?xml version="1.0" encoding="utf-8"?>
152
194
  <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"