WEB开发网
开发学院手机开发Android 开发 Android 黑白子游戏开发实例 阅读

Android 黑白子游戏开发实例

 2010-03-31 05:20: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(

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;

}

上一页  1 2 3 4 

Tags:Android 黑白 游戏

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