Home
JavaEE
Java GUI
Framework
DHtml
Android
插画
教程下载

ATOM 2.0   RSS 2.0
Add to iGoogle Add to Live.com
  • 今天终于收到金山快盘的邀请码
  • 利用最短ie判断在不同浏览器上播放背景音乐
  • 对插画方面的一点感受与回忆
  • 网上看到的两个死里逃生的图片,记录一下
  • 今天开通了糖果社区,附几个激活码
  • 终于可以实现我的多个微博实时同步了
  • 备案和现场拍照就是对站长们的瞎折腾
  • 对Android在互联网应用开发上的纠结
  • 收藏夹中的书签都没了,决定写一个自已的书签管理器
  • 测试自已整理的本机的webapps客户端发送博文能否成功。
  • 今天开通了糖果社区,附几个激活码
  • 终于可以实现我的多个微博实时同步了
  • 备案和现场拍照就是对站长们的瞎折腾
  • 昨天借用飞姐的佳作做的一个浪漫爱情网页
  • 有几个腾讯微博的邀请码(实时更新)
  • BB的网站移到了GAE-JAVA上了
  • 一个基于GAE Python Web.py和JQuery的留言本程序
  • 类许愿墙的一个告白网站和一个电子书网站
  • Android中用Bitmap获取图片中某个区域的图象
  • 对暴力破解带密码的QQ相册的可行性分析
  • 对淘宝web旺旺版一些通讯接口的研究

看看android扫雷游戏的主要代码

posted by David Chen at January 18, 2009, 3:15 PM    

其实用Canvas来画网格还更好,更省内存,可惜只是在学习中,先了解一下组件的用法,以后再深入。
A Drawable is a general abstraction for "something that can be drawn." Most often you will deal with
Drawable as the type of resource retrieved for drawing things to the screen;
Drawable一般用于处理res/drawable目录下的文件,
Activity.getResources().getDrawable(R.drawable.m0);
// 这样就可以取得目录下名字叫m0的资源文件了,比较方便,
ImageButton.setImageDrawable( m0 );
// 就可以设定要显示的图了,
Drawable可以是混合的一串图,比如某个动作的一连贯图或层次图,然后可以用
setBounds(Rect),setState(int[]), setLevel(int) 来取得要用的部分

// boomArr存放的是网格的数组指针,在boomArr中的随机置生成炸弹,根据难度不同生成不同数量的炸弹
void setBooms( final int level ) {
// 以线程方式在后台生成炸弹,level是难度,每个难度增加50个炸弹
new Thread() {
public void run() {
int count = 250 + level * 50;
int total = columnCount * rowCount;
for( int i=0; i<count; i++) {
//生成从[0,count-1]间的数字,即随机设置某些网格是炸弹
boomArr[(int) ((total) * java.lang.Math.random())].isBoom = true;
}
}
}.start();
}

// 生成网格,第一列为1,2,3...第二列是4,5,6...的顺序生成
void loadBooms( final int level ) {
int index = 0;
boomArr = new Boom[columnCount * rowCount];
int x = 0, y = 0, start_x = 10, start_y = 46;
for( int c=0; c<columnCount; c++ ) {
x = start_x + c + c * 14;
for( int r=0; r<rowCount; r++ ) {
y = start_y + r + r * 14;
boomArr[ index ] = new Boom(this, index);
//指向生成的网格的指针,可能是炸弹,也可能不是
layout.addView( boomArr[ index ++ ],
new AbsoluteLayout.LayoutParams(14, 14, x, y) );
}
}
setBooms( level );
}

void resetBooms( final int level ) {
for(int c=0; c<boomArr.length; c++) {
boomArr[c].reset();
}
setBooms( level );
}

void seeAllBooms() {
for(int c=0; c<boomArr.length; c++) {
if( !boomArr[c].hasClicked ) {
boomArr[c].performClick();
// 响应boom的点击事件,
}
}
}

最看看某个网格的点击代码:这个就是扫雷功能的主要算法了,比较简单,
int[] tmp = new int[8];
tmp[0] = index - Booms.rowCount - 1; // 左上角
tmp[1] = index - 1; // 正上方
tmp[2] = index + 25 - 1; // 右上角
tmp[3] = tmp[0] + 1; // 左边
tmp[4] = tmp[2] + 1; // 右边
tmp[5] = tmp[0] + 2; // 左下角
tmp[6] = index + 1; // 正下方
tmp[7] = tmp[2] + 2; // 右下角

int total = 0;
AbsoluteLayout.LayoutParams t1 = (AbsoluteLayout.LayoutParams) getLayoutParams();
AbsoluteLayout.LayoutParams t2;
for( int c=0; c<tmp.length; c++ ) {
if( tmp[c] < 0 || tmp[c] >= Booms.columnCount * Booms.rowCount)
continue ;
if( Booms.boomArr[ tmp[c] ].isBoom ) {
t2 = (AbsoluteLayout.LayoutParams) Booms.boomArr[ tmp[c] ].getLayoutParams();
if( Math.abs(t1.x - t2.x) > 14 * 2 || Math.abs(t1.y - t2.y) > 14 * 2)
continue ;
total ++;
}
}

// 载入数字对应的图
setImageDrawable( Booms.ms[ total ] );
Labels:   Android  
Trackback:   http://cwq.iou1314.com/android-game_a351
微博最近更新
[2010-07-31 16:33]    今天下午又将昨天赢的哎齐出来了,郁闷,一进一出,要有入没出才行啊。
[2010-07-31 07:40]    昨晚又去啊泄度开台,呢次赢左差唔多3旧水,下周星期一请假,回郁南去转社保和入党资料。
本站内的任何文章,只代表个人意见或学习所用,如有版权声明,请尊重作者的劳动成果,在转载时请保留原始链接并注明出处。
Power by David's PhpCms, © 2007 - 2010 CWQ.IOU1314.COM All Rights Reserved.