From cefce78b9581abdabadc87d158dcfe72d97934ec Mon Sep 17 00:00:00 2001 From: Dakota Sanchez Date: Wed, 26 Jul 2017 20:20:28 -0700 Subject: [PATCH] Create the ultimate minesweeper --- .../edu/pdx/cs410J/katas/Minesweeper.java | 36 +++++++++++++++---- .../edu/pdx/cs410J/katas/MinesweeperTest.java | 17 +++++---- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/minesweeper/src/main/java/edu/pdx/cs410J/katas/Minesweeper.java b/minesweeper/src/main/java/edu/pdx/cs410J/katas/Minesweeper.java index 3fe6bf0..8c32bd9 100644 --- a/minesweeper/src/main/java/edu/pdx/cs410J/katas/Minesweeper.java +++ b/minesweeper/src/main/java/edu/pdx/cs410J/katas/Minesweeper.java @@ -2,15 +2,37 @@ public class Minesweeper { - public Minesweeper(int row, int column) { + private char[][] inputBoard; + private char[][] outputBoard; - } + int rowsFilledIn = 0; - public void addRow(String row) { + public Minesweeper(int row, int column) throws ZeroSizedBoardException { + if (row == 0 || column == 0) { + throw new ZeroSizedBoardException(); + } + this.inputBoard = new char[row][column]; + } - } + public void addRow(String rowToCopy) throws RaggedBoardException { + if (rowToCopy.length() != inputBoard[0].length) { + throw new RaggedBoardException(); + } - public String solve() { - return null; - } + if (rowsFilledIn == inputBoard.length) { + System.out.println("Board is full."); + } else { + rowToCopy.getChars(0, rowToCopy.length(), inputBoard[rowsFilledIn], 0); + ++this.rowsFilledIn; + } + } + + public String solve() { +// for (int i = 0; i < inputBoard.length; i++) { +// for (int j = 0; j < inputBoard[0].length; j++) { +// +// } +// } + return null; + } } diff --git a/minesweeper/src/test/java/edu/pdx/cs410J/katas/MinesweeperTest.java b/minesweeper/src/test/java/edu/pdx/cs410J/katas/MinesweeperTest.java index c209511..12da429 100644 --- a/minesweeper/src/test/java/edu/pdx/cs410J/katas/MinesweeperTest.java +++ b/minesweeper/src/test/java/edu/pdx/cs410J/katas/MinesweeperTest.java @@ -11,34 +11,33 @@ */ 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(".."); @@ -46,7 +45,7 @@ public void raggedInputColumnThrowsException() { @Ignore @Test - public void oneSquareWithMine() { + public void oneSquareWithMine() throws ZeroSizedBoardException, RaggedBoardException{ Minesweeper board = new Minesweeper(1, 1); board.addRow("*"); @@ -56,7 +55,7 @@ public void oneSquareWithMine() { @Ignore @Test - public void oneSquareWithNoMine() { + public void oneSquareWithNoMine() throws ZeroSizedBoardException, RaggedBoardException{ Minesweeper board = new Minesweeper(1, 1); board.addRow("."); @@ -66,7 +65,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("..");