summaryrefslogtreecommitdiffstats
path: root/examples/declarative/tutorials/samegame
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/tutorials/samegame')
-rw-r--r--examples/declarative/tutorials/samegame/samegame1/Button.qml6
-rw-r--r--examples/declarative/tutorials/samegame/samegame1/samegame.qml2
-rw-r--r--examples/declarative/tutorials/samegame/samegame2/Button.qml6
-rw-r--r--examples/declarative/tutorials/samegame/samegame2/samegame.js32
-rw-r--r--examples/declarative/tutorials/samegame/samegame2/samegame.qml2
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/Button.qml6
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/Dialog.qml8
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/samegame.js108
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/samegame.qml2
-rw-r--r--examples/declarative/tutorials/samegame/samegame4/content/Button.qml6
-rw-r--r--examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml8
-rwxr-xr-xexamples/declarative/tutorials/samegame/samegame4/content/samegame.js118
-rw-r--r--examples/declarative/tutorials/samegame/samegame4/samegame.qml8
13 files changed, 156 insertions, 156 deletions
diff --git a/examples/declarative/tutorials/samegame/samegame1/Button.qml b/examples/declarative/tutorials/samegame/samegame1/Button.qml
index 8eee2ad..6798c32 100644
--- a/examples/declarative/tutorials/samegame/samegame1/Button.qml
+++ b/examples/declarative/tutorials/samegame/samegame1/Button.qml
@@ -8,12 +8,12 @@ Rectangle {
property string text: "Button"
color: activePalette.button; smooth: true
- width: txtItem.width + 20; height: txtItem.height + 6
+ width: buttonLabel.width + 20; height: buttonLabel.height + 6
border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8;
gradient: Gradient {
GradientStop {
- id: topGrad; position: 0.0
+ position: 0.0
color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } }
GradientStop { position: 1.0; color: activePalette.button }
}
@@ -21,7 +21,7 @@ Rectangle {
MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() }
Text {
- id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText
+ id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText
}
}
//![0]
diff --git a/examples/declarative/tutorials/samegame/samegame1/samegame.qml b/examples/declarative/tutorials/samegame/samegame1/samegame.qml
index 23a25f3..ae881ba 100644
--- a/examples/declarative/tutorials/samegame/samegame1/samegame.qml
+++ b/examples/declarative/tutorials/samegame/samegame1/samegame.qml
@@ -24,7 +24,7 @@ Rectangle {
anchors.bottom: screen.bottom
Button {
- id: btnA; text: "New Game"; onClicked: console.log("Starting a new game...");
+ text: "New Game"; onClicked: console.log("Starting a new game...");
anchors.left: parent.left; anchors.leftMargin: 3
anchors.verticalCenter: parent.verticalCenter
}
diff --git a/examples/declarative/tutorials/samegame/samegame2/Button.qml b/examples/declarative/tutorials/samegame/samegame2/Button.qml
index 64a8a5a..04d1d1f 100644
--- a/examples/declarative/tutorials/samegame/samegame2/Button.qml
+++ b/examples/declarative/tutorials/samegame/samegame2/Button.qml
@@ -7,12 +7,12 @@ Rectangle {
property string text: "Button"
color: activePalette.button; smooth: true
- width: txtItem.width + 20; height: txtItem.height + 6
+ width: buttonLabel.width + 20; height: buttonLabel.height + 6
border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8;
gradient: Gradient {
GradientStop {
- id: topGrad; position: 0.0
+ position: 0.0
color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } }
GradientStop { position: 1.0; color: activePalette.button }
}
@@ -20,6 +20,6 @@ Rectangle {
MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() }
Text {
- id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText
+ id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText
}
}
diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.js b/examples/declarative/tutorials/samegame/samegame2/samegame.js
index 0ec3a8b..d7cbd8d 100644
--- a/examples/declarative/tutorials/samegame/samegame2/samegame.js
+++ b/examples/declarative/tutorials/samegame/samegame2/samegame.js
@@ -1,16 +1,16 @@
//![0]
//Note that X/Y referred to here are in game coordinates
-var maxX = 10;//Nums are for tileSize 40
-var maxY = 15;
+var maxColumn = 10;//Nums are for tileSize 40
+var maxRow = 15;
var tileSize = 40;
-var maxIndex = maxX*maxY;
+var maxIndex = maxColumn*maxRow;
var board = new Array(maxIndex);
var tileSrc = "Block.qml";
var component;
//Index function used instead of a 2D array
-function index(xIdx,yIdx) {
- return xIdx + (yIdx * maxX);
+function index(column,row) {
+ return column + (row * maxColumn);
}
function initBoard()
@@ -22,21 +22,21 @@ function initBoard()
}
//Calculate board size
- maxX = Math.floor(background.width/tileSize);
- maxY = Math.floor(background.height/tileSize);
- maxIndex = maxY*maxX;
+ maxColumn = Math.floor(background.width/tileSize);
+ maxRow = Math.floor(background.height/tileSize);
+ maxIndex = maxRow*maxColumn;
//Initialize Board
board = new Array(maxIndex);
- for(var xIdx=0; xIdx<maxX; xIdx++){
- for(var yIdx=0; yIdx<maxY; yIdx++){
- board[index(xIdx,yIdx)] = null;
- createBlock(xIdx,yIdx);
+ for(var column=0; column<maxColumn; column++){
+ for(var row=0; row<maxRow; row++){
+ board[index(column,row)] = null;
+ createBlock(column,row);
}
}
}
-function createBlock(xIdx,yIdx){
+function createBlock(column,row){
if(component==null)
component = createComponent(tileSrc);
@@ -52,11 +52,11 @@ function createBlock(xIdx,yIdx){
return false;
}
dynamicObject.parent = background;
- dynamicObject.x = xIdx*tileSize;
- dynamicObject.y = yIdx*tileSize;
+ dynamicObject.x = column*tileSize;
+ dynamicObject.y = row*tileSize;
dynamicObject.width = tileSize;
dynamicObject.height = tileSize;
- board[index(xIdx,yIdx)] = dynamicObject;
+ board[index(column,row)] = dynamicObject;
}else{//isError or isLoading
print("error loading block component");
print(component.errorsString());
diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.qml b/examples/declarative/tutorials/samegame/samegame2/samegame.qml
index a8a58ba..d98d383 100644
--- a/examples/declarative/tutorials/samegame/samegame2/samegame.qml
+++ b/examples/declarative/tutorials/samegame/samegame2/samegame.qml
@@ -27,7 +27,7 @@ Rectangle {
//![1]
Button {
- id: btnA; text: "New Game"; onClicked: SameGame.initBoard();
+ text: "New Game"; onClicked: SameGame.initBoard();
anchors.left: parent.left; anchors.leftMargin: 3
anchors.verticalCenter: parent.verticalCenter
}
diff --git a/examples/declarative/tutorials/samegame/samegame3/Button.qml b/examples/declarative/tutorials/samegame/samegame3/Button.qml
index 64a8a5a..04d1d1f 100644
--- a/examples/declarative/tutorials/samegame/samegame3/Button.qml
+++ b/examples/declarative/tutorials/samegame/samegame3/Button.qml
@@ -7,12 +7,12 @@ Rectangle {
property string text: "Button"
color: activePalette.button; smooth: true
- width: txtItem.width + 20; height: txtItem.height + 6
+ width: buttonLabel.width + 20; height: buttonLabel.height + 6
border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8;
gradient: Gradient {
GradientStop {
- id: topGrad; position: 0.0
+ position: 0.0
color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } }
GradientStop { position: 1.0; color: activePalette.button }
}
@@ -20,6 +20,6 @@ Rectangle {
MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() }
Text {
- id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText
+ id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText
}
}
diff --git a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml
index 69bae7c..6c358d6 100644
--- a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml
+++ b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml
@@ -8,16 +8,16 @@ Rectangle {
page.opacity = 0;
}
function show(txt) {
- myText.text = txt;
+ dialogText.text = txt;
page.opacity = 1;
}
signal closed();
- color: "white"; border.width: 1; width: myText.width + 20; height: 60;
+ color: "white"; border.width: 1; width: dialogText.width + 20; height: 60;
opacity: 0
Behavior on opacity {
NumberAnimation { duration: 1000 }
}
- Text { id: myText; anchors.centerIn: parent; text: "Hello World!" }
- MouseArea { id: mouseArea; anchors.fill: parent; onClicked: forceClose(); }
+ Text { id: dialogText; anchors.centerIn: parent; text: "Hello World!" }
+ MouseArea { anchors.fill: parent; onClicked: forceClose(); }
}
//![0]
diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.js b/examples/declarative/tutorials/samegame/samegame3/samegame.js
index 33449fa..432e88f 100644
--- a/examples/declarative/tutorials/samegame/samegame3/samegame.js
+++ b/examples/declarative/tutorials/samegame/samegame3/samegame.js
@@ -1,23 +1,23 @@
/* This script file handles the game logic */
//Note that X/Y referred to here are in game coordinates
-var maxX = 10;//Nums are for tileSize 40
-var maxY = 15;
-var maxIndex = maxX*maxY;
+var maxColumn = 10;//Nums are for tileSize 40
+var maxRow = 15;
+var maxIndex = maxColumn*maxRow;
var board = new Array(maxIndex);
var tileSrc = "Block.qml";
var component;
//Index function used instead of a 2D array
-function index(xIdx,yIdx) {
- return xIdx + (yIdx * maxX);
+function index(column,row) {
+ return column + (row * maxColumn);
}
function initBoard()
{
//Calculate board size
- maxX = Math.floor(gameCanvas.width/gameCanvas.tileSize);
- maxY = Math.floor(gameCanvas.height/gameCanvas.tileSize);
- maxIndex = maxY*maxX;
+ maxColumn = Math.floor(gameCanvas.width/gameCanvas.tileSize);
+ maxRow = Math.floor(gameCanvas.height/gameCanvas.tileSize);
+ maxIndex = maxRow*maxColumn;
//Close dialogs
dialog.forceClose();
@@ -25,15 +25,15 @@ function initBoard()
//Initialize Board
board = new Array(maxIndex);
gameCanvas.score = 0;
- for(var xIdx=0; xIdx<maxX; xIdx++){
- for(var yIdx=0; yIdx<maxY; yIdx++){
- board[index(xIdx,yIdx)] = null;
- createBlock(xIdx,yIdx);
+ for(var column=0; column<maxColumn; column++){
+ for(var row=0; row<maxRow; row++){
+ board[index(column,row)] = null;
+ createBlock(column,row);
}
}
}
-function createBlock(xIdx,yIdx){
+function createBlock(column,row){
if(component==null)
component = createComponent(tileSrc);
@@ -50,11 +50,11 @@ function createBlock(xIdx,yIdx){
}
dynamicObject.type = Math.floor(Math.random() * 3);
dynamicObject.parent = gameCanvas;
- dynamicObject.x = xIdx*gameCanvas.tileSize;
- dynamicObject.y = yIdx*gameCanvas.tileSize;
+ dynamicObject.x = column*gameCanvas.tileSize;
+ dynamicObject.y = row*gameCanvas.tileSize;
dynamicObject.width = gameCanvas.tileSize;
dynamicObject.height = gameCanvas.tileSize;
- board[index(xIdx,yIdx)] = dynamicObject;
+ board[index(column,row)] = dynamicObject;
}else{//isError or isLoading
print("error loading block component");
print(component.errorsString());
@@ -69,14 +69,14 @@ var floodBoard;//Set to 1 if the floodFill reaches off that node
//![1]
function handleClick(x,y)
{
- var xIdx = Math.floor(x/gameCanvas.tileSize);
- var yIdx = Math.floor(y/gameCanvas.tileSize);
- if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0)
+ var column = Math.floor(x/gameCanvas.tileSize);
+ var row = Math.floor(y/gameCanvas.tileSize);
+ if(column >= maxColumn || column < 0 || row >= maxRow || row < 0)
return;
- if(board[index(xIdx, yIdx)] == null)
+ if(board[index(column, row)] == null)
return;
//If it's a valid tile, remove it and all connected (does nothing if it's not connected)
- floodFill(xIdx,yIdx, -1);
+ floodFill(column,row, -1);
if(fillFound <= 0)
return;
gameCanvas.score += (fillFound - 1) * (fillFound - 1);
@@ -85,67 +85,67 @@ function handleClick(x,y)
}
//![1]
-function floodFill(xIdx,yIdx,type)
+function floodFill(column,row,type)
{
- if(board[index(xIdx, yIdx)] == null)
+ if(board[index(column, row)] == null)
return;
var first = false;
if(type == -1){
first = true;
- type = board[index(xIdx,yIdx)].type;
+ type = board[index(column,row)].type;
//Flood fill initialization
fillFound = 0;
floodBoard = new Array(maxIndex);
}
- if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0)
+ if(column >= maxColumn || column < 0 || row >= maxRow || row < 0)
return;
- if(floodBoard[index(xIdx, yIdx)] == 1 || (!first && type != board[index(xIdx,yIdx)].type))
+ if(floodBoard[index(column, row)] == 1 || (!first && type != board[index(column,row)].type))
return;
- floodBoard[index(xIdx, yIdx)] = 1;
- floodFill(xIdx+1,yIdx,type);
- floodFill(xIdx-1,yIdx,type);
- floodFill(xIdx,yIdx+1,type);
- floodFill(xIdx,yIdx-1,type);
+ floodBoard[index(column, row)] = 1;
+ floodFill(column+1,row,type);
+ floodFill(column-1,row,type);
+ floodFill(column,row+1,type);
+ floodFill(column,row-1,type);
if(first==true && fillFound == 0)
return;//Can't remove single tiles
- board[index(xIdx,yIdx)].opacity = 0;
- board[index(xIdx,yIdx)] = null;
+ board[index(column,row)].opacity = 0;
+ board[index(column,row)] = null;
fillFound += 1;
}
function shuffleDown()
{
//Fall down
- for(var xIdx=0; xIdx<maxX; xIdx++){
+ for(var column=0; column<maxColumn; column++){
var fallDist = 0;
- for(var yIdx=maxY-1; yIdx>=0; yIdx--){
- if(board[index(xIdx,yIdx)] == null){
+ for(var row=maxRow-1; row>=0; row--){
+ if(board[index(column,row)] == null){
fallDist += 1;
}else{
if(fallDist > 0){
- var obj = board[index(xIdx,yIdx)];
+ var obj = board[index(column,row)];
obj.y += fallDist * gameCanvas.tileSize;
- board[index(xIdx,yIdx+fallDist)] = obj;
- board[index(xIdx,yIdx)] = null;
+ board[index(column,row+fallDist)] = obj;
+ board[index(column,row)] = null;
}
}
}
}
//Fall to the left
var fallDist = 0;
- for(var xIdx=0; xIdx<maxX; xIdx++){
- if(board[index(xIdx, maxY - 1)] == null){
+ for(var column=0; column<maxColumn; column++){
+ if(board[index(column, maxRow - 1)] == null){
fallDist += 1;
}else{
if(fallDist > 0){
- for(var yIdx=0; yIdx<maxY; yIdx++){
- var obj = board[index(xIdx,yIdx)];
+ for(var row=0; row<maxRow; row++){
+ var obj = board[index(column,row)];
if(obj == null)
continue;
obj.x -= fallDist * gameCanvas.tileSize;
- board[index(xIdx-fallDist,yIdx)] = obj;
- board[index(xIdx,yIdx)] = null;
+ board[index(column-fallDist,row)] = obj;
+ board[index(column,row)] = null;
}
}
}
@@ -157,27 +157,27 @@ function victoryCheck()
{
//awards bonuses for no tiles left
var deservesBonus = true;
- for(var xIdx=maxX-1; xIdx>=0; xIdx--)
- if(board[index(xIdx, maxY - 1)] != null)
+ for(var column=maxColumn-1; column>=0; column--)
+ if(board[index(column, maxRow - 1)] != null)
deservesBonus = false;
if(deservesBonus)
gameCanvas.score += 500;
//Checks for game over
- if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1)))
+ if(deservesBonus || !(floodMoveCheck(0,maxRow-1, -1)))
dialog.show("Game Over. Your score is " + gameCanvas.score);
}
//![2]
//only floods up and right, to see if it can find adjacent same-typed tiles
-function floodMoveCheck(xIdx, yIdx, type)
+function floodMoveCheck(column, row, type)
{
- if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0)
+ if(column >= maxColumn || column < 0 || row >= maxRow || row < 0)
return false;
- if(board[index(xIdx, yIdx)] == null)
+ if(board[index(column, row)] == null)
return false;
- var myType = board[index(xIdx, yIdx)].type;
+ var myType = board[index(column, row)].type;
if(type == myType)
return true;
- return floodMoveCheck(xIdx + 1, yIdx, myType) ||
- floodMoveCheck(xIdx, yIdx - 1, board[index(xIdx,yIdx)].type);
+ return floodMoveCheck(column + 1, row, myType) ||
+ floodMoveCheck(column, row - 1, board[index(column,row)].type);
}
diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.qml b/examples/declarative/tutorials/samegame/samegame3/samegame.qml
index cd9dca5..9623932 100644
--- a/examples/declarative/tutorials/samegame/samegame3/samegame.qml
+++ b/examples/declarative/tutorials/samegame/samegame3/samegame.qml
@@ -45,7 +45,7 @@ Rectangle {
anchors.bottom: screen.bottom
Button {
- id: btnA; text: "New Game"; onClicked: SameGame.initBoard();
+ text: "New Game"; onClicked: SameGame.initBoard();
anchors.left: parent.left; anchors.leftMargin: 3
anchors.verticalCenter: parent.verticalCenter
}
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml
index 64a8a5a..04d1d1f 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml
+++ b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml
@@ -7,12 +7,12 @@ Rectangle {
property string text: "Button"
color: activePalette.button; smooth: true
- width: txtItem.width + 20; height: txtItem.height + 6
+ width: buttonLabel.width + 20; height: buttonLabel.height + 6
border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8;
gradient: Gradient {
GradientStop {
- id: topGrad; position: 0.0
+ position: 0.0
color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } }
GradientStop { position: 1.0; color: activePalette.button }
}
@@ -20,6 +20,6 @@ Rectangle {
MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() }
Text {
- id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText
+ id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText
}
}
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml
index 49fd5f6..0716bb3 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml
+++ b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml
@@ -7,15 +7,15 @@ Rectangle {
page.opacity = 0;
}
function show(txt) {
- myText.text = txt;
+ dialogText.text = txt;
page.opacity = 1;
}
signal closed();
- color: "white"; border.width: 1; width: myText.width + 20; height: 60;
+ color: "white"; border.width: 1; width: dialogText.width + 20; height: 60;
opacity: 0
Behavior on opacity {
NumberAnimation { duration: 1000 }
}
- Text { id: myText; anchors.centerIn: parent; text: "Hello World!" }
- MouseArea { id: mouseArea; anchors.fill: parent; onClicked: forceClose(); }
+ Text { id: dialogText; anchors.centerIn: parent; text: "Hello World!" }
+ MouseArea { anchors.fill: parent; onClicked: forceClose(); }
}
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js
index 478c662..f88b428 100755
--- a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js
+++ b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js
@@ -1,8 +1,8 @@
/* This script file handles the game logic */
//Note that X/Y referred to here are in game coordinates
-var maxX = 10;//Nums are for gameCanvas.tileSize 40
-var maxY = 15;
-var maxIndex = maxX*maxY;
+var maxColumn = 10;//Nums are for gameCanvas.tileSize 40
+var maxRow = 15;
+var maxIndex = maxColumn*maxRow;
var board = new Array(maxIndex);
var tileSrc = "content/BoomBlock.qml";
//var scoresURL = "http://qtfx-nokia.trolltech.com.au/samegame/scores.php";
@@ -11,8 +11,8 @@ var timer;
var component = createComponent(tileSrc);
//Index function used instead of a 2D array
-function index(xIdx,yIdx) {
- return xIdx + (yIdx * maxX);
+function index(column,row) {
+ return column + (row * maxColumn);
}
function timeStr(msecs) {
@@ -31,21 +31,21 @@ function initBoard()
}
//Calculate board size
- maxX = Math.floor(gameCanvas.width/gameCanvas.tileSize);
- maxY = Math.floor(gameCanvas.height/gameCanvas.tileSize);
- maxIndex = maxY*maxX;
+ maxColumn = Math.floor(gameCanvas.width/gameCanvas.tileSize);
+ maxRow = Math.floor(gameCanvas.height/gameCanvas.tileSize);
+ maxIndex = maxRow*maxColumn;
//Close dialogs
- scoreName.forceClose();
+ nameInputDialog.forceClose();
dialog.forceClose();
//Initialize Board
board = new Array(maxIndex);
gameCanvas.score = 0;
- for(var xIdx=0; xIdx<maxX; xIdx++){
- for(var yIdx=0; yIdx<maxY; yIdx++){
- board[index(xIdx,yIdx)] = null;
- createBlock(xIdx,yIdx);
+ for(var column=0; column<maxColumn; column++){
+ for(var row=0; row<maxRow; row++){
+ board[index(column,row)] = null;
+ createBlock(column,row);
}
}
}
@@ -55,14 +55,14 @@ var floodBoard;//Set to 1 if the floodFill reaches off that node
//NOTE: Be careful with vars named x,y, as the calling object's x,y are still in scope
function handleClick(x,y)
{
- var xIdx = Math.floor(x/gameCanvas.tileSize);
- var yIdx = Math.floor(y/gameCanvas.tileSize);
- if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0)
+ var column = Math.floor(x/gameCanvas.tileSize);
+ var row = Math.floor(y/gameCanvas.tileSize);
+ if(column >= maxColumn || column < 0 || row >= maxRow || row < 0)
return;
- if(board[index(xIdx, yIdx)] == null)
+ if(board[index(column, row)] == null)
return;
//If it's a valid tile, remove it and all connected (does nothing if it's not connected)
- floodFill(xIdx,yIdx, -1);
+ floodFill(column,row, -1);
if(fillFound <= 0)
return;
gameCanvas.score += (fillFound - 1) * (fillFound - 1);
@@ -70,67 +70,67 @@ function handleClick(x,y)
victoryCheck();
}
-function floodFill(xIdx,yIdx,type)
+function floodFill(column,row,type)
{
- if(board[index(xIdx, yIdx)] == null)
+ if(board[index(column, row)] == null)
return;
var first = false;
if(type == -1){
first = true;
- type = board[index(xIdx,yIdx)].type;
+ type = board[index(column,row)].type;
//Flood fill initialization
fillFound = 0;
floodBoard = new Array(maxIndex);
}
- if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0)
+ if(column >= maxColumn || column < 0 || row >= maxRow || row < 0)
return;
- if(floodBoard[index(xIdx, yIdx)] == 1 || (!first && type != board[index(xIdx,yIdx)].type))
+ if(floodBoard[index(column, row)] == 1 || (!first && type != board[index(column,row)].type))
return;
- floodBoard[index(xIdx, yIdx)] = 1;
- floodFill(xIdx+1,yIdx,type);
- floodFill(xIdx-1,yIdx,type);
- floodFill(xIdx,yIdx+1,type);
- floodFill(xIdx,yIdx-1,type);
+ floodBoard[index(column, row)] = 1;
+ floodFill(column+1,row,type);
+ floodFill(column-1,row,type);
+ floodFill(column,row+1,type);
+ floodFill(column,row-1,type);
if(first==true && fillFound == 0)
return;//Can't remove single tiles
- board[index(xIdx,yIdx)].dying = true;
- board[index(xIdx,yIdx)] = null;
+ board[index(column,row)].dying = true;
+ board[index(column,row)] = null;
fillFound += 1;
}
function shuffleDown()
{
//Fall down
- for(var xIdx=0; xIdx<maxX; xIdx++){
+ for(var column=0; column<maxColumn; column++){
var fallDist = 0;
- for(var yIdx=maxY-1; yIdx>=0; yIdx--){
- if(board[index(xIdx,yIdx)] == null){
+ for(var row=maxRow-1; row>=0; row--){
+ if(board[index(column,row)] == null){
fallDist += 1;
}else{
if(fallDist > 0){
- var obj = board[index(xIdx,yIdx)];
+ var obj = board[index(column,row)];
obj.targetY += fallDist * gameCanvas.tileSize;
- board[index(xIdx,yIdx+fallDist)] = obj;
- board[index(xIdx,yIdx)] = null;
+ board[index(column,row+fallDist)] = obj;
+ board[index(column,row)] = null;
}
}
}
}
//Fall to the left
fallDist = 0;
- for(xIdx=0; xIdx<maxX; xIdx++){
- if(board[index(xIdx, maxY - 1)] == null){
+ for(column=0; column<maxColumn; column++){
+ if(board[index(column, maxRow - 1)] == null){
fallDist += 1;
}else{
if(fallDist > 0){
- for(yIdx=0; yIdx<maxY; yIdx++){
- obj = board[index(xIdx,yIdx)];
+ for(row=0; row<maxRow; row++){
+ obj = board[index(column,row)];
if(obj == null)
continue;
obj.targetX -= fallDist * gameCanvas.tileSize;
- board[index(xIdx-fallDist,yIdx)] = obj;
- board[index(xIdx,yIdx)] = null;
+ board[index(column-fallDist,row)] = obj;
+ board[index(column,row)] = null;
}
}
}
@@ -141,34 +141,34 @@ function victoryCheck()
{
//awards bonuses for no tiles left
var deservesBonus = true;
- for(var xIdx=maxX-1; xIdx>=0; xIdx--)
- if(board[index(xIdx, maxY - 1)] != null)
+ for(var column=maxColumn-1; column>=0; column--)
+ if(board[index(column, maxRow - 1)] != null)
deservesBonus = false;
if(deservesBonus)
gameCanvas.score += 500;
//Checks for game over
- if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))){
+ if(deservesBonus || !(floodMoveCheck(0,maxRow-1, -1))){
timer = new Date() - timer;
- scoreName.show("You won! Please enter your name: ");
+ nameInputDialog.show("You won! Please enter your name: ");
//dialog.show("Game Over. Your score is " + gameCanvas.score);
}
}
//only floods up and right, to see if it can find adjacent same-typed tiles
-function floodMoveCheck(xIdx, yIdx, type)
+function floodMoveCheck(column, row, type)
{
- if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0)
+ if(column >= maxColumn || column < 0 || row >= maxRow || row < 0)
return false;
- if(board[index(xIdx, yIdx)] == null)
+ if(board[index(column, row)] == null)
return false;
- var myType = board[index(xIdx, yIdx)].type;
+ var myType = board[index(column, row)].type;
if(type == myType)
return true;
- return floodMoveCheck(xIdx + 1, yIdx, myType) ||
- floodMoveCheck(xIdx, yIdx - 1, board[index(xIdx,yIdx)].type);
+ return floodMoveCheck(column + 1, row, myType) ||
+ floodMoveCheck(column, row - 1, board[index(column,row)].type);
}
-function createBlock(xIdx,yIdx){
+function createBlock(column,row){
// Note that we don't wait for the component to become ready. This will
// only work if the block QML is a local file. Otherwise the component will
// not be ready immediately. There is a statusChanged signal on the
@@ -182,13 +182,13 @@ function createBlock(xIdx,yIdx){
}
dynamicObject.type = Math.floor(Math.random() * 3);
dynamicObject.parent = gameCanvas;
- dynamicObject.x = xIdx*gameCanvas.tileSize;
- dynamicObject.targetX = xIdx*gameCanvas.tileSize;
- dynamicObject.targetY = yIdx*gameCanvas.tileSize;
+ dynamicObject.x = column*gameCanvas.tileSize;
+ dynamicObject.targetX = column*gameCanvas.tileSize;
+ dynamicObject.targetY = row*gameCanvas.tileSize;
dynamicObject.width = gameCanvas.tileSize;
dynamicObject.height = gameCanvas.tileSize;
dynamicObject.spawned = true;
- board[index(xIdx,yIdx)] = dynamicObject;
+ board[index(column,row)] = dynamicObject;
}else{//isError or isLoading
print("error loading block component");
print(component.errorsString());
@@ -204,7 +204,7 @@ function saveHighScore(name) {
//OfflineStorage
var db = openDatabaseSync("SameGameScores", "1.0", "Local SameGame High Scores",100);
var dataStr = "INSERT INTO Scores VALUES(?, ?, ?, ?)";
- var data = [name, gameCanvas.score, maxX+"x"+maxY ,Math.floor(timer/1000)];
+ var data = [name, gameCanvas.score, maxColumn+"x"+maxRow ,Math.floor(timer/1000)];
db.transaction(
function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)');
@@ -227,7 +227,7 @@ function saveHighScore(name) {
function sendHighScore(name) {
var postman = new XMLHttpRequest()
var postData = "name="+name+"&score="+gameCanvas.score
- +"&gridSize="+maxX+"x"+maxY +"&time="+Math.floor(timer/1000);
+ +"&gridSize="+maxColumn+"x"+maxRow +"&time="+Math.floor(timer/1000);
postman.open("POST", scoresURL, true);
postman.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
postman.onreadystatechange = function() {
diff --git a/examples/declarative/tutorials/samegame/samegame4/samegame.qml b/examples/declarative/tutorials/samegame/samegame4/samegame.qml
index f3027fa..59e0cef 100644
--- a/examples/declarative/tutorials/samegame/samegame4/samegame.qml
+++ b/examples/declarative/tutorials/samegame/samegame4/samegame.qml
@@ -36,7 +36,7 @@ Rectangle {
//![0]
Dialog {
- id: scoreName; anchors.centerIn: parent; z: 22;
+ id: nameInputDialog; anchors.centerIn: parent; z: 22;
Text {
id: spacer
opacity: 0
@@ -45,9 +45,9 @@ Rectangle {
TextInput {
id: editor
onAccepted: {
- if(scoreName.opacity==1&&editor.text!="")
+ if(nameInputDialog.opacity==1&&editor.text!="")
saveHighScore(editor.text);
- scoreName.forceClose();
+ nameInputDialog.forceClose();
}
anchors.verticalCenter: parent.verticalCenter
width: 72; focus: true
@@ -63,7 +63,7 @@ Rectangle {
anchors.bottom: screen.bottom
Button {
- id: btnA; text: "New Game"; onClicked: {SameGame.initBoard();}
+ text: "New Game"; onClicked: SameGame.initBoard();
anchors.left: parent.left; anchors.leftMargin: 3
anchors.verticalCenter: parent.verticalCenter
}