Showing mine field only conditionally minesweeper
authorJaroslav Tulach <jtulach@netbeans.org>
Sat, 08 Feb 2014 10:07:55 +0100
branchminesweeper
changeset 7655b2e1d3ad2b
parent 75 4eb79fa3434a
child 77 b344caeda33f
Showing mine field only conditionally
minesweeper/src/main/java/org/apidesign/demo/minesweeper/Main.java
minesweeper/src/main/java/org/apidesign/demo/minesweeper/MinesModel.java
minesweeper/src/main/webapp/pages/index.html
     1.1 --- a/minesweeper/src/main/java/org/apidesign/demo/minesweeper/Main.java	Sat Feb 08 09:25:53 2014 +0100
     1.2 +++ b/minesweeper/src/main/java/org/apidesign/demo/minesweeper/Main.java	Sat Feb 08 10:07:55 2014 +0100
     1.3 @@ -44,7 +44,6 @@
     1.4      /** Called when page is ready */
     1.5      public static void onPageLoad(String... args) throws Exception {
     1.6          Mines m = new Mines();
     1.7 -        m.init(10, 10, 10);
     1.8          m.applyBindings();
     1.9      }
    1.10  }
     2.1 --- a/minesweeper/src/main/java/org/apidesign/demo/minesweeper/MinesModel.java	Sat Feb 08 09:25:53 2014 +0100
     2.2 +++ b/minesweeper/src/main/java/org/apidesign/demo/minesweeper/MinesModel.java	Sat Feb 08 10:07:55 2014 +0100
     2.3 @@ -90,6 +90,14 @@
     2.4          }
     2.5      }
     2.6      
     2.7 +    @ComputedProperty static boolean fieldShowing(GameState state) {
     2.8 +        return state != null;
     2.9 +    }
    2.10 +    
    2.11 +    @Function static void showHelp(Mines model) {
    2.12 +        model.setState(null);
    2.13 +    }
    2.14 +    
    2.15      @Function static void smallGame(Mines model) {
    2.16          model.init(5, 5, 5);
    2.17      }
     3.1 --- a/minesweeper/src/main/webapp/pages/index.html	Sat Feb 08 09:25:53 2014 +0100
     3.2 +++ b/minesweeper/src/main/webapp/pages/index.html	Sat Feb 08 10:07:55 2014 +0100
     3.3 @@ -49,27 +49,30 @@
     3.4      <body>
     3.5          <div class="navbar">
     3.6              <div class="navbar-inner">
     3.7 -                <a id="apptitle" class="brand" href="http://html.java.net">Minesweeper</a>
     3.8 +                <a id="apptitle" class="brand" href="#" data-bind="click: showHelp">Minesweeper</a>
     3.9                  <button class="btn btn-default navbar-btn" disabled="true" data-bind="disable: false, click: normalGame">New Game!</button>
    3.10 -                <button class="btn btn-default navbar-btn" disabled="true" data-bind="disable: false, click: giveUp ">Show Mines!</button>
    3.11 +                <button class="btn btn-default navbar-btn" disabled="true" data-bind="disable: !fieldShowing(), click: giveUp ">Show Mines!</button>
    3.12              </div>
    3.13          </div>
    3.14 +        
    3.15  
    3.16 -        <table class="field">
    3.17 -            <tbody>
    3.18 -                <!-- ko foreach: rows -->
    3.19 -                <tr>
    3.20 -                    <!-- ko foreach: columns -->
    3.21 -                    <td data-bind="css: style, click: $parents[1].click" >
    3.22 -                        <div data-bind='html: html'></div>
    3.23 -                    </td>
    3.24 +        <script type="text/html" id="field">
    3.25 +            <table class="field">
    3.26 +                <tbody>
    3.27 +                    <!-- ko foreach: rows -->
    3.28 +                    <tr>
    3.29 +                        <!-- ko foreach: columns -->
    3.30 +                        <td data-bind="css: style, click: $parents[1].click" >
    3.31 +                            <div data-bind='html: html'></div>
    3.32 +                        </td>
    3.33 +                        <!-- /ko -->
    3.34 +                    </tr>
    3.35                      <!-- /ko -->
    3.36 -                </tr>
    3.37 -                <!-- /ko -->
    3.38 -            </tbody>
    3.39 -        </table>
    3.40 +                </tbody>
    3.41 +            </table>
    3.42 +        </script>
    3.43          
    3.44 -        
    3.45 +        <div data-bind="template: { name : 'field', if: fieldShowing }"/>
    3.46          
    3.47          <script type="text/javascript" src="bck2brwsr.js"></script>
    3.48          <script>