diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-04-09 03:05:13 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-04-09 06:02:29 (GMT) |
commit | ec389436a74a7b619924bd47942e92203b1fb213 (patch) | |
tree | 307e550b2e0659cf63998324a903301e94c05d5e /examples/declarative/tutorials/samegame/samegame2 | |
parent | 475abec27948923ae6de74db53b137f19c661601 (diff) | |
download | Qt-ec389436a74a7b619924bd47942e92203b1fb213.zip Qt-ec389436a74a7b619924bd47942e92203b1fb213.tar.gz Qt-ec389436a74a7b619924bd47942e92203b1fb213.tar.bz2 |
Example code style improvements
Diffstat (limited to 'examples/declarative/tutorials/samegame/samegame2')
-rw-r--r-- | examples/declarative/tutorials/samegame/samegame2/Button.qml | 3 | ||||
-rw-r--r-- | examples/declarative/tutorials/samegame/samegame2/samegame.js | 42 |
2 files changed, 23 insertions, 22 deletions
diff --git a/examples/declarative/tutorials/samegame/samegame2/Button.qml b/examples/declarative/tutorials/samegame/samegame2/Button.qml index 04d1d1f..cf4c61b 100644 --- a/examples/declarative/tutorials/samegame/samegame2/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame2/Button.qml @@ -13,7 +13,8 @@ Rectangle { gradient: Gradient { GradientStop { position: 0.0 - color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } + color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } + } GradientStop { position: 1.0; color: activePalette.button } } diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.js b/examples/declarative/tutorials/samegame/samegame2/samegame.js index 3f12561..9809c1d 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.js @@ -2,59 +2,58 @@ var blockSize = 40; var maxColumn = 10; var maxRow = 15; -var maxIndex = maxColumn*maxRow; +var maxIndex = maxColumn * maxRow; var board = new Array(maxIndex); var component; //Index function used instead of a 2D array -function index(column,row) { +function index(column, row) { return column + (row * maxColumn); } -function startNewGame() -{ +function startNewGame() { //Delete blocks from previous game - for(var i = 0; i<maxIndex; i++){ - if(board[i] != null) + for (var i = 0; i < maxIndex; i++) { + if (board[i] != null) board[i].destroy(); } //Calculate board size - maxColumn = Math.floor(background.width/blockSize); - maxRow = Math.floor(background.height/blockSize); - maxIndex = maxRow*maxColumn; + maxColumn = Math.floor(background.width / blockSize); + maxRow = Math.floor(background.height / blockSize); + maxIndex = maxRow * maxColumn; //Initialize Board board = new Array(maxIndex); - for(var column=0; column<maxColumn; column++){ - for(var row=0; row<maxRow; row++){ - board[index(column,row)] = null; - createBlock(column,row); + for (var column = 0; column < maxColumn; column++) { + for (var row = 0; row < maxRow; row++) { + board[index(column, row)] = null; + createBlock(column, row); } } } -function createBlock(column,row){ - if(component==null) +function createBlock(column, row) { + if (component == null) component = createComponent("Block.qml"); // Note that if Block.qml was not a local file, component.isReady would be // false and we should wait for the component's statusChanged() signal to // know when the file is downloaded and fully loaded before calling createObject(). - if(component.isReady){ + if (component.isReady) { var dynamicObject = component.createObject(); - if(dynamicObject == null){ + if (dynamicObject == null) { print("error creating block"); print(component.errorsString()); return false; } dynamicObject.parent = background; - dynamicObject.x = column*blockSize; - dynamicObject.y = row*blockSize; + dynamicObject.x = column * blockSize; + dynamicObject.y = row * blockSize; dynamicObject.width = blockSize; dynamicObject.height = blockSize; - board[index(column,row)] = dynamicObject; - }else{ + board[index(column, row)] = dynamicObject; + } else { print("error loading block component"); print(component.errorsString()); return false; @@ -62,3 +61,4 @@ function createBlock(column,row){ return true; } //![0] + |