From c3cc3fe009db765bfcaa0a77b072ea471abf08d6 Mon Sep 17 00:00:00 2001 From: LaVloZ Date: Sun, 17 Nov 2013 01:12:59 +0100 Subject: [PATCH] Making some changes. --- .classpath | 1 + src/com/github/puzzles/core/FlipPuzzle.java | 32 +++++++++++++++++++++---- src/com/github/puzzles/core/SlidingPuzzle.java | 12 ++++++++++ src/com/github/puzzles/test/FlipPuzzleTest.java | 27 +++++++++++++++++++++ src/com/github/puzzles/test/MatricesTest.java | 18 ++++++++++++++ 5 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 src/com/github/puzzles/core/SlidingPuzzle.java create mode 100644 src/com/github/puzzles/test/FlipPuzzleTest.java create mode 100644 src/com/github/puzzles/test/MatricesTest.java diff --git a/.classpath b/.classpath index fb50116..3e0fb27 100644 --- a/.classpath +++ b/.classpath @@ -2,5 +2,6 @@ + diff --git a/src/com/github/puzzles/core/FlipPuzzle.java b/src/com/github/puzzles/core/FlipPuzzle.java index b2cdcbf..2668317 100644 --- a/src/com/github/puzzles/core/FlipPuzzle.java +++ b/src/com/github/puzzles/core/FlipPuzzle.java @@ -10,13 +10,33 @@ public class FlipPuzzle extends AbstractRectangularPuzzle implements Fl Boolean correctPuzzle[][]; - public FlipPuzzle(int width, int height, Difficulty difficulty) { - super(makeRandomPuzzleHelper(width, height), width, height, difficulty); + public FlipPuzzle(Boolean[][] puzzle){ + this(puzzle, Difficulty.PERSONALISED); + } + + public FlipPuzzle(Boolean [][] puzzle, Difficulty difficulty){ + super(puzzle, GetWidth(puzzle), GetHeight(puzzle), difficulty); this.correctPuzzle = new Boolean[getWidth()][getHeight()]; Matrices.fill(correctPuzzle, new Boolean(true)); } + public FlipPuzzle(int width, int height, Difficulty difficulty) { + this(makeRandomPuzzleHelper(width, height), difficulty); + } + + private static int GetWidth(Boolean [][] puzzle){ + if(puzzle != null) + return puzzle.length; + return 0; + } + + private static int GetHeight(Boolean [][] puzzle){ + if((puzzle != null) && (puzzle[0] != null)) + return puzzle[0].length; + return 0; + } + private Boolean toggle(Boolean bool){ return !bool; } @@ -41,9 +61,11 @@ public class FlipPuzzle extends AbstractRectangularPuzzle implements Fl @Override public void flip(Point index) { - int x = new Double(index.getX()).intValue(); - int y = new Double(index.getY()).intValue(); - + //int x = new Double(index.getX()).intValue(); + //int y = new Double(index.getY()).intValue(); + int x = (int)index.getX(); + int y = (int)index.getY(); + try { puzzle[y][x] = toggle(puzzle[y][x]); } catch (ArrayIndexOutOfBoundsException e) {} diff --git a/src/com/github/puzzles/core/SlidingPuzzle.java b/src/com/github/puzzles/core/SlidingPuzzle.java new file mode 100644 index 0000000..55b6ef9 --- /dev/null +++ b/src/com/github/puzzles/core/SlidingPuzzle.java @@ -0,0 +1,12 @@ +package com.github.puzzles.core; + +public class SlidingPuzzle extends AbstractRectangularPuzzle implements + Slidable { + + @Override + public boolean check() { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/com/github/puzzles/test/FlipPuzzleTest.java b/src/com/github/puzzles/test/FlipPuzzleTest.java new file mode 100644 index 0000000..841294b --- /dev/null +++ b/src/com/github/puzzles/test/FlipPuzzleTest.java @@ -0,0 +1,27 @@ +package com.github.puzzles.test; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.github.puzzles.core.Difficulty; +import com.github.puzzles.core.FlipPuzzle; + +public class FlipPuzzleTest { + + @Test + public void testCheck() { + new FlipPuzzle(5, 5, Difficulty.EASY).check(); + } + + @Test + public void testFlipPuzzle() { + fail("Not yet implemented"); + } + + @Test + public void testFlip() { + fail("Not yet implemented"); + } + +} diff --git a/src/com/github/puzzles/test/MatricesTest.java b/src/com/github/puzzles/test/MatricesTest.java new file mode 100644 index 0000000..bcb8d3d --- /dev/null +++ b/src/com/github/puzzles/test/MatricesTest.java @@ -0,0 +1,18 @@ +package com.github.puzzles.test; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.github.puzzles.core.Difficulty; +import com.github.puzzles.core.FlipPuzzle; +import com.github.puzzles.util.Matrices; + +public class MatricesTest { + + + @Test + public void testFill() { + System.out.println(this); + } +} -- 2.11.4.GIT