WEB开发网
开发学院手机开发Android 开发 android平台俄罗斯方块游戏完整代码 阅读

android平台俄罗斯方块游戏完整代码

 2012-12-02 14:31:58 来源:WEB开发网   
核心提示: protected void dialog() // 对话框函数 { AlertDialog.Builder builder = new Builder(GameActivity.this); builder.setMessage("确定要退出吗?"); builder.setTi
   protected void dialog()  // 对话框函数
   { 
      AlertDialog.Builder builder = new Builder(GameActivity.this); 
      builder.setMessage("确定要退出吗?"); 
      builder.setTitle("提示"); 
      builder.setPositiveButton("确认", 
      new android.content.DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
         MusicPlay.releaseMusic();
          dialog.dismiss(); 
          android.os.Process.killProcess(android.os.Process.myPid()); 
        }   
      }); 
      builder.setNegativeButton("取消", 
      new android.content.DialogInterface.OnClickListener() {  
        public void onClick(DialogInterface dialog, int which) { 
          dialog.dismiss(); 
          Thread_Log = true;
        } 
      }); 
      builder.create().show(); 
    } 
   
   protected void dialog_a() 
   { 
      AlertDialog.Builder builder = new Builder(GameActivity.this); 
      builder.setMessage("游戏结束!!!"); 
      builder.setTitle("提示"); 
      builder.setPositiveButton("确认", 
      new android.content.DialogInterface.OnClickListener() 
      { 
        public void onClick(DialogInterface dialog, int which) 
        { 
         m_GameView = null;
         Intent intent = new Intent(GameActivity.this,WelcomeActivity.class);
         MusicPlay.releaseMusic();
       startActivity(intent);
         //  GameActivity.this.finish();
        }   
      }); 
     
      builder.create().show(); 
    } 
   
   public void onDestroy() // 销毁函数
    {
      super.onDestroy();
      MusicPlay.releaseMusic();
    }
    
    
 public boolean onDown(MotionEvent event) //按下触摸事件
 {
   int x = (int)event.getX();  //获取按下的坐标位置
    int y = (int)event.getY();
 
    if(m_GameView.m_ButtonLeft.IsClick(x, y))  // 按下坐标是否在图标区域
    {
     vibrator.vibrate(pattern,-1);  // 真机下按键震动响应
    
     if(m_GameView.moveLeftOn()&& Thread_Log)
     {
       m_GameView.Left();
        m_GameView.fastDown(1);  // 计算此时与下方方块的最短距离,以便绘制透明方块
     }
    
     MusicPlay.playSound(R.raw.action,0);
    }
    
    if(m_GameView.m_ButtonRight.IsClick(x, y))
    {
      vibrator.vibrate(pattern,-1); 
      
      if(m_GameView.moveRightOn()&& Thread_Log)
      {
         m_GameView.Right();
     m_GameView.fastDown(1); 
      }
      
      MusicPlay.playSound(R.raw.action,0);
    }
    
    if(m_GameView.m_ButtonDown.IsClick(x, y))
    {
     m_GameView.buttonDown = true;
     vibrator.vibrate(pattern,-1); 
    
     if(m_GameView.moveDownOn()&& Thread_Log)
     {
      m_GameView.Down();
      m_GameView.fastDown(1);
     }
    }
    
    if(m_GameView.m_ButtonRotate.IsClick(x, y))
    {
     m_GameView.buttonRotate = true;
     vibrator.vibrate(pattern,-1); 
    
     if(m_GameView.rotateOnCourt()&& Thread_Log)
     {
        m_GameView.rate();
        m_GameView.fastDown(1);
     }
    
     MusicPlay.playSound(R.raw.action,0);
    }
    
    if(m_GameView.m_ButtonFastDown.IsClick(x, y))
    {
     m_GameView.buttonFastDown = true;
     vibrator.vibrate(pattern,-1);
    
     if(m_GameView.moveDownOn()&& Thread_Log)
     {
        m_GameView.FastDown();     
     }
    
     MusicPlay.playSound(R.raw.fastdown,0);
    }
    
 return true;
 }
 
 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY)
   {
     final int FLING_MIN_DISTANCE = 100, FLING_MIN_VELOCITY = 200; 
    
     if(e2.getY()-e1.getY()>FLING_MIN_DISTANCE && Math.abs(velocityY)>FLING_MIN_VELOCITY && m_GameView.moveDownOn()&& Thread_Log)
     {    
        log_num = 1;
        m_GameView.FastDown();
        MusicPlay.playSound(R.raw.fastdown,0);
     } 
     
     if(e2.getY()-e1.getY()<0&&Math.abs(velocityY)>FLING_MIN_VELOCITY)
     {
      if(log_log == 0)
      {
      Thread_Log = false;
      log_log = 1;
      }
      else
      {
      Thread_Log = true;
      log_log = 0;
      }
     
     }
    return false;
   }
 
 public void onLongPress(MotionEvent event) 
 {
 }
 
  public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,float distanceY) {
 
  Log.i("onScroll","Downstill");
 
 if(e1.getAction() == MotionEvent.ACTION_DOWN)
   log = e1.getX();
    float e1x = e1.getX() ;
  float e2x = e2.getX() ;
  float x1 = e2x - e1x ;
  float e1y = e1.getY() ;
  float e2y = e2.getY() ;
  float y1 = e2y - e1y ;
  float absX = Math.abs(x1), absY = Math.abs(y1) ;
    float ex2 = e2.getX();
    float x = ex2-log;
  if(absX > absY)
  {
    if(x>60f&&x<70f || x>-70f&&x<-60f)
    {
    log = ex2; 
 
          if( x>-70f&&x<-60f&& m_GameView.moveLeftOn())
       { 
       m_GameView.Left();
       m_GameView.fastDown(1);
       MusicPlay.playSound(R.raw.action,0);
       }
       if(x>60f&&x<70f && m_GameView.moveRightOn())
       {
       m_GameView.Right();
       m_GameView.fastDown(1);
       MusicPlay.playSound(R.raw.action,0);
       }
    }
  }
  
 return true;
 }
 
 public void onShowPress(MotionEvent event) {

上一页  7 8 9 10 11 12 13  下一页

Tags:android 平台 俄罗斯

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接