扫雷Android版详解版

这篇博客详细介绍了如何在Android平台上实现扫雷游戏,主要涉及两个关键类:GameView.java和Main.java。
摘要由CSDN通过智能技术生成

本程序有两个类,分别为GameView.java和Main.java

GameView.java

package org.yexing.android.games.mine;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;

public class Main extends Activity {

 GameView gameView;
 @Override
 public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  gameView = new GameView(this);
  setContentView(gameView);
 }

 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  gameView.gameState = GameView.STATE_LOST;
  super.onPause();
 }

 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
  // TODO Auto-generated method stub
  gameView.onKeyDown(keyCode, event);
  return super.onKeyDown(keyCode, event);
 }
 G
 @Override
 public boolean onKeyUp(int keyCode, KeyEvent event) {
  // TODO Auto-generated method stub
  gameView.onKeyUp(keyCode, event);
  return super.onKeyUp(keyCode, event);
 }

}

package org.yexing.android.games.mine;

import java.util.Random;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;

public class GameView extends View {
 private static final String TAG = "GameView";

 private RefreshHandler mRedrawHandler = new RefreshHandler();

 class RefreshHandler extends Handler {

  @Override
  public void handleMessage(Message msg) {
   GameView.this.updateView();
   GameView.this.invalidate();
  }

  public void sleep(long delayMillis) {
   this.removeMessages(0);
   sendMessageDelayed(obtainMessage(0), delayMillis);
  }
 };

 // 游戏状态 开始 胜利 失败 暂停
 public static final int STATE_PLAYING = 0;
 public static final int STATE_WIN = 1;
 public static final int STATE_LOST = 2;
 public static final int STATE_PAUSE = 3;
 public int gameState;
 //随机
 private static final Random random = new Random();
 //画笔
 private Paint paint;
 //发送消息
 private String message;
 //格子的宽度
 private static final int tileWidth = 16;
 private static final int tileHeight = 16;
 //格子的数量
 private static final int tilesCount = 19;
 private static final int margin = 16;
 private static final int titleHeight = 30;
 //棋子
 private Bitmap[] tiles;
 //表面层
 private int[][] mapSky;
 //底层
 
安卓 扫雷源码 添加重新开始按钮支持 Android studio ====================================== Risky Project Location: ----------------------- The tools *should* handle project locations in any directory. However, due to bugs, placing projects in directories containing spaces in the path, or characters like ", ' and &, have had issues. We're working to eliminate these bugs, but to save yourself headaches you may want to move your project to a location where this is not a problem. D:\Program Files\android_s_workplace\terrysaolei - Ignored Files: -------------- The following files were *not* copied into the new Gradle project; you should evaluate whether these are still needed in your project and if so manually move them: * ic_launcher-web.png * proguard-project.txt Moved Files: ------------ Android Gradle projects use a different directory structure than ADT Eclipse projects. Here's how the projects were restructured: * AndroidManifest.xml => app\src\main\AndroidManifest.xml * assets\ => app\src\main\assets * res\ => app\src\main\res\ * src\ => app\src\main\java\ Next Steps: ----------- You can now build the project. The Gradle project needs network connectivity to download dependencies. Bugs: ----- If for some reason your project does not build, and you determine that it is due to a bug or limitation of the Eclipse to Gradle importer, please file a bug at http://b.android.com with category Component-Tools. (This import summary is for your information only, and can be deleted after import once you are satisfied with the results.)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值