diff --git a/nbproject/project.properties b/nbproject/project.properties index 09c70e615bdff0440eaf43232a05a9b1d01ce72f..7da044b01d55acbf237efce054db8c222ad0efe1 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,75 +1,76 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -application.title=Minesweeper2 -application.vendor=D\u00e1niel -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# Files in build.classes.dir which should be excluded from distribution jar -dist.archive.excludes= -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/Minesweeper2.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -includes=** -jar.compress=false -javac.classpath= -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.processorpath=\ - ${javac.classpath} -javac.source=1.7 -javac.target=1.7 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -main.class=Program.Program -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=Minesweeper2 +application.vendor=D\u00e1niel +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Minesweeper2.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=Program.Program +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/settings2.dat b/settings2.dat index 843909e98fcbd1f726ce8eb901724fbcb52991de..5b05a879b88d367f8a80a7845fb958acecbd093c 100644 Binary files a/settings2.dat and b/settings2.dat differ diff --git a/src/GUI/game/Model.java b/src/GUI/game/Model.java index b8cf67c23625948e41ac86291feadda1d6743beb..c91a58eba0192fb49ed29d321a0e4c125ceaa4c1 100644 --- a/src/GUI/game/Model.java +++ b/src/GUI/game/Model.java @@ -263,7 +263,7 @@ public class Model return po; } - private boolean isMined(int x, int y) + public boolean isMined(int x, int y) { if( x < 0 || y < 0 || x > controller.game.game.settings.size || y > controller.game.game.settings.size ) { @@ -367,6 +367,11 @@ public class Model this.squares[x][y].setBackground(color); this.squares[x][y].setForeground(colorF); } + /** + * Amikor a user megjelol egy poziciot, akkor ez fut le. + * + * @param pos + */ void flagButton(int[] pos) { if( isGameOver ) diff --git a/src/GUI/game/RecursiveNullFinder.java b/src/GUI/game/RecursiveNullFinder.java index 4ee1190a3158615ed2447cadfbe6a821fd967944..5e61dc9a36b69420202b5950e3c5a9729ab9fab3 100644 --- a/src/GUI/game/RecursiveNullFinder.java +++ b/src/GUI/game/RecursiveNullFinder.java @@ -27,7 +27,13 @@ public class RecursiveNullFinder extends Thread this.wasThere = wasThere; this.controller = controller; } - private ArrayList<int[]> getNullFieldAround() + /** + * getNullFieldAround() + * Megkeresi az adott elem koruli osszes nulla ertekkel rendelkezo elemet. + * + * @return + */ + public ArrayList<int[]> getNullFieldAround() { if( wasThere == null ) wasThere = new ArrayList<>(); @@ -75,6 +81,14 @@ public class RecursiveNullFinder extends Thread } return nullsAround; } + /** + * X-Y koordináták alapján keres az ArrayListben, ha a koordináta benne van, true-t ad vissza, ha nem false-ot. + * + * + * @param container + * @param position + * @return + */ public Boolean isContains(ArrayList<int[]> container, int[] position) { for( int[] act : container) @@ -84,16 +98,26 @@ public class RecursiveNullFinder extends Thread } return false; } + /** + * ArrayList-be helyez be elemeket, úgy, hogy ha az elem már szerepelt, nem rakja be mégegyszer. + * + * @param to + * @param add + * @return + */ public ArrayList<int[]> addUnique(ArrayList<int[]> to, int[] add) { for (int[] actTo : to ) { - if( actTo == add ) + if( actTo[0] == add[0] && actTo[1] == add[1] ) return to; } to.add(add); return to; } + /** + * A szál indítása + */ @Override public void run() { diff --git a/test/GUI/game/ModelTest.java b/test/GUI/game/ModelTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f566358bb973cc24a9943f362fcf02a66cb966aa --- /dev/null +++ b/test/GUI/game/ModelTest.java @@ -0,0 +1,123 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package GUI.game; + +import Program.Settings; +import java.awt.Color; +import javax.swing.JButton; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author kovax + */ +public class ModelTest { + + public ModelTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + /* + 0123 + 0*X** 2,2 3,2 2,3 3,3 + 1**** x: 3 y= 2 + 2**** + 3**** + */ + /** + * Test of calculateMinesAround method, of class Model. + */ + @Test + public void testCalculateMinesAround() { + + System.out.println("colorField"); + int[] pos = {1,1}; + + Program.Settings settings = new Settings(4, "Test", 1, 600, 600); + GUI.game.Game game = new Game(settings, new Program.Game(settings)); + + game.controller.model.build(); + //2,2 + int mines = 0; + if( game.controller.model.isMined(0, 0) ) + mines++; + if( game.controller.model.isMined(2, 0) ) + mines++; + if( game.controller.model.isMined(0, 1) ) + mines++; + if( game.controller.model.isMined(1, 1) ) + mines++; + if( game.controller.model.isMined(2, 1) ) + mines++; + if( game.controller.model.isMined(1, 0)) + mines++; + + int realValue = game.controller.model.calculateMinesAround(1, 0); + System.out.println("Mines:" + mines + "real:" + realValue); + assertEquals(mines, realValue); + } + + /** + * Test of colorField method, of class Model. + */ + @Test + public void testColorField() { + + //this.squares[x][y].setBackground(color); + //this.squares[x][y].setForeground(colorF); + + System.out.println("colorField"); + int[] pos = {1,1}; + + Program.Settings settings = new Settings(4, "Test", 1, 600, 600); + GUI.game.Game game = new Game(settings, new Program.Game(settings)); + + game.controller.model.build(); + game.controller.model.colorField(1, 1, Color.blue, Color.yellow); + + + assertEquals(Color.blue,game.controller.model.squares[1][1].getBackground()); + assertEquals(Color.yellow, game.controller.model.squares[1][1].getForeground()); + } + /* + 1234 + 1**** 2,2 3,2 2,3 3,3 + 2**** x: 3 y= 2 + 3**** + 4**** + */ + /** + * Test of flagButton method, of class Model. + * + */ + @Test + public void testFlagButton() { + System.out.println("flagButton"); + int[] pos = {1,1}; + + Program.Settings settings = new Settings(4, "Test", 1, 600, 600); + GUI.game.Game game = new Game(settings, new Program.Game(settings)); + + game.controller.model.build(); + game.controller.model.flagButton(pos); + + + + assertEquals("?", game.controller.model.squares[1][1].getText()); + } + +} diff --git a/test/GUI/game/RecursiveNullFinderTest.java b/test/GUI/game/RecursiveNullFinderTest.java new file mode 100644 index 0000000000000000000000000000000000000000..182f24b84b3a85d195beb473904ad709e91c8dc2 --- /dev/null +++ b/test/GUI/game/RecursiveNullFinderTest.java @@ -0,0 +1,151 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package GUI.game; + +import Program.Settings; +import java.util.ArrayList; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author kovax + */ +public class RecursiveNullFinderTest { + + //private + + public RecursiveNullFinderTest() + { + + } + + /* + 1234 + 1**** 2,2 3,2 2,3 3,3 + 2**** x: 3 y= 2 + 3**** + 4**** + */ + /** + * Test of isContains method, of class RecursiveNullFinder. + */ + @Test + public void testIsContains() { + System.out.println("isContains"); + + + ArrayList<int[]> container = new ArrayList<>(); + + int[] a = {1,1}; + int[] b = {1,2}; + int[] c = {2,5}; + int[] d = {5,6}; + + container.add(a); + container.add(b); + container.add(c); + container.add(d); + + int[] position = {1,1}; + + + RecursiveNullFinder instance = new RecursiveNullFinder(1, 1, null, null, null); + Boolean expResult = null; + + Boolean result = instance.isContains(container, position); + assertEquals(true, result); + // TODO review the generated test code and remove the default call to fail. + } + + @Test + public void getNullFieldsAroundTest() + { + RecursiveNullFinder recur; + + ArrayList<int[]> nulls = new ArrayList<>(); + ArrayList<int[]> wasthere; + + Program.Settings settings = new Settings(4, "Test", 1, 600, 600); + GUI.game.Game game = new Game(settings, new Program.Game(settings)); + + + int[] testNullA = {2,2}; + int[] testNullB = {3,2}; + int[] testNullC = {2,3}; + int[] testNullD = {3,3}; + + nulls.add(testNullA); + nulls.add(testNullB); + nulls.add(testNullC); + nulls.add(testNullD); + + wasthere = new ArrayList<>(); + + recur = new RecursiveNullFinder(3, 2, nulls, wasthere, game.controller); + + + System.out.println("RecursiveNullFinderTest"); + ArrayList<int[]> result = recur.getNullFieldAround(); + + ArrayList<int[]> expected = new ArrayList<>(); + + + expected.add(testNullA); + expected.add(testNullB); + expected.add(testNullC); + expected.add(testNullD); + + assertArrayEquals(expected.get(1), result.get(1)); + + + + } + /** + * Test of addUnique method, of class RecursiveNullFinder. + */ + @Test + public void testAddUnique() { + System.out.println("addUnique"); + ArrayList<int[]> to = new ArrayList<>(); + + int[] a = {1,1}; + int[] b = {1,2}; + int[] c = {2,5}; + int[] d = {5,6}; + + + int[] add1 = {1,2}; + int[] add2 = {1,3}; + + to.add(a); + to.add(b); + to.add(c); + to.add(d); + + RecursiveNullFinder instance = new RecursiveNullFinder(1, 1, null, null, null); + + + ArrayList<int[]> expResult = new ArrayList<>(); + expResult.add(a); + expResult.add(b); + expResult.add(c); + expResult.add(d); + expResult.add(add2); + + + ArrayList<int[]> result = instance.addUnique(to, add1); + result = instance.addUnique(result, add2); + + + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + } + +}