91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何在android中利view實現一個推箱子小游戲

發布時間:2020-12-02 17:36:13 來源:億速云 閱讀:135 作者:Leah 欄目:移動開發

如何在android中利view實現一個推箱子小游戲?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

自定義view:

package com.jisai.materialdesigndemo.tuixiangzhi; 
 
import android.content.Context; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.graphics.Canvas; 
import android.graphics.Color; 
import android.graphics.Paint; 
import android.graphics.Rect; 
import android.util.AttributeSet; 
import android.util.Log; 
import android.widget.ImageView; 
 
import com.jisai.materialdesigndemo.R; 
 
import java.util.ArrayList; 
 
public class View_tuixiangzhi extends ImageView { 
  ArrayList<int[][]> arrayList = new ArrayList<>(); 
  int[][][] ccc =new int[300][15][15]; 
  int kk=0; 
  Canvas canvas; 
  private int mWidth; 
  private int mHeight; 
  Boolean flag=false; 
  Bitmap bitmap0= BitmapFactory.decodeResource(getResources(), R.mipmap.qiang); 
  Bitmap bitmap1= BitmapFactory.decodeResource(getResources(),R.mipmap.kong); 
  Bitmap bitmap2= BitmapFactory.decodeResource(getResources(),R.mipmap.ren_1); 
  Bitmap bitmap3= BitmapFactory.decodeResource(getResources(),R.mipmap.xiang_1); 
  Bitmap bitmap4= BitmapFactory.decodeResource(getResources(),R.mipmap.xiang_2); 
  Bitmap bitmap5= BitmapFactory.decodeResource(getResources(),R.mipmap.hua); 
  Bitmap bitmap6= BitmapFactory.decodeResource(getResources(),R.mipmap.renandhua); 
  int [][]aaa= {//0是墻,1是空,2是人,3是空箱子,4是滿箱子,5是花,6是人加花 
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,5,0,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,3,1,3,5,0,0,0,0,0}, 
      {0,0,0,0,5,3,2,1,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,0,3,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,0,5,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 
  }; 
 
  public interface PassLitener 
  { 
    void pass(); 
  } 
  private PassLitener mPassLitener; 
  public void setPassLitener(PassLitener mPassLitener) 
  { 
    this.mPassLitener = mPassLitener; 
  } 
 
  public View_tuixiangzhi(Context context) { 
    super(context); 
    init("MyImageView(Context context)"); 
  } 
 
  public View_tuixiangzhi(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    init("MyImageView(Context context, AttributeSet attrs)"); 
  } 
 
  public View_tuixiangzhi(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    init("MyImageView(Context context, AttributeSet attrs, int defStyle)"); 
 
  } 
 
  private void init(String structName) { 
  } 
 
  @Override 
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    int specSize = MeasureSpec.getSize(widthMeasureSpec); 
 
    mWidth = specSize; 
    specSize = MeasureSpec.getSize(heightMeasureSpec); 
 
    mHeight = specSize; 
 
    Log.e("寬高:","寬:"+mWidth+"高:"+mHeight); 
 
    setMeasuredDimension(mWidth, mHeight); 
 
  } 
 
  @Override 
  protected void onDraw(Canvas canvas) { 
    Log.e("onDraw:","onDraw"); 
    this.canvas=canvas; 
    super.onDraw(canvas); 
    Paint p=new Paint(); 
    p.setColor(Color.RED); 
    //canvas.drawRect(20,20,100,100,p); 
    //canvas.drawColor(Color.RED); 
    for(int i=0;i<15;i++){ 
      for(int k=0;k<15;k++){ 
        int x=aaa[i][k]; 
 
        Rect rect = new Rect((mWidth/15)*k,(mWidth/15)*i,(mWidth/15)*(k+1),(mWidth/15)*(i+1)); 
        switch (x){ 
          case 0: 
            canvas.drawBitmap(bitmap0,null,rect,p); 
            break; 
          case 1: 
            canvas.drawBitmap(bitmap1,null,rect,p); 
            break; 
          case 2: 
            canvas.drawBitmap(bitmap2,null,rect,p); 
            break; 
          case 3: 
            canvas.drawBitmap(bitmap3,null,rect,p); 
            break; 
          case 4: 
            canvas.drawBitmap(bitmap4,null,rect,p); 
            break; 
          case 5: 
            canvas.drawBitmap(bitmap5,null,rect,p); 
            break; 
          case 6: 
            canvas.drawBitmap(bitmap6,null,rect,p); 
            break; 
 
        } 
      } 
    } 
 
 
 
  } 
 
  public void setaaa(int [][]xxx){ 
    for(int i=0;i<15;i++){ 
      for(int k=0;k<15;k++) { 
        aaa[i][k]=xxx[i][k]; 
      } 
    } 
    kk=0; 
    arrayList.clear(); 
    postInvalidate(); 
  } 
  public void moveLeft(){ 
    addBack(); 
    flag=false; 
    for(int i=0;i<15;i++){ 
      if (flag){ 
        break; 
      } 
      for(int k=0;k<15;k++) { 
        if (flag){ 
          break; 
        } 
        int x = aaa[i][k]; 
        if(x==2|x==6){ 
          Log.e("x",""+x+"i:"+i+"k:"+k); 
 
          switch ( aaa[i][k-1]){ 
            case 0://左邊是墻,不能移動 
              break; 
            case 1://左邊是空,可以移動 
              if(x==6){ 
                aaa[i][k]=5; 
              }else{ 
                aaa[i][k]=1; 
              } 
              aaa[i][k-1]=2; 
 
              break; 
            case 3://左邊是空箱子 
              if(aaa[i][k-2]==5){//箱子左邊是花 
                aaa[i][k-2]=4; 
                aaa[i][k-1]=2; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
 
              }else if(aaa[i][k-2]==1){//箱子左邊是空 
                aaa[i][k-2]=3; 
                aaa[i][k-1]=2; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
 
              }else{}//是其他則不能移動 
 
              break; 
            case 4://左邊是滿箱子 
              if(aaa[i][k-2]==5){//箱子左邊是花 
                aaa[i][k-2]=4; 
                aaa[i][k-1]=6; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
 
              }else if(aaa[i][k-2]==1){//箱子左邊是空 
                aaa[i][k-2]=3; 
                aaa[i][k-1]=6; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
 
              }else{}//是其他則不能移動 
              break; 
            case 5://左邊是花 
              if(x==6){ 
                aaa[i][k]=5; 
              }else{ 
                aaa[i][k]=1; 
              } 
              aaa[i][k-1]=6; 
 
              break; 
          } 
          flag=true; 
        } 
      } 
    } 
 
 
    postInvalidate(); 
    ifPass(); 
  } 
  public void moveRight(){ 
    addBack(); 
    flag=false; 
    for(int i=0;i<15;i++){ 
      if (flag){ 
        break; 
      } 
      for(int k=0;k<15;k++) { 
        int x = aaa[i][k]; 
        if (flag){ 
          break; 
        } 
        if(x==2|x==6){ 
          Log.e("x",""+x+"i:"+i+"k:"+k); 
          switch ( aaa[i][k+1]){ 
            case 0://右邊是墻,不能移動 
              break; 
            case 1://右邊是空,可以移動 
              if(x==6){ 
                aaa[i][k]=5; 
              }else{ 
                aaa[i][k]=1; 
              } 
              aaa[i][k+1]=2; 
              break; 
            case 3://右邊是空箱子 
              if(aaa[i][k+2]==5){//箱子右邊是花 
                aaa[i][k+2]=4; 
                aaa[i][k+1]=2; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
              }else if(aaa[i][k+2]==1){//箱子右邊是空 
                aaa[i][k+2]=3; 
                aaa[i][k+1]=2; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
              }else{}//是其他則不能移動 
              break; 
            case 4://右邊是滿箱子 
              if(aaa[i][k+2]==5){//箱子右邊是花 
                aaa[i][k+2]=4; 
                aaa[i][k+1]=6; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
              }else if(aaa[i][k+2]==1){//箱子右邊是空 
                aaa[i][k+2]=3; 
                aaa[i][k+1]=6; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
              }else{}//是其他則不能移動 
              break; 
            case 5://右邊是花 
              if(x==6){ 
                aaa[i][k]=5; 
              }else{ 
                aaa[i][k]=1; 
              } 
              aaa[i][k+1]=6; 
              break; 
          } 
          flag=true; 
        } 
      } 
    } 
 
    postInvalidate(); 
    ifPass(); 
  } 
  public void moveUp(){ 
    addBack(); 
    flag=false; 
    for(int i=0;i<15;i++){ 
      if (flag){ 
        break; 
      } 
      for(int k=0;k<15;k++) { 
        int x = aaa[i][k]; 
        if (flag){ 
          break; 
        } 
        if(x==2|x==6){ 
          Log.e("x",""+x+"i:"+i+"k:"+k); 
          switch ( aaa[i-1][k]){ 
            case 0://上邊是墻,不能移動 
              break; 
            case 1://上邊是空,可以移動 
              if(x==6){ 
                aaa[i][k]=5; 
              }else{ 
                aaa[i][k]=1; 
              } 
              aaa[i-1][k]=2; 
              break; 
            case 3://上邊是空箱子 
              if(aaa[i-2][k]==5){//箱子上邊是花 
                aaa[i-2][k]=4; 
                aaa[i-1][k]=2; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
              }else if(aaa[i-2][k]==1){//箱子上邊是空 
                aaa[i-2][k]=3; 
                aaa[i-1][k]=2; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
              }else{}//是其他則不能移動 
              break; 
            case 4://上邊是滿箱子 
              if(aaa[i-2][k]==5){//箱子上邊是花 
                aaa[i-2][k]=4; 
                aaa[i-1][k]=6; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
              }else if(aaa[i-2][k]==1){//箱子上邊是空 
                aaa[i-2][k]=3; 
                aaa[i-1][k]=6; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
              }else{}//是其他則不能移動 
              break; 
            case 5://上邊是花 
              if(x==6){ 
                aaa[i][k]=5; 
              }else{ 
                aaa[i][k]=1; 
              } 
              aaa[i-1][k]=6; 
              break; 
          } 
          flag=true; 
        } 
      } 
    } 
 
    postInvalidate(); 
    ifPass(); 
  } 
  public void moveDown(){ 
    addBack(); 
    flag=false; 
    for(int i=0;i<15;i++){ 
      if (flag){ 
        break; 
      } 
      for(int k=0;k<15;k++) { 
        int x = aaa[i][k]; 
        if (flag){ 
          break; 
        } 
        if(x==2|x==6){ 
          Log.e("x",""+x+"i:"+i+"k:"+k); 
          switch ( aaa[i+1][k]){ 
            case 0://下邊是墻,不能移動 
              break; 
            case 1://下邊是空,可以移動 
              if(x==6){ 
                aaa[i][k]=5; 
              }else{ 
                aaa[i][k]=1; 
              } 
              aaa[i+1][k]=2; 
              break; 
            case 3://下邊是空箱子 
              if(aaa[i+2][k]==5){//箱子下邊是花 
                aaa[i+2][k]=4; 
                aaa[i+1][k]=2; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
              }else if(aaa[i+2][k]==1){//箱子下邊是空 
                aaa[i+2][k]=3; 
                aaa[i+1][k]=2; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
              }else{}//是其他則不能移動 
              break; 
            case 4://下邊是滿箱子 
              if(aaa[i+2][k]==5){//箱子下邊是花 
                aaa[i+2][k]=4; 
                aaa[i+1][k]=6; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
              }else if(aaa[i+2][k]==1){//箱子下邊是空 
                aaa[i+2][k]=3; 
                aaa[i+1][k]=6; 
                if(x==6){ 
                  aaa[i][k]=5; 
                }else{ 
                  aaa[i][k]=1; 
                } 
              }else{}//是其他則不能移動 
              break; 
            case 5://下邊是花 
              if(x==6){ 
                aaa[i][k]=5; 
              }else{ 
                aaa[i][k]=1; 
              } 
              aaa[i+1][k]=6; 
              break; 
          } 
          flag=true; 
        } 
      } 
    } 
    postInvalidate(); 
    ifPass(); 
  } 
 
  public void ifPass(){ 
    flag=false; 
    for(int i=0;i<15;i++){ 
      if (flag){ 
        break; 
      } 
      for(int k=0;k<15;k++) { 
        int x = aaa[i][k]; 
        if (flag){ 
          break; 
        } 
        if(x==3){//還有空箱子 
          flag=true; 
        } 
      } 
    } 
 
    if (!flag){//沒有一個空箱子 
      mPassLitener.pass(); 
    } 
  } 
 
  public void moveBack(){ 
    if(arrayList.size()>0){ 
      this.aaa=(arrayList.get(arrayList.size()-1)); 
      postInvalidate(); 
      arrayList.remove(arrayList.size()-1); 
    } 
  } 
  public void addBack(){ 
    if(kk>299){ 
      arrayList.clear(); 
      kk=0; 
    } 
    if(arrayList.size()>99){ 
      arrayList.remove(0); 
    } 
    for(int i=0;i<15;i++){ 
      for(int k=0;k<15;k++){ 
        ccc[kk][i][k]=aaa[i][k]; 
      } 
    } 
    arrayList.add(ccc[kk]); 
    kk++; 
  } 
 
} 

activity  :

package com.jisai.materialdesigndemo.tuixiangzhi; 
 
import android.content.DialogInterface; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.support.design.widget.Snackbar; 
import android.support.v7.app.AlertDialog; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.Button; 
 
import com.jisai.materialdesigndemo.R; 
 
import java.util.ArrayList; 
 
public class MainActivity_tuixiangzhi extends AppCompatActivity 
    { 
  ArrayList<int[][]> arrayList=new ArrayList<>(); 
      Button up,down,left,right,back,nextup,nextdown; 
      View_tuixiangzhi myImageView_circle; 
      Toolbar mToolbar; 
      int   LV=1; 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_tuixiangzhi); 
    LV_data lv_data=new LV_data(); 
    arrayList=lv_data.arrayList; 
    mToolbar = (Toolbar) findViewById(R.id.toolbar); 
    // mToolbar.setBackgroundColor(0xFF42B1CD); 
    mToolbar.setTitle("推箱子(第"+LV+"關)");    //設置標題 
    mToolbar.setTitleTextColor(Color.parseColor("#ffffff"));  //設置標題顏色 
    setSupportActionBar(mToolbar); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
        // onBackPressed(); 
        finish(); 
        //Toast.makeText(getApplicationContext(),"返回",Toast.LENGTH_SHORT).show(); 
 
      } 
    }); 
 
 
 
 
 
 
    myImageView_circle= (View_tuixiangzhi) findViewById(R.id.nnn); 
 
    myImageView_circle.setPassLitener(new View_tuixiangzhi.PassLitener() { 
      @Override 
      public void pass() { 
 
        final AlertDialog.Builder normalDialog = 
            new AlertDialog.Builder(MainActivity_tuixiangzhi.this); 
        normalDialog.setTitle("恭喜你"); 
        normalDialog.setMessage("真厲害,你已通過本關!"); 
        normalDialog.setPositiveButton("下一關", 
            new DialogInterface.OnClickListener() { 
              @Override 
              public void onClick(DialogInterface dialog, int which) { 
                if(LV<arrayList.size()){ 
                  LV=LV+1; 
                  myImageView_circle.setaaa(arrayList.get(LV-1)); 
                  mToolbar.setTitle("推箱子(第"+LV+"關)");    //設置標題 
                }else{ 
                  final Snackbar snackbar = Snackbar.make(up, "已是最后一關", Snackbar 
                      .LENGTH_LONG); 
                  snackbar.show(); 
                  snackbar.setAction("確定", new View.OnClickListener() { 
                    @Override 
                    public void onClick(View view) { 
                      snackbar.dismiss(); 
                    } 
                  }); 
                } 
 
              } 
            }); 
        // 顯示 
        normalDialog.show(); 
      } 
    }); 
 
    up= (Button) findViewById(R.id.shang); 
    down= (Button) findViewById(R.id.xia); 
    left= (Button) findViewById(R.id.zuo); 
    right= (Button) findViewById(R.id.you); 
    back= (Button) findViewById(R.id.back); 
    nextup= (Button) findViewById(R.id.shangyi); 
    nextdown= (Button) findViewById(R.id.xiayi); 
 
    up.setOnClickListener(cccc); 
    down.setOnClickListener(cccc); 
    left.setOnClickListener(cccc); 
    right.setOnClickListener(cccc); 
    back.setOnClickListener(cccc); 
    nextup.setOnClickListener(cccc); 
    nextdown.setOnClickListener(cccc); 
 
 
  } 
      View.OnClickListener cccc = new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 
          switch (v.getId()){ 
            case R.id.shang: 
              myImageView_circle.moveUp(); 
              break; 
            case R.id.xia: 
              myImageView_circle.moveDown(); 
              break; 
            case R.id.zuo: 
              myImageView_circle.moveLeft(); 
              break; 
            case R.id.you: 
              myImageView_circle.moveRight(); 
              break; 
            case R.id.back: 
              myImageView_circle.moveBack(); 
              break; 
            case R.id.shangyi: 
              if(LV>1){ 
                LV=LV-1; 
                myImageView_circle.setaaa(arrayList.get(LV-1)); 
                mToolbar.setTitle("推箱子(第"+LV+"關)");    //設置標題 
              } 
              break; 
            case R.id.xiayi: 
              if(LV<arrayList.size()){ 
                LV=LV+1; 
                myImageView_circle.setaaa(arrayList.get(LV-1)); 
                mToolbar.setTitle("推箱子(第"+LV+"關)");    //設置標題 
              }else{ 
                final Snackbar snackbar = Snackbar.make(up, "已是最后一關", Snackbar 
                    .LENGTH_LONG); 
                snackbar.show(); 
                snackbar.setAction("確定", new View.OnClickListener() { 
                  @Override 
                  public void onClick(View view) { 
                    snackbar.dismiss(); 
                  } 
                }); 
              } 
              break; 
          } 
 
        } 
      }; 
 
      @Override 
      public boolean onCreateOptionsMenu(Menu menu) { 
        // Inflate the menu; this adds items to the action bar if it is present. 
        getMenuInflater().inflate(R.menu.menu_tuixiangzhi, menu); 
        return true; 
      } 
 
      @Override 
      public boolean onOptionsItemSelected(MenuItem item) { 
        // Handle action bar item clicks here. The action bar will 
        // automatically handle clicks on the Home/Up button, so long 
        // as you specify a parent activity in AndroidManifest.xml. 
        int id = item.getItemId(); 
 
        //noinspection SimplifiableIfStatement 
        if (id == R.id.item1) { 
          myImageView_circle.setaaa(arrayList.get(LV-1)); 
 
          return true; 
        } 
 
        return super.onOptionsItemSelected(item); 
      } 
 
 
} 

布局文件:

<&#63;xml version="1.0" encoding="utf-8"&#63;> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  xmlns:tools="http://schemas.android.com/tools" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="vertical" 
  xmlns:app="http://schemas.android.com/apk/res-auto" 
  tools:context="com.jisai.materialdesigndemo.caipu.CaipuItemActivity"> 
 
    <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="&#63;attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      android:elevation="6dp" 
      android:background="&#63;attr/colorPrimary" 
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      app:layout_scrollFlags="scroll|enterAlways" 
      /> 
 
  <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@mipmap/bg3" 
    > 
    <com.jisai.materialdesigndemo.tuixiangzhi.View_tuixiangzhi 
      android:id="@+id/nnn" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
 
 
    <RelativeLayout 
      android:layout_alignParentBottom="true" 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      > 
      <Button 
        android:id="@+id/back" 
        android:layout_width="40dp" 
        android:layout_centerInParent="true" 
        android:layout_height="40dp" 
        android:background="@drawable/back2" 
        android:layout_margin="15dp"/> 
 
      <Button 
        android:id="@+id/shang" 
        android:layout_width="40dp" 
        android:layout_height="40dp" 
        android:background="@drawable/s_s" 
        android:layout_above="@+id/back" 
        android:layout_alignLeft="@+id/back"/> 
      <Button 
        android:id="@+id/xia" 
        android:layout_width="40dp" 
        android:layout_height="40dp" 
        android:background="@drawable/d_s" 
        android:layout_below="@+id/back" 
        android:layout_alignLeft="@+id/back"/> 
      <Button 
        android:id="@+id/zuo" 
        android:layout_width="40dp" 
        android:layout_height="40dp" 
        android:background="@drawable/l_s" 
        android:layout_toLeftOf="@+id/back" 
        android:layout_alignTop="@+id/back"/> 
      <Button 
        android:id="@+id/you" 
        android:layout_width="40dp" 
        android:layout_height="40dp" 
        android:background="@drawable/r_s" 
        android:layout_toRightOf="@+id/back" 
        android:layout_alignTop="@+id/back"/> 
 
      <Button 
        android:id="@+id/shangyi" 
        android:layout_width="40dp" 
        android:layout_height="40dp" 
        android:background="@drawable/l_n" 
        android:layout_marginBottom="40dp" 
        android:layout_marginLeft="15dp" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentLeft="true" 
        /> 
      <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="30dp" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentLeft="true" 
        android:layout_marginLeft="20dp" 
        android:text="上一關"/> 
 
      <Button 
        android:id="@+id/xiayi" 
        android:layout_width="40dp" 
        android:layout_height="40dp" 
        android:background="@drawable/r_n" 
        android:layout_marginBottom="40dp" 
        android:layout_marginRight="15dp" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentRight="true" 
        /> 
      <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="30dp" 
        android:layout_marginRight="20dp" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentRight="true" 
        android:text="下一關"/> 
 
    </RelativeLayout> 
 
 
  </RelativeLayout> 
 
</LinearLayout> 

關卡數據(二位數組),我加了40關,太長這里就貼一點。

package com.jisai.materialdesigndemo.tuixiangzhi; 
 
import java.util.ArrayList; 
 
/** 
 * Created by Administrator on 17-4-11. 
 */ 
public class LV_data { 
 final  ArrayList<int[][]>arrayList = new ArrayList<>(); 
 
  LV_data(){ 
    int[][] LV_1 ={//0是墻,1是空,2是人,3是空箱子,4是滿箱子,5是花,6是人加花 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,5,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,3,1,3,5,0,0,0,0,0}, 
        {0,0,0,0,5,3,2,1,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,3,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,5,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 
    }; 
    arrayList.add(LV_1); 
 
 
    int[][] LV_2 ={//0是墻,1是空,2是人,3是空箱子,4是滿箱子,5是花,6是人加花 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,2,1,1,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,1,3,3,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,1,3,1,0,0,0,5,0,0,0,0}, 
        {0,0,0,0,0,0,1,0,0,0,5,0,0,0,0}, 
        {0,0,0,0,0,0,1,1,1,1,5,0,0,0,0}, 
        {0,0,0,0,0,1,1,1,0,1,1,0,0,0,0}, 
        {0,0,0,0,0,1,1,1,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 
    }; 
    arrayList.add(LV_2); 
 
    int[][] LV_3 ={//0是墻,1是空,2是人,3是空箱子,4是滿箱子,5是花,6是人加花 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, 
        {0,0,0,0,0,3,0,0,0,1,1,1,0,0,0}, 
        {0,0,0,0,1,2,1,3,1,1,3,1,0,0,0}, 
        {0,0,0,0,1,5,5,0,1,3,1,0,0,0,0}, 
        {0,0,0,0,0,5,5,0,1,1,1,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 
    }; 
    arrayList.add(LV_3); 
 
    int[][] LV_4 ={//0是墻,1是空,2是人,3是空箱子,4是滿箱子,5是花,6是人加花 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,1,1,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,2,3,1,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,3,1,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,1,3,1,0,0,0,0,0,0}, 
        {0,0,0,0,0,5,3,1,1,0,0,0,0,0,0}, 
        {0,0,0,0,0,5,5,4,5,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 
    }; 
    arrayList.add(LV_4); 
 
    int[][] LV_5 ={//0是墻,1是空,2是人,3是空箱子,4是滿箱子,5是花,6是人加花 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,2,1,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,1,3,1,1,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,1,0,1,0,0,0,0,0,0}, 
        {0,0,0,0,5,0,1,0,1,1,0,0,0,0,0}, 
        {0,0,0,0,5,3,1,1,0,1,0,0,0,0,0}, 
        {0,0,0,0,5,1,1,1,3,1,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 
    }; 
    arrayList.add(LV_5); 
 
    int[][] LV_6 ={//0是墻,1是空,2是人,3是空箱子,4是滿箱子,5是花,6是人加花 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, 
        {0,0,1,1,1,5,0,0,0,1,0,0,0,0,0}, 
        {0,0,1,0,1,0,1,1,1,1,0,0,0,0,0}, 
        {0,0,1,0,1,3,1,3,0,5,1,0,0,0,0}, 
        {0,0,1,0,1,1,4,1,1,0,1,0,0,0,0}, 
        {0,0,1,5,0,3,1,3,1,0,1,0,0,0,0}, 
        {0,0,0,1,1,1,1,0,1,0,1,0,0,0,0}, 
        {0,0,0,1,0,0,0,5,1,1,1,1,2,0,0}, 
        {0,0,0,1,1,1,1,1,0,0,1,1,1,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 
    }; 
    arrayList.add(LV_6); 
 
    int[][] LV_7 ={//0是墻,1是空,2是人,3是空箱子,4是滿箱子,5是花,6是人加花 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,1,1,1,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,1,3,1,5,5,1,3,1,0,0,0,0}, 
        {0,0,0,0,3,1,5,5,3,3,2,0,0,0,0}, 
        {0,0,0,0,1,1,5,5,1,3,1,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 
    }; 
    arrayList.add(LV_7); 
 
    int[][] LV_8 ={//0是墻,1是空,2是人,3是空箱子,4是滿箱子,5是花,6是人加花 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,1,1,1,1,0,0,0,0}, 
        {0,0,0,0,0,5,1,3,0,0,1,0,0,0,0}, 
        {0,0,0,0,5,5,3,1,3,1,1,2,0,0,0}, 
        {0,0,0,0,5,5,1,3,1,3,1,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,1,1,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 
    }; 
    arrayList.add(LV_8); 

關于如何在android中利view實現一個推箱子小游戲問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

龙井市| 华亭县| 涞源县| 古交市| 六盘水市| 突泉县| 阜康市| 鲜城| 定襄县| 雅江县| 萨嘎县| 东乡| 南和县| 苏尼特左旗| 巴东县| 广昌县| 丹凤县| 乐安县| 蒙自县| 财经| 东台市| 兴国县| 德保县| 大渡口区| 聂拉木县| 和政县| 岐山县| 定结县| 赫章县| 邛崃市| 上杭县| 玉山县| 普兰店市| 佳木斯市| 闻喜县| 太保市| 申扎县| 仪征市| 和政县| 闽侯县| 镇坪县|