public class WelcomeViewGoThread extends Thread{
WelcomeView welcomeView;//welcomeView的引用 private int sleepSpan = 150;
private boolean flag = true;//循环标记位
public WelcomeViewGoThread(WelcomeView welcomeView) {//构造器 this.welcomeView = welcomeView;//得到welcomeView的引用 }
public void run() {//重写的run方法法 }
26
while (flag) {//循环 }
welcomeView.drawIndex++;//自加
if(welcomeView.drawIndex>welcomeView.bitmapsID.length-1){ }
if(welcomeView.drawIndex%5 == 0){ } try{
Thread.sleep(sleepSpan);//睡眠 }catch(Exception e){
e.printStackTrace();//打印异常信息 }
welcomeView.drawString = !welcomeView.drawString; welcomeView.drawIndex =
welcomeView.bitmapsID.length-10;
public void setFlag(boolean flag){//循环标志位的设置方法 this.flag = flag;
}}
当用户单击“放弃”菜单时,将进入帮助界面,菜单按钮时,重新开始。
27
去
canvas.drawBitmap(stop, 150,380, paint);
canvas.drawBitmap(change, 230,380, paint); canvas.drawBitmap(drop, 150,420, paint); canvas.drawBitmap(help, 230,420, paint); if(status == 2){//游戏胜利 tt.flag = false;
canvas.drawBitmap(win, 40, 160, paint); }else if(status == 3){//游戏失败 tt.flag = false;
canvas.drawBitmap(fail, 80, 180, paint); }else if(status == 4){//是否退出 canvas.drawBitmap(exit, 70, 180, paint); }else if(status == 0){//游戏中 if(tishi == true){ canvas.drawBitmap(heart, 10, 340, paint);
}
//画全部数字
tt.flag = true; int x;
int y;
for(int i = 0;i < 9;i++){ for(int j = 0;j < 9;j++){ x = 16+28*j;
28
y = 35+29*i; if(j>=3&&j<6){ }
if(j>=6){ }
if(i>=3&&i<6){ }
if(i>=6){ }
canvas.drawBitmap(number_bitmap[outputNum[i][j]], x, y, } }
//画用户输入的数字
for(int i = 0;i < 9;i++){ for(int j = 0;j < 9;j++){ x = 16+28*j; y = 35+29*i; if(j>=3&&j<6){ }
if(j>=6){ }
if(i>=3&&i<6){ }
if(i>=6){ }
canvas.drawBitmap(number_input[inputNum[i][j]], x, y,
y += 34; y += 18; x += 42; x += 20; y += 34; y += 18; x += 42; x += 20;
paint);
paint);
}
计时器线程的开发
TimeThread类的实现比较简单,只需每一秒更改以下GameView中表示时间的属性即可,代码如下:
public class TimeThread extends Thread{
GameView gameView;//声明GameView的引用
29
相关推荐: