package Minesweeper;

import game.CharBoard;
import game.Coordinate;
import game.PieceType;

public class MinesweeperBoard extends CharBoard {

	/** This character represents a bomb */
	public static final PieceType BOMB = PieceType.X;
	/** This character represents a revealed square */
	public static final PieceType OPEN = PieceType.O;

	/** This 2d array shows the user the number of bombs around each square */
	private int[][] visibleBoard;
	/**
	 * This board keeps track of the size of the board because the value is used
	 * often
	 */
	private int size;

	// The previous board tracks the revealed squares and the squares with bombs
	// on them

	public MinesweeperBoard(int size) {
		super(size);
		visibleBoard = new int[size][size];
		this.size = size;
		generateVisibleBoard();
	}

	public void generateVisibleBoard() {
		for (int j = 0; j < size; j++) {
			for (int i = 0; i < size; i++) {

				if (getBoard()[j][i] == BOMB.getChar())
					visibleBoard[j][i] = 0;
				else
					visibleBoard[j][i] = numOfSurroundingBombs(j, i);
			}
		}
	}

	public int numOfSurroundingBombs(int y, int x) {
		// TODO
		return 0;
	}
	// (1, 1)
	// (1, 0)
	// (1, -1)
	//
	// (0, 1)
	// (0, -1)
	//
	// (-1, -1)
	// (-1, 0)
	// (-1, 1)

	/**
	 * This method verifies that a square can be revealed. For Minesweeper, this
	 * involves checking if the square had been reveled before.
	 * 
	 * @param piece
	 *            the piece that will be checked. Only an OPEN PieceType should
	 *            be given
	 * @param c
	 *            the coordinates that will be checked
	 * @return if the square can be revealed
	 */
	@Override
	public boolean canPlace(PieceType piece, Coordinate c) {
		return getBoard()[c.getX()][c.getY()] != OPEN.getChar();
	}

	@Override
	public char gameEnd() {
		// TODO Auto-generated method stub
		return 0;
	}

}

@@ -432,16 +432,22 @@
 private 
+final 
 int%5B%5D%5B%5D 
@@ -572,16 +572,22 @@
 private 
+final 
 int size
@@ -588,16 +588,113 @@
 t size;%0D
+%0A%09/** This is the number of bombs that should be on the board */%0D%0A%09private final int numOfBombs;%0D
 %0A%0D%0A%09// T
@@ -896,16 +896,55 @@
  size;%0D%0A
+%09%09numOfBombs = (size * size + 4) / 5;%0D%0A
 %09%09genera
@@ -1965,81 +1965,672 @@
 %0A%0D%0A%09
-@Override%0D%0A%09public char gameEnd() %7B%0D%0A%09%09// TODO Auto-generated method stub
+/**%0D%0A%09 * This method detects if the user had ended the game by either revealed a%0D%0A%09 * bomb (a loss) or filling the board (a win).%0D%0A%09 * %0D%0A%09 * @return a character that corresponds to a win or loss%0D%0A%09 */%0D%0A%09@Override%0D%0A%09public char gameEnd() %7B%0D%0A%09%09// The user had removed a bomb by revealing it%0D%0A%09%09if (countBombs() != numOfBombs)%0D%0A%09%09%09return BOMB.getChar();%0D%0A%09%09// The user has not revealed every square%0D%0A%09%09Coordinate c;%0D%0A%09%09for (int j = 0; j %3C size; j++)%0D%0A%09%09%09for (int i = 0; i %3C size; i++) %7B%0D%0A%09%09%09%09c = new Coordinate(j, i);%0D%0A%09%09%09%09if(isEmpty(c)) return ' ';%0D%0A%09%09%09%7D%0D%0A%09%09// The user has revealed every square%0D%0A%09%09return OPEN.getChar();%0D%0A%09%7D%0D%0A%0D%0A%09public int countBombs() %7B%0D%0A%09%09// TODO
 %0D%0A%09%09

add gameEnd conditions