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

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 onD

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< p>

for(int j=0;j< p>

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){

上一页  1 2 3 4  下一页

Tags:Android 黑白 游戏

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