Android黑白子游戏
2010-09-21 02:14:00 来源:WEB开发网Log.d(TAG,"select:"+x+"-"+y);
invalidate(selRect);
//不让它跑外面去.所以是-1.
/*selX = Math.min(Math.max(x, 0), Game.level - 1);
selY = Math.min(Math.max(y, 0), Game.level - 1);
getRect(selX, selY, selRect);*/
setRect(x,y);
//Log.d(TAG,"select:selX:"+selX+"-selY:"+selY);
//Log.d(TAG,"ing ... select rects:"+rect.left+":"+rect.top+":"+rect.right+":"+rect.bottom);
invalidate(selRect);
}
/**
* 设置位图
* x:横坐标0-13
* y:纵坐标0-13
*/
private void setRectImg(int x,int y){
//Log.d(TAG, "setRectImg x:"+x+"--y:"+y);
//invalidate(selRect);
invalidate();
if(game.isVal(x,y,c,rect)){
c=(c==Game.GAME_BLACK)?Game.GAME_WHITE:Game.GAME_BLACK;
setRect(x,y);
score=game.getScore();
canMove=(c==1?"轮到黑":"轮到黄:")+"黑--"+score[0]+"--黄--"+score[1];
}else{
canMove=(c==1?"轮到黑":"轮到黄:")+"不能放子";
}
//Log.d(TAG,"setRectImg:c--"+(c==1?"轮到黑":"轮到黄")+"--canMove:"+canMove);
//invalidate(selRect);之前是使用了这个,然后一直没有更新棋盘上棋 子,也不知道为什么,后来终于知道答案了
}
private int[] score;
@Override
public boolean onKeyDown(int keyCode,KeyEvent event){
//Log.d(TAG, "onKeyDown: keycode=" + keyCode + ", event=" + event);
switch(keyCode){
case KeyEvent.KEYCODE_DPAD_UP:
select(selX,selY-1);
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
select(selX,selY+1);
break;
case KeyEvent.KEYCODE_DPAD_LEFT:
select(selX-1,selY);
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
select(selX+1,selY);
break;
case KeyEvent.KEYCODE_ENTER:
case KeyEvent.KEYCODE_DPAD_CENTER:
setRectImg(selX,selY);
break;
default:
return super.onKeyDown(keyCode,event);
}
return true;
}
更多精彩
赞助商链接