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

Android黑白子游戏

 2010-09-21 02:14:00 来源:WEB开发网   
核心提示:hilite.setColor(getResources().getColor(R.color.puzzle_hint_0));selected.setColor(getResources().getColor(R.color.puzzle_selected));moveFont=new Paint();String

hilite.setColor(getResources().getColor(R.color.puzzle_hint_0));

selected.setColor(getResources().getColor(R.color.puzzle_selected));

moveFont=new Paint();

String familyName="Arial";

Typeface font=Typeface.create(familyName,Typeface.BOLD);

moveFont.setColor(Color.RED);

moveFont.setTypeface(font);

moveFont.setTextSize(22);

}

@Override

protected void onSizeChanged(int w,int h,int oldw,int oldh){

initImg(w,h);

Log.d(TAG,"onSizeChanged: width "+gridW+", height "+gridH);

super.onSizeChanged(w,h,oldw,oldh);

}

/**

* 初始化屏幕大小,图片

*

* @param w

* @param h

*/

private void initImg(int w,int h){

screenWidth=(float)w;

screenHeight=(float)h;

gridW=(float)(screenWidth/Game.level);

gridH=(float)((screenHeight-40)/Game.level); // 当作默认高比宽多

setNewBitmap();

}

// 设置新位图.

private void setNewBitmap(){

// 设置纵横比.

float w=gridW/bitmap2.getWidth();

float h=gridH/bitmap2.getHeight();

Matrix matrix=new Matrix();

matrix.postScale(w*0.88f,h*0.88f);

// 设置新的大小的位图.

dstbmp1=Bitmap.createBitmap(bitmap1,0,0,bitmap1.getWidth(),bitmap1.getHeight(),

matrix,true);

dstbmp2=Bitmap.createBitmap(bitmap2,0,0,bitmap2.getWidth(),bitmap2.getHeight(),

matrix,true);

}

@Override

protected void onDraw(Canvas canvas){

super.onDraw(canvas);

// 画背景

canvas.drawRect(0,0,screenWidth,screenHeight,background);

// 画网格

for(int i=0;i<=Game.level;i++){

canvas.drawLine(0,i*gridH,screenWidth,i*gridH,hilite);

canvas.drawLine(0,i*gridH+1,screenWidth,i*gridH+1,hilite);

上一页  1 2 3 4  下一页

Tags:Android 黑白 游戏

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