Toggle Theme Editor
Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Charcoal

Help Me ! Xin Hỏi Cách Sủa Lỗi

Discussion in 'Lập trình Android' started by monody, 15/7/19.

  1. monody

    monody New Member

    package lengoc.hn.fish;
    import android.content.Context;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.Point;
    import android.graphics.Rect;
    import android.graphics.Typeface;
    import android.media.AudioManager;
    import android.media.SoundPool;
    import android.support.v7.app.AppCompatActivity;
    import android.view.Display;
    import android.view.MotionEvent;
    import android.view.View;

    import java.util.Random;
    public class GameView extends View {
    private Bitmap background;
    private int dWidth,dHeight;
    private Rect rect;
    private Bitmap water;
    private int x1 ,y1,x2,y2;
    private Bitmap[] fish;
    private int fishX = 10;
    private int fishY;
    private int fishSpeed ,fishCounter;
    public int maxFishY;
    public int minFishY;
    //ca map
    private Bitmap[] shank = new Bitmap[3];
    private int shankX, shankY , shankSpeed , shankFrame;
    Random random;
    //ca vang
    private Bitmap[] yellowFish = new Bitmap[2];
    private int yellowFishX ,yellowFishY, yellowFishSpeed,yellowFishFrame;
    //Rua
    private Bitmap[] turtle = new Bitmap[2];
    private int turtleX, turtleY,turtleSpeed,turtleFrame;
    //ca do
    private Bitmap[] redFish = new Bitmap[3];
    private int redFishX, redFishY, redFishSpeed, redFishFrame;
    //may
    private Bitmap clound1;
    private int clound1X, clound1Y, cloundSpeed;
    private Bitmap clound2;
    private int clound2X, clound2Y, clound2Speed;
    //bong
    private Bitmap ball;
    private int ballX, ballY, ballSpeed;
    //diem
    private Paint scorePaint = new Paint();
    private int score;
    private SoundPool audio;
    private int id_Audio;

    public GameView(Context context) {
    super(context);
    background = BitmapFactory.decodeResource(getResources(),R.drawable.background);
    water = BitmapFactory.decodeResource(getResources(),R.drawable.test);
    x1 =0;y1 =-10;x2 = x1 + water.getWidth();y2=-10;
    Display display = ((AppCompatActivity) getContext()).getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    dWidth = size.x;
    dHeight = size.y;
    rect = new Rect(0,0,dWidth,dHeight);
    fish = new Bitmap[2];
    fish[0] = BitmapFactory.decodeResource(getResources(),R.drawable.caheo1);
    fish[1] = BitmapFactory.decodeResource(getResources(),R.drawable.caheo2);
    //diem
    scorePaint.setColor(Color.BLUE);
    scorePaint.setTextSize(70);
    scorePaint.setTypeface(Typeface.DEFAULT_BOLD);
    scorePaint.setAntiAlias(true);
    score = 0;
    //ca map
    shank[0] = BitmapFactory.decodeResource(getResources(),R.drawable.camap1);
    shank[1] = BitmapFactory.decodeResource(getResources(),R.drawable.camap2);
    shank[2] = BitmapFactory.decodeResource(getResources(),R.drawable.camap3);
    random = new Random();
    resetPositionShank();
    //ca vang
    yellowFish[0] = BitmapFactory.decodeResource(getResources(),R.drawable.cavang1);
    yellowFish[1] = BitmapFactory.decodeResource(getResources(),R.drawable.cavang2);
    resetPositionYellowFish();
    //rua
    turtle[0] = BitmapFactory.decodeResource(getResources(),R.drawable.rua1);
    turtle[1] = BitmapFactory.decodeResource(getResources(),R.drawable.rua2);
    resetPositionTurtle();
    //ca do
    redFish[0] = BitmapFactory.decodeResource(getResources(),R.drawable.ca1);
    redFish[1] = BitmapFactory.decodeResource(getResources(),R.drawable.ca2);
    redFish[2] = BitmapFactory.decodeResource(getResources(),R.drawable.ca3);
    resetPositionRedFish();
    //may
    clound1 = BitmapFactory.decodeResource(getResources(),R.drawable.may1);
    resetPositionClound();
    clound2 = BitmapFactory.decodeResource(getResources(),R.drawable.may2);
    resetPositionClound2();
    //bong
    ball = BitmapFactory.decodeResource(getResources(),R.drawable.ball);
    resetPositionBall();
    //am thanh
    audio = new SoundPool(1, AudioManager.STREAM_MUSIC,0);
    id_Audio = audio.load(getContext(),R.raw.cut,1);
    }

    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawBitmap(background,null,rect,null);
    canvas.drawBitmap(water,x1,y1,null);
    canvas.drawBitmap(water,x2,y2,null);
    x1-=2;
    x2-=2;
    if(x2 <0){
    x1 = x2+water.getWidth();
    }
    if(x1 <0){
    x2 = x1+water.getWidth();
    }
    //ca heo:
    minFishY = fish[0].getHeight();
    maxFishY = dHeight - fish[0].getHeight();
    fishY = fishY + fishSpeed;
    if (fishY < minFishY) {
    fishY = minFishY;
    }
    if (fishY > maxFishY) {
    fishY = maxFishY;
    }
    fishSpeed = fishSpeed +1;
    canvas.drawBitmap(fish[fishCounter],fishX,fishY,null);
    fishCounter++;
    if (fishCounter > 1) {
    fishCounter = 0;
    }
    //ca map
    shankX -= shankSpeed;
    canvas.drawBitmap(shank[shankFrame],shankX,shankY,null);
    shankFrame++;
    if (shankFrame>1){
    shankFrame=0;
    }
    if (shankX < -shank[0].getWidth()){
    resetPositionShank();
    }
    if(hitChecker(shankX,shankY+ shank[0].getHeight()/2)){
    audio.play(id_Audio,1.0f,1.0f,1,0,1.0f);
    canvas.drawBitmap(shank[2],shankX,shankY,null);
    fishX -=500;
    Intent gameOver = new Intent(getContext(),GameOverActivity.class);
    gameOver.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    gameOver.putExtra("score",score);
    getContext().startActivity(gameOver);
    }
    //ca vang
    yellowFishX -=yellowFishSpeed;
    canvas.drawBitmap(yellowFish[yellowFishFrame],yellowFishX,yellowFishY,null);
    yellowFishFrame++;
    if (yellowFishFrame>1){
    yellowFishFrame=0;
    }
    if (yellowFishX < -yellowFish[0].getWidth()){
    resetPositionYellowFish();
    }
    if (hitChecker(yellowFishX,yellowFishY)){
    audio.play(id_Audio,1.0f,1.0f,1,0,1.0f);
    score = score +15;
    resetPositionYellowFish();
    }
    //Rua
    turtleX -= turtleSpeed;
    canvas.drawBitmap(turtle[turtleFrame],turtleX,turtleY,null);
    turtleFrame++;
    if (turtleFrame>1){
    turtleFrame=0;
    }
    if (turtleX < -turtle[0].getWidth()){
    resetPositionTurtle();
    }
    if (hitChecker(turtleX,turtleY)){
    audio.play(id_Audio,1.0f,1.0f,1,0,1.0f);
    score = score +10;
    resetPositionTurtle();
    }
    // ca do
    redFishX -= redFishSpeed;
    canvas.drawBitmap(redFish[redFishFrame],redFishX,redFishY,null);
    redFishFrame++;
    if (redFishFrame>2){
    redFishFrame=0;
    }
    if (redFishX < -redFish[0].getWidth()){
    resetPositionRedFish();
    }
    if (hitChecker(redFishX,redFishY)){
    audio.play(id_Audio,1.0f,1.0f,1,0,1.0f);
    score = score +5;
    resetPositionRedFish();
    }
    //may
    clound1X -= cloundSpeed;
    canvas.drawBitmap(clound1,clound1X,clound1Y,null);
    if(clound1X < -clound1.getWidth()){
    resetPositionClound();
    }
    //may2
    clound2X -= clound2Speed;
    canvas.drawBitmap(clound2,clound2X,clound2Y,null);
    if (clound2X < -clound2.getWidth()){
    resetPositionClound2();
    }
    //bong
    ballY -= ballSpeed;
    canvas.drawBitmap(ball,ballX,ballY,null);
    if (ballY < 200){
    resetPositionBall();
    }
    //diem
    canvas.drawText("Score : "+ score,20,60,scorePaint);

    }
    public void resetPositionShank(){
    shankX = 3000;
    shankY = random.nextInt((dHeight-100)-200)+200;
    shankSpeed = random.nextInt(6)+9;
    shankFrame = 0;
    }
    public void resetPositionYellowFish(){
    yellowFishX = 2000;
    yellowFishY = random.nextInt((dHeight-100)-200)+200;
    yellowFishSpeed = random.nextInt(8)+9;
    yellowFishFrame = 0;
    }
    public void resetPositionTurtle(){
    turtleX = 1000;
    turtleY = random.nextInt((dHeight-100)-200)+200;
    turtleSpeed = random.nextInt(6)+6;
    turtleFrame = 0;
    }
    public void resetPositionRedFish(){
    redFishX = 2000;
    redFishY = random.nextInt((dHeight-100)-200)+200;
    redFishSpeed = random.nextInt(6)+6;
    redFishFrame = 0;
    }
    public void resetPositionClound(){
    clound1X = 800;
    clound1Y = random.nextInt(100)+10;
    cloundSpeed = random.nextInt(3)+1;
    }
    public void resetPositionClound2(){
    clound2X = 800;
    clound2Y = random.nextInt(100)+10;
    clound2Speed = random.nextInt(3)+1;
    }
    public void resetPositionBall(){
    ballX = random.nextInt(dWidth)+10;
    ballY = 1000;
    ballSpeed = random.nextInt(5)+5;
    }
    public boolean hitChecker(int x, int y){
    return fishX < x && x < (fishX + fish[0].getWidth()) && fishY < y && y < (fishY + fish[0].getHeight());
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
    if(event.getAction()== MotionEvent.ACTION_DOWN){
    fishSpeed = -22;
    }
    return true;
    }
    }
    Mình chạy code trên khi chạy thì android studio báo :
    Note: GameView.java uses or overrides a deprecated API.
    Note: Recompiled with -deprecation for details.

    các bạn biết lỗi trên sửa thế nào xin chỉ bảo giúp.
     
  2. Joe

    Joe Thành viên VIP

    Uncle Google said in Vietnamese
    "Deprecated" is in Vietnamese: "không dùng nữa"
    "Recompiled with -deprecation for details" is in Vietnamese: "Được biên dịch lại với -deprecation để biết chi tiết"
     
    monody likes this.
  3. monody

    monody New Member

    i don't see where error is.
    how did "recompiled with - deprecation for details" ? thanks
     
  4. Joe

    Joe Thành viên VIP

    It wasn't / isn't an error. Recompile the source with the switch -deprecation then read the lines where the deprecation is noted and then check the API of the version you are using and see what replacement must be used. Example:
    Java 9 deprecates the Integer Object as following:
    PHP:
    Integer I = new Integer(1);      // deprecated
    Integer X Integer.valueOf(1); // the replacement
    Is it now clear?
     
    monody likes this.
  5. monody

    monody New Member

    thanks you very much !
     

Chia sẻ trang này

Loading...