Android Open Source - Minesweeper Game Tile






From Project

Back to project page Minesweeper.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project Minesweeper listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.minesweeper;
//from  ww  w.j  a va 2  s  . c o  m
import android.content.Context;

import android.util.AttributeSet;
import android.util.Log;
import android.widget.Button;

/*
 * GameTile extends Button class to include the private members for the game.
 * */

public class GameTile extends Button {

  private Context mContext;
  private boolean isCovered;
  private boolean isMine;
  private boolean isFlagged;
  private boolean isQuestionMark;
  public int noOfAdjMines;

  public GameTile(Context ctxt) {
    super(ctxt);
    mContext = ctxt;
  }

  public void initGameTile(int width, int height) {
    isCovered = true;
    isMine = false;
    isFlagged = false;
    isQuestionMark = false;
    noOfAdjMines = 0;
    Log.d("Minew", "GameTile: " + width);
    this.setWidth(width);
    this.setHeight(height);
    this.setBackgroundResource(R.drawable.active_tile);
  }

  public void openTile() {
    isCovered = false;
    this.setEnabled(false);
    this.setText("" + noOfAdjMines);
    this.setBackgroundResource(R.drawable.inactive_tile);
    this.setClickable(false);
  }

  // ----Getter/Setter---------
  public boolean isCovered() {
    return isCovered;
  }

  public boolean isMine() {
    return isMine;
  }

  public void plantMine() {
    this.isMine = true;
  }

  public int getNoOfAdjMines() {
    return this.noOfAdjMines;
  }

  public void setNoOfAdjMines(int noOfMines) {
    this.noOfAdjMines = noOfMines;
  }

  public boolean isFlagged() {
    return isFlagged;
  }

  public void setFlagged(boolean isFlagged) {
    this.isFlagged = isFlagged;
  }

  public boolean isQuestionMark() {
    return isQuestionMark;
  }

  public void setQuestionMark(boolean isQuestionMark) {
    this.isQuestionMark = isQuestionMark;
  }

}




Java Source Code List

com.example.minesweeper.GameTile.java
com.example.minesweeper.MainActivity.java
com.example.minesweeper.MinesweeperActivity.java