Android Open Source - FindtheMines Game






From Project

Back to project page FindtheMines.

License

The source code is released under:

MIT License

If you think the Android project FindtheMines 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 findtheminecore;
//from w w  w . ja v a  2 s  .  c om
import java.util.ArrayList;


public class Game {

  public boolean isStarted;
  private RuleSet ruleSet;
  private Board board;
  
  //// constructors  ////
  
  public Game(){
    this(RuleSet.STANDARD,BoardSize.STANDARD);
  }

  public Game(RuleSet ruleSet) {
    this(ruleSet,BoardSize.STANDARD);    
  }

  public Game(BoardSize size) {
    this(RuleSet.STANDARD,size);
  }
  
  public Game(RuleSet ruleSet,BoardSize size){
    isStarted = false;
    this.ruleSet = ruleSet;  
    board = new Board(size);
  }
  
  //// methods

  public void revealBoard() {
    board.revealBoard();
    
  }

  public void newBoard() {
    board.clear();
    randomiseBoard();
  }
  

  public void newBoard(RuleSet rules, BoardSize size) {
    isStarted = false;
    this.ruleSet = rules;  
    board = new Board(size);    
  }
  
  public boolean selectPos(Position pos) {
    if (isStarted){
      if (!board.selectTile(pos)){
        return false;
      }else{
        
      }
      if (board.isExploded()){
        endGame();
      }      
    }

    return true;
  }
  
  public void markPos(Position pos) {
    if (isStarted){
      board.markTile(pos);
    }
  }
  
  public void startGame() {
    isStarted = true;    
  }
  
  public void endGame() {
    isStarted = false;  
  }
  
  public void reStartGame() {
    isStarted = true;  
  }  
  public void changeRuleSet(RuleSet ruleSet) {
    this.ruleSet = ruleSet;
    
  }  
  
  public void randomiseBoard(){
    if (ruleSet != RuleSet.TEST){
      randomiseBoard(this.getBoardSize().getRandomValue());
    }
      
  }
  
  private BoardSize getBoardSize() {
    // TODO Auto-generated method stub
    return board.getBoardSize();
  }

  public void randomiseBoard(int amount){
    int randomAmount = amount;
    for (int count = 0;count<randomAmount ;count++){
      int row = (int)(Math.random()*board.getNoOfRows());
      int col = (int)(Math.random()*board.getNoOfCols());
      this.getBoard().setMine(new Position(row, col));
    }  
  }

  public void revealMines() {
    board.revealMines();  
  }
  
  //// tests  ////
  
  public boolean isStarted() {
    return isStarted;
  }

  public boolean isWon() {
    if (board.getNoOfMovesLeft()==0 && !board.isExploded()){
      return true;
    }
    return false;
  }  
  
  public boolean isEnded() {
    return (!isStarted);
  }

  ////  Setters ////


  public void setBoard(Board board) {
    this.board = board;
    
  }  
  //// getters ////

  
  public RuleSet getRuleSet() {
    return ruleSet;
  }

  public Board getBoard() {
    return board;
  }

  public int getValue(Position pos) {
    return board.getValue(pos);
  }

  public Tile getPos(Position pos) {
    return board.getTile(pos);
  }

  public int getNoMovesLeft() {
    return board.getNoOfMovesLeft();
  }

  public int getNoOfSelected() {
    return board.getNoOfSelected();
  }

  public int getNoOfMarked() {
    return board.getNoOfMarked();
  }
  public int getNoOfMines() {
    return board.getNoOfMines();
  }

  public void unMarkPos(Position pos) {
    board.unMark(pos);
    
  }

  public ArrayList<Tile> getAllPos() {
    
    ArrayList<Tile> allTiles = new ArrayList<Tile>();
    allTiles = board.getAllTiles();
    return allTiles ;
  }

  public int size() {
    return board.getSize();
  }

  public ArrayList<String> getStringArry() {
    ArrayList<Tile> allTiles = new ArrayList<Tile>();
    ArrayList<String> list = new ArrayList<String>();
    allTiles = board.getAllTiles();
    for (Tile tile: allTiles){
      list.add(":");
      list.add("0");
      list.add("1");
      list.addAll(tile.toStringArray());
    }
    
    return list;
  }


}




Java Source Code List

com.stealthness.findthemines.ImageAdapter.java
com.stealthness.findthemines.MainActivity.java
com.stealthness.findthemines.SplashScreen.java
findtheminecore.BoardSize.java
findtheminecore.Board.java
findtheminecore.Game.java
findtheminecore.Position.java
findtheminecore.RuleSet.java
findtheminecore.TileType.java
findtheminecore.Tile.java