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);
}
09-07
07-13
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交