设为首页 加入收藏

TOP

Android骰子游戏案例源码(二)
2014-11-24 02:01:51 来源: 作者: 【 】 浏览:5
Tags:Android 骰子 游戏 案例 源码
; //取得屏幕高度
Dice_x =(int)screen_width/2 - (int)dice.avgWidth/2; //计算骰子的X位置
Dice_y =(int)screen_height/3 - (int)dice.diceHeight/2; //计算骰子的Y位置
// Dice_x = 300;
// Dice_y =200;
System.out.println("screen_width=" + screen_width + ", screen_height=" + screen_height + ", Dice_x=" + Dice_x + ", Dice_y=" + Dice_y);
flag = true; //给flag设置初始值
th.start(); //启动线程
}


@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}

public void run(){
while(flag){
if(isRun){ //用判断语句控制是否进入骰子的投掷过程
for(i = 1; i <= 10; i++){ //随机取骰子值10次,完成投掷,建立此循环的目的是为了让线程持续执行,让投掷可控,
canvas = holder.lockCanvas(); //取得surfaceView的canvas
dice.playDice(canvas, Dice_x, Dice_y); //随机投掷骰子
if(canvas != null){
holder.unlockCanvasAndPost(canvas); //释放holder的画布
}
}
isRun = false;
}
}
try{
Thread.sleep(sleepSpan);
}catch(Exception e){
e.printStackTrace();
}
}
}


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Python动态类型简介 下一篇Java中对象与引用的理解

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: