search

Home  >  Q&A  >  body text

I typed the same thing as the teacher, why can’t the interface be displayed?

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;//Set the number of rows
private static final int ROW = 10;//Set the number of columns
private static final int BLOCKS = 15;//Add the initial number of roadblocks by default
private Dot matrix[][];//Define a two-dimensional array to represent the entire chessboard
private Dot cat;//Define cat
public Playground(Context context) {
super(context);
getHolder().addCallback(callback);
matrix = new Dot[ROW][COL];
for(int i=0;i<ROW;i ){
            for(int j=0;j<COL;j ){
                    matrix[i][j] = new Dot(j,i);
}
    }
      initGame();
    }
    private Dot getDot(int x,int y){
        return matrix[y][x];
    }

private void readraw() {//Implement the drawing of the interface
Canvas c = getHolder().lockCanvas();
c.drawColor(Color.LTGRAY);
Paint paint = new Paint() ;
paint.setFlags(Paint.ANTI_ALIAS_FLAG);//Anti-aliasing
for(int i=0;i<ROW;i){
int offset = 0;
if(i%2 , i) ;                                   break; .setColor(0XFFFFAA00);
                       break;
                   case Dot.STATUS_IN:
                       paint.setColor(0XFFFF0000);
                       break;

               }
               c.drawOval(new RectF(one.getX()*WIDTH offset,one.getY()*WIDTH,(one.getX() 1)*WIDTH offset,(one.getY() 1)*WIDTH),paint);
           }
       }
       getHolder().unlockCanvasAndPost(c);
   }

   SurfaceHolder.Callback callback = new SurfaceHolder.Callback() {
       @Override
       public void surfaceCreated(SurfaceHolder holder) {
           readraw();
       }

       @Override
       public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
           WIDTH = width/(COL 1);
           readraw();

       }

       @Override
       public void surfaceDestroyed(SurfaceHolder holder) {

       }
   };
   private void initGame(){
       for(int i=0;i<ROW;i ){
           for(int j=0;j<COL;j ){
               matrix[i][j].setStatus(Dot.STATUS_ON);
           }
       }
       cat = new Dot(4,5);
       getDot(4,5).setStatus(Dot.STATUS_IN);
       for(int i=0;i<BLOCKS;){
           int x = (int)(Math.random()*1000)%COL;
           int y = (int)(Math.random()*1000)%ROW;
           if(getDot(x,y).getStatus() == Dot.STATUS_OFF){
               getDot(x,y).setStatus(Dot.STATUS_ON);
               i ;
               System.out.println("BLOCKS" i);
           }
       }
   }

}

依恋依恋2054 days ago1233

reply all(0)I'll reply

No reply
  • Cancelreply