Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 60 additions & 8 deletions minesweeper/src/main/java/edu/pdx/cs410J/katas/Minesweeper.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,68 @@
package edu.pdx.cs410J.katas;

public class Minesweeper {
public class Minesweeper {
int row;
int column;

public Minesweeper(int row, int column) {
char[][] board;

}
int indexRow = 0;

public void addRow(String row) {
public Minesweeper(int row, int column) throws ZeroSizedBoardException {
if (row == 0 || column == 0)
throw new ZeroSizedBoardException();
this.row = row;
this.column = column;

}
board = new char[row][column];
}

public String solve() {
return null;
}
public void addRow(String row) throws RaggedBoardException {
if (row.length() != this.column) {
throw new RaggedBoardException();
}
for (int z = 0; z < this.column; ++z) {
board[indexRow][z] = row.charAt(z);
}
++indexRow;

}

public String solve() {
StringBuilder sb = new StringBuilder();
for (int rowCount = 0; rowCount < this.row; rowCount++) {
for (int columnCount = 0; columnCount < this.column; columnCount++) {
//if (board[rowCount][columnCount] == '.') {
// sb.append(checkMines(rowCount, columnCount));
//} else {
sb.append(board[rowCount][columnCount]);
//}
}
if (rowCount > 1) {
sb.append("\n");
}
}
return sb.toString();
}

/*
private int checkMines(int rowCount, int columnCount) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a work in progress method that will calculate the number of mines surrounding a given position. The intention is that the integer that this method returns is what will be displayed by the solve() method.

int numberOfSurroundingMines = 0;
for (int rowCheckPos = rowCount - 1; rowCheckPos <= rowCount + 1; rowCheckPos++) {
if (rowCheckPos < 0 || rowCheckPos > this.row) {
continue;
} else {
for (int colCheckPos = columnCount - 1; colCheckPos <= columnCount + 1; colCheckPos++) {
if (colCheckPos < 0 || colCheckPos > this.column) {
continue;
} else if (board[rowCheckPos][colCheckPos] == '*') {
numberOfSurroundingMines++;
}
}
}
}
return numberOfSurroundingMines;
}
*/
}
26 changes: 12 additions & 14 deletions minesweeper/src/test/java/edu/pdx/cs410J/katas/MinesweeperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,40 @@
*/
public class MinesweeperTest {

@Ignore

@Test(expected = ZeroSizedBoardException.class)
public void zeroSizedBoardThrowException() {
public void zeroSizedBoardThrowException() throws ZeroSizedBoardException {
new Minesweeper(0, 0);
}

@Ignore

@Test(expected = ZeroSizedBoardException.class)
public void boardWithZeroRowsThrowsException() {
public void boardWithZeroRowsThrowsException() throws ZeroSizedBoardException {
new Minesweeper(0, 5);
}

@Ignore

@Test(expected = ZeroSizedBoardException.class)
public void boardWithZeroColumnsThrowsException() {
public void boardWithZeroColumnsThrowsException() throws ZeroSizedBoardException {
new Minesweeper(5, 0);
}

@Ignore

@Test(expected = RaggedBoardException.class)
public void raggedInputRowThrowsException() {
public void raggedInputRowThrowsException() throws ZeroSizedBoardException, RaggedBoardException {
Minesweeper board = new Minesweeper(1, 2);
board.addRow(".");
}

@Ignore
@Test(expected = RaggedBoardException.class)
public void raggedInputColumnThrowsException() {
public void raggedInputColumnThrowsException() throws ZeroSizedBoardException, RaggedBoardException {
Minesweeper board = new Minesweeper(2, 1);
board.addRow(".");
board.addRow("..");
}

@Ignore
@Test
public void oneSquareWithMine() {
public void oneSquareWithMine() throws ZeroSizedBoardException, RaggedBoardException {
Minesweeper board = new Minesweeper(1, 1);
board.addRow("*");

Expand All @@ -56,7 +54,7 @@ public void oneSquareWithMine() {

@Ignore
@Test
public void oneSquareWithNoMine() {
public void oneSquareWithNoMine() throws ZeroSizedBoardException, RaggedBoardException {
Minesweeper board = new Minesweeper(1, 1);
board.addRow(".");

Expand All @@ -66,7 +64,7 @@ public void oneSquareWithNoMine() {

@Ignore
@Test
public void twoByTwoBoardWithMineAtZeroZero() {
public void twoByTwoBoardWithMineAtZeroZero() throws ZeroSizedBoardException, RaggedBoardException {
Minesweeper board = new Minesweeper(2, 2);
board.addRow("*.");
board.addRow("..");
Expand Down