d

public boolean onTouchEvent(MotionEvent event) {
     switch(event.getAction())
     {
      //触摸屏幕时刻
              case MotionEvent.ACTION_DOWN:
               {
                 if(myTurn)
                  {
                        int x=0,y=0;
                        while(mScreen.pre+x*mScreen.width_unit<=event.getX()) x++;
                        while(mScreen.pre+y*mScreen.height_unit+mScreen.y<=event.getY()) y++;
                        x--;
                        y-=3;
                        if(x>=0&x<9&&y>=0&&y<10)
                        {
                            //如果有棋子

                            if(mScreen.Layout[x][y]!=0)
                            {
                                if(start_x!=-1) {
                                    mScreen.Layout[end_x][end_y] -= 20;
                                    mScreen.Layout[start_x][start_y] = 0;
                                    start_x = -1;
                                }
                                if(mScreen.Layout[x][y]>7&&mScreen.Layout[x][y]<15)
                                {
                                    if(selected)
                                    mScreen.Layout[start_Pos.x][start_Pos.y]-=20;
                                    runStoneID=mScreen.Layout[x][y];
                                    mScreen.Layout[x][y]+=20;
                                    start_Pos.set(x,y);
                                    selected=true;
                                    soundPool.play(sound_slect_ID,1, 1, 1, 0, 1);
                                    mScreen.postInvalidate();

                                }
                                else//判断能否吃子
                                {
                                         Point endP= new Point(x,y);
                                        if(cango(runStoneID,start_Pos,endP))
                                        {
                                            soundPool.play(sound_eat_ID,1, 1, 1, 0, 1);
                                            mScreen.Layout[x][y]=runStoneID+20;
                                            mScreen.Layout[start_Pos.x][start_Pos.y]=-1;
                                            selected=false;
                                            String msg;
                                            msg = runStoneID+"w"+start_Pos.x+"w"+start_Pos.y+"w"+x+"w"+y;
                                            if(isOwner) {serverSendMsg(msg);Log.e("服务端发送",msg);}
                                            else {clientSendMsg(msg);Log.e("客户端发送",msg);}
                                            myTurn=!myTurn;
                                            mScreen.postInvalidate();
                                           if(mScreen.Layout[x][y]==1)
                                           {
                                            soundPool.play(sound_loss_ID,1, 1, 1, 0, 1);
                                            newgame.setTitle("你赢了!!");
                                            newgame.show();

                                            }
                                        }
                                }
                            }
                            else //如果没有  走棋
                            {
                                if(selected)
                                {
                                    end_Pos.set(x,y);
                                    if(cango(runStoneID,start_Pos,end_Pos))
                                    {
                                        soundPool.play(sound_move_ID,1, 1, 1, 0, 1);
                                        mScreen.Layout[end_Pos.x][end_Pos.y]=runStoneID+20;
                                        mScreen.Layout[start_Pos.x][start_Pos.y]=-1;
                                        selected=false;
                                        String msg;
                                        msg = runStoneID+"w"+start_Pos.x+"w"+start_Pos.y+"w"+end_Pos.x+"w"+end_Pos.y;
                                        if(isOwner) {serverSendMsg(msg);Log.e("服务端发送",msg);}
                                        else {clientSendMsg(msg);Log.e("客户端发送",msg);}
                                        mScreen.run_stone=runStoneID;
                                        myTurn=!myTurn;
                                        mScreen.postInvalidate();
                                    }
                                }

                            }
                        }

                    }//end of if(myTurn)
                }
            }
            return super.onTouchEvent(event);
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值