Rumah > Soal Jawab > teks badan
pakej activitytest.example.com.catchcat;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
Taman permainan kelas awam memanjangkan SurfaceView {
apungan statik peribadi LEBAR = 40;
int akhir statik peribadi COL = 10 int akhir statik peribadi ;//Tetapkan bilangan baris
int akhir statik peribadi ROW = 10;//Tetapkan bilangan lajur
int akhir statik peribadi BLOK = 15;//Bilangan sekatan jalan awal ditambah secara lalai
matriks titik peribadi[] [];//Definisi Tatasusunan dua dimensi, mewakili keseluruhan papan catur
kucing Dot peribadi;//takrifkan kucing
Taman Permainan awam(Konteks Konteks) {
super(konteks);
getHolder().addCallback(panggilan balik);
matriks = Titik baharu[ROW][COL ];
untuk(int i=0;i<ROW;i++){
untuk(int j=0;j<COL;j++){
matriks[i][j] = baharu Titik(j,i);
}
Kanvas c = getHolder().lockCanvas();
c.drawColor(Color.LTGRAY);
Paint paint = new Paint();
paint.setFlags(ALIint.setFLAGs(ALIint.setFlags) );//Anti-aliasing
untuk(int i=0 ;i<ROW;i++){
int offset = 0;
if(i%2 != 0){
offset = (int) (WIDTH/2) ;.
pecah;
sarung Dot.STATUS_ON:
cat .setColor(0XFFFFAA00);
pecah;
titik kes.STATUS_IN:
paint.setColor(0XFFFF0000);
; }
c.drawOval(RectF baharu(one.getX()*WIDTH+offset,one.getY()*WIDTH,(satu .getX()+1)*WIDTH+offset,(one.getY()+1)*WIDTH),paint);
}
}
getHolder().unlockCanvasAndPost(c);
panggil balik = SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
readraw();
public void surfaceChanged(SurfaceHolder holder, format int, int width, int height) {
LEBAR = lebar/(COL+1);
readraw();
}
@Override
permukaan kosong awam Dimusnahkan (Pemegang Permukaan)🜎 };
private void initGame(){
for(int i= 0;i<ROW;i++){
untuk(int j=0;j<COL;j++){
matriks[i][j].setStatus(Dot.STATUS_ON ); } } kucing = Titik baharu( 4,5);
getDot(4,5).setStatus(Dot.STATUS_IN);
untuk(int i=0;i<BLOCKS;){
int x = (int)(Math.random()*100() %COL;
int y = (int)(Math.random()*1000)%ROW;
if(getDot(x,y).getStatus() == Dot.STATUS_OFF){
).(x,y) setStatus(Dot.STATUS_ON)