Updating to real release of dlvkbrwsr
authorJaroslav Tulach <jtulach@netbeans.org>
Sun, 16 Mar 2014 08:30:22 +0100
changeset 107f8f222243d3c
parent 106 09a0a7d7a960
child 108 ceebcfdcc742
Updating to real release of dlvkbrwsr
minesweeper/AndroidManifest.xml
minesweeper/pom.xml
minesweeper/src/main/java/org/apidesign/demo/minesweeper/MinesModel.java
     1.1 --- a/minesweeper/AndroidManifest.xml	Sat Mar 15 21:03:15 2014 +0100
     1.2 +++ b/minesweeper/AndroidManifest.xml	Sun Mar 16 08:30:22 2014 +0100
     1.3 @@ -39,7 +39,7 @@
     1.4          android:icon="@drawable/ic_launcher"
     1.5          android:label="@string/app_name"
     1.6          android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
     1.7 -        <activity android:name="org.apidesign.html.dlvkbrwsr.DlvkBrwsr" 
     1.8 +        <activity android:name="org.apidesign.html.brwsr.DlvkBrwsr" 
     1.9                    android:configChanges="orientation|screenSize">
    1.10              <intent-filter>
    1.11                  <action android:name="android.intent.action.MAIN" />
     2.1 --- a/minesweeper/pom.xml	Sat Mar 15 21:03:15 2014 +0100
     2.2 +++ b/minesweeper/pom.xml	Sun Mar 16 08:30:22 2014 +0100
     2.3 @@ -206,11 +206,6 @@
     2.4        </profile>
     2.5        <profile>
     2.6            <id>dlvkbrwsr</id>
     2.7 -          <activation>
     2.8 -              <property>
     2.9 -                  <name>android.sdk.path</name>
    2.10 -              </property>
    2.11 -          </activation>
    2.12            <properties>
    2.13                <platform.version>4.1.1.4</platform.version>
    2.14                <android.plugin.version>3.7.0</android.plugin.version>
    2.15 @@ -224,6 +219,12 @@
    2.16                    <scope>provided</scope>
    2.17                </dependency>
    2.18                <dependency>
    2.19 +                  <groupId>org.apidesign.brwsr</groupId>
    2.20 +                  <artifactId>dlvkbrwsr</artifactId>
    2.21 +                  <version>0.5</version>
    2.22 +                  <type>jar</type>
    2.23 +              </dependency>
    2.24 +              <dependency>
    2.25                    <groupId>org.netbeans.html</groupId>
    2.26                    <artifactId>ko-ws-tyrus</artifactId>
    2.27                    <version>${net.java.html.version}</version>
    2.28 @@ -234,12 +235,6 @@
    2.29                        </exclusion>
    2.30                    </exclusions>
    2.31                </dependency>
    2.32 -              <dependency>
    2.33 -                  <groupId>org.apidesign.html</groupId>
    2.34 -                  <artifactId>dlvkbrwsr</artifactId>
    2.35 -                  <version>0.1-SNAPSHOT</version>
    2.36 -                  <type>jar</type>
    2.37 -              </dependency>
    2.38            </dependencies>
    2.39            <build>
    2.40                <plugins>
     3.1 --- a/minesweeper/src/main/java/org/apidesign/demo/minesweeper/MinesModel.java	Sat Mar 15 21:03:15 2014 +0100
     3.2 +++ b/minesweeper/src/main/java/org/apidesign/demo/minesweeper/MinesModel.java	Sun Mar 16 08:30:22 2014 +0100
     3.3 @@ -111,13 +111,23 @@
     3.4      }
     3.5      
     3.6      @ModelOperation static void init(Mines model, int width, int height, int mines) {
     3.7 -        List<Row> rows = new ArrayList<Row>(height);
     3.8 -        for (int y = 0; y < height; y++) {
     3.9 -            Square[] columns = new Square[width];
    3.10 -            for (int x = 0; x < width; x++) {
    3.11 -                columns[x] = new Square(SquareType.UNKNOWN, false);
    3.12 +        List<Row> rows = model.getRows();
    3.13 +        if (rows.size() != height || rows.get(0).getColumns().size() != width) {
    3.14 +            rows = new ArrayList<Row>(height);
    3.15 +            for (int y = 0; y < height; y++) {
    3.16 +                Square[] columns = new Square[width];
    3.17 +                for (int x = 0; x < width; x++) {
    3.18 +                    columns[x] = new Square(SquareType.UNKNOWN, false);
    3.19 +                }
    3.20 +                rows.add(new Row(columns));
    3.21              }
    3.22 -            rows.add(new Row(columns));
    3.23 +        } else {
    3.24 +            for (Row row : rows) {
    3.25 +                for (Square sq : row.getColumns()) {
    3.26 +                    sq.setState(SquareType.UNKNOWN);
    3.27 +                    sq.setMine(false);
    3.28 +                }
    3.29 +            }
    3.30          }
    3.31          
    3.32          Random r = new Random();
    3.33 @@ -133,8 +143,10 @@
    3.34          }
    3.35  
    3.36          model.setState(GameState.IN_PROGRESS);
    3.37 -        model.getRows().clear();
    3.38 -        model.getRows().addAll(rows);
    3.39 +        if (rows != model.getRows()) {
    3.40 +            model.getRows().clear();
    3.41 +            model.getRows().addAll(rows);
    3.42 +        }
    3.43      }
    3.44      
    3.45      @ModelOperation static void computeMines(Mines model) {
    3.46 @@ -233,6 +245,7 @@
    3.47                  } else {
    3.48                      TOUCH.play();
    3.49                      expandKnown(model, data);
    3.50 +                    model.computeMines();
    3.51                  }
    3.52              break;
    3.53          }
    3.54 @@ -260,9 +273,18 @@
    3.55          }
    3.56          final Square sq = columns.get(x);
    3.57          if (sq.getState() == SquareType.UNKNOWN) {
    3.58 -            sq.setState(SquareType.N_0);
    3.59 -            model.computeMines();
    3.60 -            if (sq.getState() == SquareType.N_0) {
    3.61 +            int around = 
    3.62 +                minesAt(model, x - 1, y - 1) +
    3.63 +                minesAt(model, x - 1, y) +
    3.64 +                minesAt(model, x - 1, y + 1) +
    3.65 +                minesAt(model, x , y - 1) +
    3.66 +                minesAt(model, x, y + 1) +
    3.67 +                minesAt(model, x + 1, y - 1) +
    3.68 +                minesAt(model, x + 1, y) +
    3.69 +                minesAt(model, x + 1, y + 1);
    3.70 +            final SquareType t = SquareType.valueOf("N_" + around);
    3.71 +            sq.setState(t);
    3.72 +            if (t == SquareType.N_0) {
    3.73                  expandKnown(model, x - 1, y - 1);
    3.74                  expandKnown(model, x - 1, y);
    3.75                  expandKnown(model, x - 1, y + 1);
    3.76 @@ -274,4 +296,17 @@
    3.77              }
    3.78          }
    3.79      }
    3.80 +    
    3.81 +    private static int minesAt(Mines model, int x, int y) {
    3.82 +        if (y < 0 || y >= model.getRows().size()) {
    3.83 +            return 0;
    3.84 +        }
    3.85 +        final List<Square> columns = model.getRows().get(y).getColumns();
    3.86 +        if (x < 0 || x >= columns.size()) {
    3.87 +            return 0;
    3.88 +        }
    3.89 +        Square sq = columns.get(x);
    3.90 +        return sq.isMine() ? 1 : 0;
    3.91 +    }
    3.92 +    
    3.93  }