im trying to make a game that when a user clicks on a green button it disappears but when a user clicks on a red button they loose im having trouble displaying multiple random buttons continuously on forever onto the screen here is my code
package com.Tripps.thesimplegame;
import java.util.Random;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Paint.FontMetrics;
import android.util.AttributeSet;
import android.view.View;
public class DrawingView extends View {
int mBackgroundColor = 000000;
String yo = "#";
Paint paint;
final float radius = 230f;
private long lastUpdated = 0;
private int lastColor = Color.BLACK;
public DrawingView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public DrawingView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public DrawingView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// TODO Auto-generated constructor stub
}
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas){
String str = "Joke of the day";
super.onDraw(canvas);
paint = new Paint();
Random random = new Random();
Random randomTwo = new Random();
//Rect ourRect = new Rect();
Rect topRect = new Rect();
Rect backGround = new Rect();
paint.setColor(Color.BLACK);
backGround.set(0,0,canvas.getWidth(),canvas.getHeight());
canvas.drawRect(backGround, paint);
while(System.currentTimeMillis() > lastUpdated + 1000){
lastColor = random.nextInt(2) == 1 ? Color.RED : Color.GREEN;
lastUpdated = System.currentTimeMillis();
paint.setColor(lastColor);
canvas.drawCircle(random.nextInt((int) (canvas.getWidth()-radius/2)) + radius/2f, random.nextInt((int) (canvas.getHeight()-radius/2)) + radius/2f, radius, paint);
}
}
}
Aucun commentaire:
Enregistrer un commentaire