青岛滨海学院毕业设计 绪论
welcomeViewGoThread = new WelcomeViewGoThread(this);
public void initBitmap(){//初始化图片方法
paint = new Paint(); paint2 = new Paint(); paint2.setAlpha(125);
}
paint.setColor(Color.WHITE);
paint.setAntiAlias(true);//打开抗锯齿
paint.setTextSize(18);
bitmaps = new Bitmap[bitmapsID.length]; for(int i=0; i bitmaps[i] = BitmapFactory.decodeResource(getResources(), bitmapsID[i]);} Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.menu); for(int i=0; i menuBitmap[i] = Bitmap.createBitmap(bitmap, 0, (bitmap.getHeight()/menuBitmap.length)*i, bitmap.getWidth(), } (bitmap.getHeight()/menuBitmap.length)); bitmap = null;//释放掉大图 } protected void onDraw(Canvas canvas) {//绘制方法 super.onDraw(canvas); canvas.drawColor(Color.BLACK);//清背景 canvas.drawBitmap(bitmaps[drawIndex], 0, 100, paint); if(status == 0){ if(drawString){ canvas.drawText(\点击屏幕继续...\ } }else if(status == 1){//菜单状态时 canvas.drawRect(0, 0, 320, 480, paint2); for(int i=0; i canvas.drawBitmap(menuBitmap[i], 60, 130+50*i, null);} } } public boolean onTouchEvent(MotionEvent event) {//屏幕监听方法 if(event.getAction() == MotionEvent.ACTION_DOWN){//屏幕被按下事件 double x = event.getX(); double y = event.getY(); if(status == 0){ 26 status = 1; 青岛滨海学院毕业设计 绪论 }else if(status == 1){ if(x>60 && x<260 && y>130 && y<160){//开始游戏 activity.myHandler.sendEmptyMessage(1); }else if(x>60 && x<260 && y>180 && y<210){//关于游戏 activity.myHandler.sendEmptyMessage(3); }else if(x>60 && x<260 && y>230 && y<260){//帮助游戏 activity.myHandler.sendEmptyMessage(4); }else if(x>60 && x<260 && y>280 && y<310){//退出游戏 System.exit(0);//直接退出游戏} } } return super.onTouchEvent(event); } public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3){} public void surfaceCreated(SurfaceHolder arg0) { welcomeViewDrawThread.setFlag(true);//设置循环标志位 welcomeViewGoThread.setFlag(true); welcomeViewDrawThread.start();//启动线程 welcomeViewGoThread.start();//启动线程 } public void surfaceDestroyed(SurfaceHolder arg0) { boolean retry = true;//循环标志位 welcomeViewDrawThread.setFlag(false);//设置循环标志位 welcomeViewGoThread.setFlag(false); while (retry) {//循环 try { welcomeViewDrawThread.join();//得到线程结束 welcomeViewGoThread.join();//得到线程结束 retry = false; } catch (Exception e) {//不断地循环,直到刷帧线程结束 e.printStackTrace(); } } }} 4.3.3.7当用户单击“换题”菜单时,将进入帮助界面,菜单按钮时,新界面进入。 27 青岛滨海学院毕业设计 绪论 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方法法 while (flag) {//循环 welcomeView.drawIndex++;//自加 if(welcomeView.drawIndex>welcomeView.bitmapsID.length-1){ welcomeView.drawIndex = welcomeView.bitmapsID.length-10; } if(welcomeView.drawIndex%5 == 0){ welcomeView.drawString = !welcomeView.drawString; } try{ Thread.sleep(sleepSpan);//睡眠 }catch(Exception e){ e.printStackTrace();//打印异常信息 } } } public void setFlag(boolean flag){//循环标志位的设置方法 this.flag = flag; }} 4.3.3.8当用户单击“放弃”菜单时,将进入帮助界面,菜单按钮时,重新开始。 28 青岛滨海学院毕业设计 绪论 29 青岛滨海学院毕业设计 绪论 去 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; y = 35+29*i; if(j>=3&&j<6){ x += 20; } if(j>=6){ x += 42; } if(i>=3&&i<6){ y += 18; } 30 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库专科毕业设计模板- 副本1 - 图文(7)在线全文阅读。
相关推荐: