Android 黑白子游戏开发实例
2010-03-31 05:20:00 来源:WEB开发网canvas.drawLine(i*gridW,0,i*gridW,(screenHeight-40),hilite);
canvas.drawLine(i*gridW+1,0,i*gridW+1,(screenHeight-40),hilite);
}
// 填充图像
//Log.d(TAG,"before onDraw rects:"+rect.left+":"+rect.top+":"+rect.right+":"+rect.bottom);
for(int i=0;i
for(int j=0;j
if(game.getTiles()[i][j]==1){
getRect(i,j,rect);
canvas.drawBitmap(dstbmp1,null,rect,null);
}else if(game.getTiles()[i][j]==2){
getRect(i,j,rect);
canvas.drawBitmap(dstbmp2,null,rect,null);
}
}
}
//canvas.drawBitmap(dstbmp1,null,selRect,null);
canvas.drawRect(selRect,selected);
//Log.d(TAG,"draw selected rects:"+rect.left+":"+rect.top+":"+rect.right+":"+rect.bottom);
canvas.drawText(canMove,10,screenHeight-8,moveFont);
Log.d(TAG,"onDraw: canMove:"+canMove);
}
//获得位置
public void getRect(int x,int y,Rect rect){
rect.set((int)(x*gridW)+2,(int)(y*gridH)+2,(int)(x*gridW+gridW),(int)(y*gridH+gridH));
}
private void setRect(int x,int y){
selX=Math.min(Math.max(x,0),Game.level-1);
selY=Math.min(Math.max(y,0),Game.level-1);
getRect(selX,selY,selRect);
}
@Override
public boolean onTouchEvent(MotionEvent event){
if(event.getAction()!=MotionEvent.ACTION_DOWN){
return super.onTouchEvent(event);
}
Log.d(TAG,"onTouchEvent select:"+event.getX()+":"+event.getY());
//select((int) (event.getX() / gridW), (int) (event.getY() / gridH));
setRectImg((int)(event.getX()/gridW),(int)(event.getY()/gridH));
return true;
}
private void select(int x,int y){
更多精彩
赞助商链接