package 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;
public class Playground extends SurfaceView {
private static float WIDTH = 40;
private static final int COL = 10;//設定行數
# # private int COL = 10;//設定行數
#. # private static final int BLOCKS = 15;//預設加入初始時候路障的數量
private Dot matrix[][];//定義二維數組,表示整個棋盤
private Dot cat;//定義貓
public Playground(Context context) {
super(context);
getHolder().addCallback(callback);#coofor RO i=0;i<ROW;i ){
for(int j=0;j<COL;j ){
trix ## 時}
}
initGame();
}
private Dot getDot(int x,) ## private void readraw() {//實作介面的繪製
Canvas c = getHolder().lockCanvas();
;
paint.setFlags(Paint.ANTI_ALIAS_FLAG);//抗鋸齒
for(int i=0;i<¡ if(i%2 != 0){
offset = (int) (WIDTH/2);
}
amp Dot one = getDot(j, i);
switch(one.getStatus()){
paint.setColor(0XFFEEEEEE);
break;
paint .setColor(0XFFFFAA00);
break;
case Dot.STATUS_IN:
break;
}
## }
## 移量,one.getY()*WIDTH,(one.getX() 1)*WIDTH 偏移量,(one.getY() 1)*WIDTH),paint);
}
}
# getHolder() .unlockCanvasAndPost(c);
}
SurfaceHolder.Callback 回呼= new SurfaceHolder.Callback() {# 合適urfaceHolderholder) {
readraw() ;
}
## @Override
public void surChanged(Sur th/(COL 1);
readraw( );
}
# @Override
public void ) ate void initGame(){
for(int i=0;i