Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 1dd17e0d683ef79b4bb6872bbf359d7f > files > 769

qt4-doc-4.8.7-26.2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- advtutorial.qdoc -->
  <title>Qt 4.8: QML Advanced Tutorial 3 - Implementing the Game Logic</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <div class="breadcrumb toolblock">
            <ul>
              <li class="first"><a href="index.html">Home</a></li>
              <!--  Breadcrumbs go here -->
<li><a href="all-examples.html">Examples</a></li>
<li>QML Examples &amp; Demos</li>
<li>QML Advanced Tutorial 3 - Implementing the Game Logic</li>
            </ul>
          </div>
          <div class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></li>
            </ul>
        </div>
        </div>
        <div class="content mainContent">
  <link rel="prev" href="declarative-tutorials-samegame-samegame2.html" />
  <link rel="next" href="declarative-tutorials-samegame-samegame4.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="declarative-tutorials-samegame-samegame2.html">QML Advanced Tutorial 2 - Populating the Game Canvas</a>
<a class="nextPage" href="declarative-tutorials-samegame-samegame4.html">QML Advanced Tutorial 4 - Finishing Touches</a>
</p><p/>
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level2"><a href="#making-a-playable-game">Making a playable game</a></li>
<li class="level3"><a href="#enabling-mouse-click-interaction">Enabling mouse click interaction</a></li>
<li class="level3"><a href="#updating-the-score">Updating the score</a></li>
<li class="level3"><a href="#a-dash-of-color">A dash of color</a></li>
<li class="level2"><a href="#a-working-game">A working game</a></li>
</ul>
</div>
<h1 class="title">QML Advanced Tutorial 3 - Implementing the Game Logic</h1>
<span class="subtitle"></span>
<!-- $$$declarative/tutorials/samegame/samegame3-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="declarative-tutorials-samegame-samegame3-block-qml.html">declarative/tutorials/samegame/samegame3/Block.qml</a></li>
<li><a href="declarative-tutorials-samegame-samegame3-button-qml.html">declarative/tutorials/samegame/samegame3/Button.qml</a></li>
<li><a href="declarative-tutorials-samegame-samegame3-dialog-qml.html">declarative/tutorials/samegame/samegame3/Dialog.qml</a></li>
<li><a href="declarative-tutorials-samegame-samegame3-samegame-js.html">declarative/tutorials/samegame/samegame3/samegame.js</a></li>
<li><a href="declarative-tutorials-samegame-samegame3-samegame-qml.html">declarative/tutorials/samegame/samegame3/samegame.qml</a></li>
<li><a href="declarative-tutorials-samegame-samegame3-samegame3-qmlproject.html">declarative/tutorials/samegame/samegame3/samegame3.qmlproject</a></li>
</ul>
<a name="making-a-playable-game"></a>
<h3>Making a playable game</h3>
<p>Now that we have all the game components, we can add the game logic that dictates how a player interacts with the blocks and plays the game until it is won or lost.</p>
<p>To do this, we have added the following functions to <tt>samegame.js</tt>:</p>
<ul>
<li><tt>handleClick(x,y)</tt></li>
<li><tt>floodFill(xIdx,yIdx,type)</tt></li>
<li><tt>shuffleDown()</tt></li>
<li><tt>victoryCheck()</tt></li>
<li><tt>floodMoveCheck(xIdx, yIdx, type)</tt></li>
</ul>
<p>As this is a tutorial about QML, not game design, we will only discuss <tt>handleClick()</tt> and <tt>victoryCheck()</tt> below since they interface directly with the QML elements. Note that although the game logic here is written in JavaScript, it could have been written in C++ and then exposed to QML.</p>
<a name="enabling-mouse-click-interaction"></a>
<h4>Enabling mouse click interaction</h4>
<p>To make it easier for the JavaScript code to interface with the QML elements, we have added an Item called <tt>gameCanvas</tt> to <tt>samegame.qml</tt>. It replaces the background as the item which contains the blocks. It also accepts mouse input from the user. Here is the item code:</p>
<pre class="qml">         <span class="type"><a href="qml-item.html">Item</a></span> {
             <span class="name">id</span>: <span class="name">gameCanvas</span>

             property <span class="type">int</span> <span class="name">score</span>: <span class="number">0</span>
             property <span class="type">int</span> <span class="name">blockSize</span>: <span class="number">40</span>

             <span class="name">width</span>: <span class="name">parent</span>.<span class="name">width</span> <span class="operator">-</span> (<span class="name">parent</span>.<span class="name">width</span> <span class="operator">%</span> <span class="name">blockSize</span>)
             <span class="name">height</span>: <span class="name">parent</span>.<span class="name">height</span> <span class="operator">-</span> (<span class="name">parent</span>.<span class="name">height</span> <span class="operator">%</span> <span class="name">blockSize</span>)
             <span class="name">anchors</span>.centerIn: <span class="name">parent</span>

             <span class="type"><a href="qml-mousearea.html">MouseArea</a></span> {
                 <span class="name">anchors</span>.fill: <span class="name">parent</span>
                 <span class="name">onClicked</span>: <span class="name">SameGame</span>.<span class="name">handleClick</span>(<span class="name">mouse</span>.<span class="name">x</span>, <span class="name">mouse</span>.<span class="name">y</span>)
             }
         }</pre>
<p>The <tt>gameCanvas</tt> item is the exact size of the board, and has a <tt>score</tt> property and a <a href="qml-mousearea.html">MouseArea</a> to handle mouse clicks. The blocks are now created as its children, and its dimensions are used to determine the board size so that the application scales to the available screen size. Since its size is bound to a multiple of <tt>blockSize</tt>, <tt>blockSize</tt> was moved out of <tt>samegame.js</tt> and into <tt>samegame.qml</tt> as a QML property. Note that it can still be accessed from the script.</p>
<p>When clicked, the <a href="qml-mousearea.html">MouseArea</a> calls <tt>handleClick()</tt> in <tt>samegame.js</tt>, which determines whether the player's click should cause any blocks to be removed, and updates <tt>gameCanvas.score</tt> with the current score if necessary. Here is the <tt>handleClick()</tt> function:</p>
<pre class="js"> <span class="keyword">function</span> <span class="name">handleClick</span>(<span class="name">xPos</span>, yPos) {
     var <span class="name">column</span> = <span class="name">Math</span>.<span class="name">floor</span>(<span class="name">xPos</span> <span class="operator">/</span> <span class="name">gameCanvas</span>.<span class="name">blockSize</span>);
     var <span class="name">row</span> = <span class="name">Math</span>.<span class="name">floor</span>(<span class="name">yPos</span> <span class="operator">/</span> <span class="name">gameCanvas</span>.<span class="name">blockSize</span>);
     <span class="keyword">if</span> (<span class="name">column</span> <span class="operator">&gt;=</span> <span class="name">maxColumn</span> <span class="operator">||</span> <span class="name">column</span> <span class="operator">&lt;</span> <span class="number">0</span> <span class="operator">||</span> <span class="name">row</span> <span class="operator">&gt;=</span> <span class="name">maxRow</span> <span class="operator">||</span> <span class="name">row</span> <span class="operator">&lt;</span> <span class="number">0</span>)
         <span class="keyword">return</span>;
     <span class="keyword">if</span> (<span class="name">board</span>[<span class="name">index</span>(<span class="name">column</span>, <span class="name">row</span>)] <span class="operator">==</span> <span class="number">null</span>)
         <span class="keyword">return</span>;
     <span class="comment">//If it's a valid block, remove it and all connected (does nothing if it's not connected)</span>
     <span class="name">floodFill</span>(<span class="name">column</span>, <span class="name">row</span>, -<span class="number">1</span>);
     <span class="keyword">if</span> (<span class="name">fillFound</span> <span class="operator">&lt;=</span> <span class="number">0</span>)
         <span class="keyword">return</span>;
     <span class="name">gameCanvas</span>.<span class="name">score</span> <span class="operator">+=</span> (<span class="name">fillFound</span> <span class="operator">-</span> <span class="number">1</span>) <span class="operator">*</span> (<span class="name">fillFound</span> <span class="operator">-</span> <span class="number">1</span>);
     <span class="name">shuffleDown</span>();
     <span class="name">victoryCheck</span>();
 }</pre>
<p>Note that if <tt>score</tt> was a global variable in the <tt>samegame.js</tt> file you would not be able to bind to it. You can only bind to QML properties.</p>
<a name="updating-the-score"></a>
<h4>Updating the score</h4>
<p>When the player clicks a block and triggers <tt>handleClick()</tt>, <tt>handleClick()</tt> also calls <tt>victoryCheck()</tt> to update the score and to check whether the player has completed the game. Here is the <tt>victoryCheck()</tt> code:</p>
<pre class="js"> <span class="keyword">function</span> <span class="name">victoryCheck</span>() {
     <span class="comment">//Award bonus points if no blocks left</span>
     var <span class="name">deservesBonus</span> = <span class="number">true</span>;
     <span class="keyword">for</span> (<span class="keyword">var</span> <span class="name">column</span> = <span class="name">maxColumn</span> <span class="operator">-</span> <span class="number">1</span>; <span class="name">column</span> <span class="operator">&gt;=</span> <span class="number">0</span>; column--)
         <span class="keyword">if</span> (<span class="name">board</span>[<span class="name">index</span>(<span class="name">column</span>, <span class="name">maxRow</span> <span class="operator">-</span> <span class="number">1</span>)] <span class="operator">!=</span> <span class="number">null</span>)
         <span class="name">deservesBonus</span> <span class="operator">=</span> <span class="number">false</span>;
     <span class="keyword">if</span> (<span class="name">deservesBonus</span>)
         <span class="name">gameCanvas</span>.<span class="name">score</span> <span class="operator">+=</span> <span class="number">500</span>;

     <span class="comment">//Check whether game has finished</span>
     <span class="keyword">if</span> (<span class="name">deservesBonus</span> <span class="operator">||</span> !(<span class="name">floodMoveCheck</span>(<span class="number">0</span>, <span class="name">maxRow</span> <span class="operator">-</span> <span class="number">1</span>, -<span class="number">1</span>)))
         <span class="name">dialog</span>.<span class="name">show</span>(<span class="string">&quot;Game Over. Your score is &quot;</span> <span class="operator">+</span> <span class="name">gameCanvas</span>.<span class="name">score</span>);
 }</pre>
<p>This updates the <tt>gameCanvas.score</tt> value and displays a &quot;Game Over&quot; dialog if the game is finished.</p>
<p>The Game Over dialog is created using a <tt>Dialog</tt> element that is defined in <tt>Dialog.qml</tt>. Here is the <tt>Dialog.qml</tt> code. Notice how it is designed to be usable imperatively from the script file, via the functions and signals:</p>
<pre class="qml"> import QtQuick 1.0

 <span class="type"><a href="qml-rectangle.html">Rectangle</a></span> {
     <span class="name">id</span>: <span class="name">container</span>

     <span class="keyword">function</span> <span class="name">show</span>(<span class="name">text</span>) {
         <span class="name">dialogText</span>.<span class="name">text</span> <span class="operator">=</span> <span class="name">text</span>;
         <span class="name">container</span>.<span class="name">opacity</span> <span class="operator">=</span> <span class="number">1</span>;
     }

     <span class="keyword">function</span> <span class="name">hide</span>() {
         <span class="name">container</span>.<span class="name">opacity</span> <span class="operator">=</span> <span class="number">0</span>;
     }

     <span class="name">width</span>: <span class="name">dialogText</span>.<span class="name">width</span> <span class="operator">+</span> <span class="number">20</span>
     <span class="name">height</span>: <span class="name">dialogText</span>.<span class="name">height</span> <span class="operator">+</span> <span class="number">20</span>
     <span class="name">opacity</span>: <span class="number">0</span>

     <span class="type"><a href="qml-text.html">Text</a></span> {
         <span class="name">id</span>: <span class="name">dialogText</span>
         <span class="name">anchors</span>.centerIn: <span class="name">parent</span>
         <span class="name">text</span>: <span class="string">&quot;&quot;</span>
     }

     <span class="type"><a href="qml-mousearea.html">MouseArea</a></span> {
         <span class="name">anchors</span>.fill: <span class="name">parent</span>
         <span class="name">onClicked</span>: <span class="name">hide</span>();
     }
 }</pre>
<p>And this is how it is used in the main <tt>samegame.qml</tt> file:</p>
<pre class="qml">     <span class="type">Dialog</span> {
         <span class="name">id</span>: <span class="name">dialog</span>
         <span class="name">anchors</span>.centerIn: <span class="name">parent</span>
         <span class="name">z</span>: <span class="number">100</span>
     }</pre>
<p>We give the dialog a <a href="qml-item.html#z-prop">z</a> value of 100 to ensure it is displayed on top of our other components. The default <tt>z</tt> value for an item is 0.</p>
<a name="a-dash-of-color"></a>
<h4>A dash of color</h4>
<p>It's not much fun to play Same Game if all the blocks are the same color, so we've modified the <tt>createBlock()</tt> function in <tt>samegame.js</tt> to randomly create a different type of block (for either red, green or blue) each time it is called. <tt>Block.qml</tt> has also changed so that each block contains a different image depending on its type:</p>
<pre class="qml"> import QtQuick 1.0

 <span class="type"><a href="qml-item.html">Item</a></span> {
     <span class="name">id</span>: <span class="name">block</span>

     property <span class="type">int</span> <span class="name">type</span>: <span class="number">0</span>

     <span class="type"><a href="qml-image.html">Image</a></span> {
         <span class="name">id</span>: <span class="name">img</span>

         <span class="name">anchors</span>.fill: <span class="name">parent</span>
         <span class="name">source</span>: {
             <span class="keyword">if</span> (<span class="name">type</span> <span class="operator">==</span> <span class="number">0</span>)
                 <span class="keyword">return</span> <span class="string">&quot;../shared/pics/redStone.png&quot;</span>;
             else <span class="keyword">if</span> (<span class="name">type</span> <span class="operator">==</span> <span class="number">1</span>)
                 <span class="keyword">return</span> <span class="string">&quot;../shared/pics/blueStone.png&quot;</span>;
             else
                 <span class="keyword">return</span> <span class="string">&quot;../shared/pics/greenStone.png&quot;</span>;
         }
     }
 }</pre>
<a name="a-working-game"></a>
<h3>A working game</h3>
<p>Now we now have a working game! The blocks can be clicked, the player can score, and the game can end (and then you can start a new one). Here is a screenshot of what has been accomplished so far:</p>
<p class="centerAlign"><img src="images/declarative-adv-tutorial3.png" alt="" /></p><p>This is what <tt>samegame.qml</tt> looks like now:</p>
<pre class="qml"> import QtQuick 1.0
 import &quot;samegame.js&quot; as SameGame

 <span class="type"><a href="qml-rectangle.html">Rectangle</a></span> {
     <span class="name">id</span>: <span class="name">screen</span>

     <span class="name">width</span>: <span class="number">490</span>; <span class="name">height</span>: <span class="number">720</span>

     <span class="type"><a href="qml-systempalette.html">SystemPalette</a></span> { <span class="name">id</span>: <span class="name">activePalette</span> }

     <span class="type"><a href="qml-item.html">Item</a></span> {
         <span class="name">width</span>: <span class="name">parent</span>.<span class="name">width</span>
         <span class="type">anchors</span> { <span class="name">top</span>: <span class="name">parent</span>.<span class="name">top</span>; <span class="name">bottom</span>: <span class="name">toolBar</span>.<span class="name">top</span> }

         <span class="type"><a href="qml-image.html">Image</a></span> {
             <span class="name">id</span>: <span class="name">background</span>
             <span class="name">anchors</span>.fill: <span class="name">parent</span>
             <span class="name">source</span>: <span class="string">&quot;../shared/pics/background.jpg&quot;</span>
             <span class="name">fillMode</span>: <span class="name">Image</span>.<span class="name">PreserveAspectCrop</span>
         }

         <span class="type"><a href="qml-item.html">Item</a></span> {
             <span class="name">id</span>: <span class="name">gameCanvas</span>

             property <span class="type">int</span> <span class="name">score</span>: <span class="number">0</span>
             property <span class="type">int</span> <span class="name">blockSize</span>: <span class="number">40</span>

             <span class="name">width</span>: <span class="name">parent</span>.<span class="name">width</span> <span class="operator">-</span> (<span class="name">parent</span>.<span class="name">width</span> <span class="operator">%</span> <span class="name">blockSize</span>)
             <span class="name">height</span>: <span class="name">parent</span>.<span class="name">height</span> <span class="operator">-</span> (<span class="name">parent</span>.<span class="name">height</span> <span class="operator">%</span> <span class="name">blockSize</span>)
             <span class="name">anchors</span>.centerIn: <span class="name">parent</span>

             <span class="type"><a href="qml-mousearea.html">MouseArea</a></span> {
                 <span class="name">anchors</span>.fill: <span class="name">parent</span>
                 <span class="name">onClicked</span>: <span class="name">SameGame</span>.<span class="name">handleClick</span>(<span class="name">mouse</span>.<span class="name">x</span>, <span class="name">mouse</span>.<span class="name">y</span>)
             }
         }
     }

     <span class="type">Dialog</span> {
         <span class="name">id</span>: <span class="name">dialog</span>
         <span class="name">anchors</span>.centerIn: <span class="name">parent</span>
         <span class="name">z</span>: <span class="number">100</span>
     }

     <span class="type"><a href="qml-rectangle.html">Rectangle</a></span> {
         <span class="name">id</span>: <span class="name">toolBar</span>
         <span class="name">width</span>: <span class="name">parent</span>.<span class="name">width</span>; <span class="name">height</span>: <span class="number">30</span>
         <span class="name">color</span>: <span class="name">activePalette</span>.<span class="name">window</span>
         <span class="name">anchors</span>.bottom: <span class="name">screen</span>.<span class="name">bottom</span>

         <span class="type">Button</span> {
             <span class="type">anchors</span> { <span class="name">left</span>: <span class="name">parent</span>.<span class="name">left</span>; <span class="name">verticalCenter</span>: <span class="name">parent</span>.<span class="name">verticalCenter</span> }
             <span class="name">text</span>: <span class="string">&quot;New Game&quot;</span>
             <span class="name">onClicked</span>: <span class="name">SameGame</span>.<span class="name">startNewGame</span>()
         }

         <span class="type"><a href="qml-text.html">Text</a></span> {
             <span class="name">id</span>: <span class="name">score</span>
             <span class="type">anchors</span> { <span class="name">right</span>: <span class="name">parent</span>.<span class="name">right</span>; <span class="name">verticalCenter</span>: <span class="name">parent</span>.<span class="name">verticalCenter</span> }
             <span class="name">text</span>: <span class="string">&quot;Score: Who knows?&quot;</span>
         }
     }
 }</pre>
<p>The game works, but it's a little boring right now. Where are the smooth animated transitions? Where are the high scores? If you were a QML expert you could have written these in the first iteration, but in this tutorial they've been saved until the next chapter - where your application becomes alive!</p>
</div>
<!-- @@@declarative/tutorials/samegame/samegame3 -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="declarative-tutorials-samegame-samegame2.html">QML Advanced Tutorial 2 - Populating the Game Canvas</a>
<a class="nextPage" href="declarative-tutorials-samegame-samegame4.html">QML Advanced Tutorial 4 - Finishing Touches</a>
</p>
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
      Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Qt and respective logos are trademarks of The Qt Company Ltd 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
  </div>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>