# HG changeset patch # User Jaroslav Tulach # Date 1392198442 -3600 # Node ID e69ac983e3f7696e0e5107360bdddde42f21fe11 # Parent 9fcc1e38b4c97658d6e7d0ab4c6774c854d1ea1d# Parent 748db72a7f57866fb1c3fcd11cb1b96f1a01037e Minesweeper seems to be more or less stable (at least in default configuration). Merging in to default branch. diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/AndroidManifest.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/AndroidManifest.xml Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/nbactions-bck2brwsr.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/nbactions-bck2brwsr.xml Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,39 @@ + + + + + run + + package + bck2brwsr:brwsr + + + true + NONE + + + diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/nbactions-dlvkbrwsr.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/nbactions-dlvkbrwsr.xml Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,36 @@ + + + + + run + + package + android:deploy + android:run + + + diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/nbactions-fxbrwsr.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/nbactions-fxbrwsr.xml Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,45 @@ + + + + + run + + process-classes + exec:java + + + + debug + + process-classes + exec:java + + + maven + + + diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/nbactions.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/nbactions.xml Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,45 @@ + + + + + run + + process-classes + exec:java + + + + debug + + process-classes + exec:java + + + maven + + + diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/pom.xml Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,303 @@ + + + 4.0.0 + + org.apidesign.demo + minesweeper + 1.0-SNAPSHOT + jar + + demo + org.apidesign.html + 1.0-SNAPSHOT + + + Mine Sweeper + + + UTF-8 + pages/index.html + org.apidesign.demo.minesweeper.Main + none + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + ${project.mainclass} + true + lib/ + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + + browser.rootdir + ${basedir}/src/main/webapp/ + + + ${project.mainclass} + + + + + + + org.netbeans.html + net.java.html.json + ${net.java.html.version} + + + org.netbeans.html + net.java.html.boot + ${net.java.html.version} + + + org.netbeans.html + net.java.html.sound + ${net.java.html.version} + + + org.netbeans.html + ko4j + ${net.java.html.version} + + + org.testng + testng + 6.7 + test + + + + + fxbrwsr + + true + + + + + maven-assembly-plugin + 2.4 + + + distro-assembly + package + + single + + + + src/main/assembly/html.java.net.xml + + + + + + + + + + org.netbeans.html + net.java.html.boot.fx + ${net.java.html.version} + runtime + + + + + bck2brwsr + + + brwsr + bck2brwsr + + + + + + org.apidesign.bck2brwsr + bck2brwsr-maven-plugin + ${bck2brwsr.version} + + + + brwsr + + + + + ${basedir}/src/main/webapp/ + ${brwsr.startpage} + + + + org.apache.maven.plugins + maven-compiler-plugin + + + netbeans.ignore.jdk.bootclasspath + + + + + maven-assembly-plugin + 2.4 + + + distro-assembly + package + + single + + + + src/main/assembly/bck2brwsr.xml + + + + + + + + + + org.apidesign.bck2brwsr + emul + ${bck2brwsr.version} + rt + + + org.apidesign.bck2brwsr + ko-bck2brwsr + ${bck2brwsr.version} + runtime + + + org.apidesign.bck2brwsr + vm4brwsr + js + zip + ${bck2brwsr.version} + provided + + + + + dlvkbrwsr + + + android.sdk.path + + + + 4.1.1.4 + 3.7.0 + false + + + + com.google.android + android + ${platform.version} + provided + + + org.netbeans.html + ko-ws-tyrus + ${net.java.html.version} + + + org.json-osgi + de.twentyeleven.skysail + + + + + org.apidesign.html + dlvkbrwsr + 0.1-SNAPSHOT + jar + + + + + + com.jayway.maven.plugins.android.generation2 + android-maven-plugin + ${android.plugin.version} + true + + apk + false + debug + src/main/webapp + + 16 + + + + services/org.apidesign.** + + + ${project.build.directory}/${project.build.finalName}.apk + + + + apk + + apk + dex + + + + + + org.apache.maven.plugins + maven-install-plugin + 2.5.1 + + ${project.groupId} + ${project.artifactId} + ${project.version} + ${project.build.directory}/${project.build.finalName}.apk + apk + true + + + + install-apk + install + + install-file + + + + + + + + + + diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/res/drawable-hdpi/ic_launcher.png Binary file minesweeper/res/drawable-hdpi/ic_launcher.png has changed diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/res/drawable-mdpi/ic_launcher.png Binary file minesweeper/res/drawable-mdpi/ic_launcher.png has changed diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/res/drawable-xhdpi/ic_launcher.png Binary file minesweeper/res/drawable-xhdpi/ic_launcher.png has changed diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/res/drawable-xxhdpi/ic_launcher.png Binary file minesweeper/res/drawable-xxhdpi/ic_launcher.png has changed diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/res/layout/activity_main.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/res/layout/activity_main.xml Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,40 @@ + + + + + + + + + + + +
+ +
+
+

HTML/Java Technology Demo

+ +

At first sight this is an old good minesweeper + game. At closer look, this is a demo of a revolutionary + technology that allows you to use Java + to code your application logic and present it using + HTML on any device capable of rendering + modern HTML5 browser. +

+

Visit Project Page! +

+
+
+ +
+
+
+

Minesweeper

+

+ At the end this is a minesweeper + game and you can of course play it. Discover + all fields that don't contain a mine. + Touch a field to find out if there is + a mine or not. A number on a field indicates + how many mines is in the eight surrounding + fields. +

+

Play »

+
+
+

Documentation

+

+ In case you want to write application like + this (e.g. use Java and HTML) + you can learn more about the libraries that + make that possible. Follow this link to + our documentation. +

+

Read more »

+
+
+

Run in a Browser

+

+ While primarily this technology runs on a desktop + or as a table or phone application, it is possible + to execute the same unchanged code in a browser + as well. To do so, one needs a bck2brwsr + virtual machine. +

+

Learn more »

+
+
+ + + + + + diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/src/main/webapp/pages/mines-phone-large.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/src/main/webapp/pages/mines-phone-large.css Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,53 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +table.field td { + padding: 4px; + width: 28px; + height: 28px; + font-size: 2em; +} +h1 { + font-size: 15px; +} +.col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 { + float: none; + } +.col-md-6 { + width: 100%; +} +.col-md-5 { + width: 100%; +} +.col-md-4 { + width: 100%; +} +.col-md-3 { + width: 100%; +} +.col-md-2 { + width: 100%; +} +.col-md-1 { + width: 100%; +} diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/src/main/webapp/pages/mines-phone-small.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/src/main/webapp/pages/mines-phone-small.css Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,53 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +table.field td { + padding: 4px; + width: 18px; + height: 18px; + font-size: 1.5em; +} +h1 { + font-size: 12px; +} +.col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 { + float: none; + } +.col-md-6 { + width: 100%; +} +.col-md-5 { + width: 100%; +} +.col-md-4 { + width: 100%; +} +.col-md-3 { + width: 100%; +} +.col-md-2 { + width: 100%; +} +.col-md-1 { + width: 100%; +} diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/src/main/webapp/pages/mines-phone-smaller.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/src/main/webapp/pages/mines-phone-smaller.css Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,54 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +table.field td { + padding: 2px; + width: 10px; + height: 10px; + line-height: 10px; + font-size: 0.8em; +} +h1 { + font-size: 8px; +} +.col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 { + float: none; + } +.col-md-6 { + width: 100%; +} +.col-md-5 { + width: 100%; +} +.col-md-4 { + width: 100%; +} +.col-md-3 { + width: 100%; +} +.col-md-2 { + width: 100%; +} +.col-md-1 { + width: 100%; +} diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/src/main/webapp/pages/mines-tablet-large.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/src/main/webapp/pages/mines-tablet-large.css Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,54 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 { + float: left; + } +.col-md-6 { + width: 50%; +} +.col-md-5 { + width: 41.66666666666667%; +} +.col-md-4 { + width: 33.33333333333333%; +} +.col-md-3 { + width: 25%; +} +.col-md-2 { + width: 16.666666666666664%; +} +.col-md-1 { + width: 8.333333333333332%; +} + + table.field td { + padding: 8px; + width: 42px; + height: 42px; + font-size: 3em; +} +h1 { + font-size: 34px; +} \ No newline at end of file diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/src/main/webapp/pages/mines-tablet-small.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/src/main/webapp/pages/mines-tablet-small.css Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,53 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +table.field td { + padding: 6px; + width: 34px; + height: 34px; + font-size: 2.4em; +} +h1 { + font-size: 18px; +} + .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 { + float: left; + } +.col-md-6 { + width: 50%; +} +.col-md-5 { + width: 50%; +} +.col-md-4 { + width: 50%; +} +.col-md-3 { + width: 100%; +} +.col-md-2 { + width: 100%; +} +.col-md-1 { + width: 100%; +} diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/src/main/webapp/pages/mines.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/src/main/webapp/pages/mines.css Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,86 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +/** main chess style **/ +#apptitle { + font-size: 20px; +} +.log { + margin-bottom: 10px; +} + +.jumbotron { + background-color: #fafafa; +} + +table.field { +} +table.field td { + border: 1px solid black; + padding:10px; + width: 56px; + height: 56px; + vertical-align: middle; + text-align: center; + font-size:4em; +} + +table.field td.UNKNOWN { + background-color: #D6E4E1; + cursor: pointer; +} +table.field td.EXPLOSION { + background-color: #A31E39; +} +table.field td.DISCOVERED { + background-color: #9DB2B1; +} +.but-orientation { + margin-top:20px; +} +h3.log-h { + border-top:1px solid silver; +} +.badge-status { + display:inline-block; + margin-left:20px; + padding:5px; + font-size:1em; + text-shadow: none; +} +.btn {text-shadow: none;} +.select {line-height: inherit;} +.uneditable-input { + margin-left: 0; + color: black; +} +span.myturn { + display: inline-block; + position:relative; + left:23px; + padding:3px; +} +.whitePiece { + text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; + color: white; +} diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/src/main/webapp/pages/move.mp3 Binary file minesweeper/src/main/webapp/pages/move.mp3 has changed diff -r 9fcc1e38b4c9 -r e69ac983e3f7 minesweeper/src/test/java/org/apidesign/demo/minesweeper/MinesModelTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minesweeper/src/test/java/org/apidesign/demo/minesweeper/MinesModelTest.java Wed Feb 12 10:47:22 2014 +0100 @@ -0,0 +1,108 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.minesweeper; + +import org.apidesign.demo.minesweeper.MinesModel.SquareType; +import static org.testng.Assert.*; +import org.testng.annotations.Test; + +public class MinesModelTest { + @Test public void tenTenTen() { + Mines m = new Mines(); + m.init(10, 10, 10); + + assertEquals(m.getRows().size(), 10, "Ten rows"); + int cnt = 0; + for (Row row : m.getRows()) { + assertEquals(row.getColumns().size(), 10, "Ten columns in each row"); + for (Square square : row.getColumns()) { + if (square.isMine()) { + cnt++; + } + } + } + assertEquals(cnt, 10, "Ten mines"); + } + + @Test public void bombsSet() { + Mines m = new Mines(); + m.init(10, 10, 0); + + set(m, 1, 1, SquareType.UNKNOWN, true); + set(m, 0, 0, SquareType.N_0, false); + set(m, 0, 1, SquareType.N_2, false); + set(m, 0, 2, SquareType.N_3, false); + set(m, 1, 0, SquareType.N_5, false); + set(m, 2, 0, SquareType.N_8, false); + set(m, 3, 0, SquareType.N_2, false); + + m.computeMines(); + + assertSquare(m, 0, 0, SquareType.N_1); + assertSquare(m, 1, 0, SquareType.N_1); + assertSquare(m, 2, 0, SquareType.N_1); + assertSquare(m, 3, 0, SquareType.N_0); + assertSquare(m, 0, 1, SquareType.N_1); + assertSquare(m, 0, 2, SquareType.N_1); + assertSquare(m, 2, 2, SquareType.UNKNOWN); + } + + @Test public void gameIsWonIfAllMinesDiscovered() { + Mines m = new Mines(); + m.init(2, 1, 0); + set(m, 0, 0, SquareType.UNKNOWN, true); + m.computeMines(); + assertEquals(m.getState(), MinesModel.GameState.IN_PROGRESS); + set(m, 1, 0, SquareType.N_0, false); + m.computeMines(); + assertEquals(m.getState(), MinesModel.GameState.WON, "All non-bomb squares discovered"); + } + + @Test public void unhideNeibourghsOfEmptyPieces() { + Mines m = new Mines(); + m.init(3, 3, 0); + set(m, 0, 0, SquareType.UNKNOWN, true); + MinesModel.click(m, m.getRows().get(2).getColumns().get(2)); + + assertSquare(m, 0, 0, SquareType.DISCOVERED); + assertSquare(m, 0, 1, SquareType.N_1); + assertSquare(m, 1, 1, SquareType.N_1); + assertSquare(m, 1, 0, SquareType.N_1); + assertSquare(m, 2, 0, SquareType.N_0); + assertSquare(m, 2, 1, SquareType.N_0); + assertSquare(m, 2, 2, SquareType.N_0); + assertSquare(m, 1, 2, SquareType.N_0); + } + + private static void set(Mines m, int x, int y, SquareType squareType, boolean mine) { + Square sq = m.getRows().get(y).getColumns().get(x); + sq.setState(squareType); + sq.setMine(mine); + } + + private static void assertSquare(Mines m, int x, int y, SquareType t) { + Square sq = m.getRows().get(y).getColumns().get(x); + assertEquals(sq.getState(), t, "Expecting at " + x + ":" + y); + } +} diff -r 9fcc1e38b4c9 -r e69ac983e3f7 pom.xml --- a/pom.xml Wed Feb 12 10:35:21 2014 +0100 +++ b/pom.xml Wed Feb 12 10:47:22 2014 +0100 @@ -20,6 +20,7 @@ chat chess + minesweeper spinningcube words