aboutsummaryrefslogtreecommitdiffstats
path: root/examples/declarative/qtquick1/toys/tic-tac-toe
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/qtquick1/toys/tic-tac-toe')
-rw-r--r--examples/declarative/qtquick1/toys/tic-tac-toe/content/Button.qml79
-rw-r--r--examples/declarative/qtquick1/toys/tic-tac-toe/content/TicTac.qml60
-rw-r--r--examples/declarative/qtquick1/toys/tic-tac-toe/content/pics/board.pngbin12258 -> 0 bytes
-rw-r--r--examples/declarative/qtquick1/toys/tic-tac-toe/content/pics/o.pngbin1470 -> 0 bytes
-rw-r--r--examples/declarative/qtquick1/toys/tic-tac-toe/content/pics/x.pngbin1331 -> 0 bytes
-rw-r--r--examples/declarative/qtquick1/toys/tic-tac-toe/content/tic-tac-toe.js149
-rw-r--r--examples/declarative/qtquick1/toys/tic-tac-toe/tic-tac-toe.qml123
-rw-r--r--examples/declarative/qtquick1/toys/tic-tac-toe/tic-tac-toe.qmlproject16
8 files changed, 0 insertions, 427 deletions
diff --git a/examples/declarative/qtquick1/toys/tic-tac-toe/content/Button.qml b/examples/declarative/qtquick1/toys/tic-tac-toe/content/Button.qml
deleted file mode 100644
index 01f2c61aad..0000000000
--- a/examples/declarative/qtquick1/toys/tic-tac-toe/content/Button.qml
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
-** the names of its contributors may be used to endorse or promote
-** products derived from this software without specific prior written
-** permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-import QtQuick 1.0
-
-Rectangle {
- id: container
-
- property string text
- property bool pressed: false
-
- signal clicked
-
- width: buttonLabel.width + 20; height: buttonLabel.height + 6
- border { width: 1; color: Qt.darker(container.color) }
- radius: 8
- color: "lightgray"
- smooth: true
-
- gradient: Gradient {
- GradientStop {
- position: 0.0
- color: container.pressed ? "darkgray" : "white"
- }
- GradientStop {
- position: 1.0
- color: container.color
- }
- }
-
- MouseArea {
- anchors.fill: parent
- onClicked: container.clicked()
- }
-
- Text {
- id: buttonLabel
- anchors.centerIn: container
- text: container.text
- font.pixelSize: 14
- }
-}
diff --git a/examples/declarative/qtquick1/toys/tic-tac-toe/content/TicTac.qml b/examples/declarative/qtquick1/toys/tic-tac-toe/content/TicTac.qml
deleted file mode 100644
index 67b0402a98..0000000000
--- a/examples/declarative/qtquick1/toys/tic-tac-toe/content/TicTac.qml
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
-** the names of its contributors may be used to endorse or promote
-** products derived from this software without specific prior written
-** permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-import QtQuick 1.0
-
-Item {
- signal clicked
-
- states: [
- State { name: "X"; PropertyChanges { target: image; source: "pics/x.png" } },
- State { name: "O"; PropertyChanges { target: image; source: "pics/o.png" } }
- ]
-
- Image {
- id: image
- anchors.centerIn: parent
- }
-
- MouseArea {
- anchors.fill: parent
- onClicked: parent.clicked()
- }
-}
diff --git a/examples/declarative/qtquick1/toys/tic-tac-toe/content/pics/board.png b/examples/declarative/qtquick1/toys/tic-tac-toe/content/pics/board.png
deleted file mode 100644
index 7e5b7ba27c..0000000000
--- a/examples/declarative/qtquick1/toys/tic-tac-toe/content/pics/board.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/qtquick1/toys/tic-tac-toe/content/pics/o.png b/examples/declarative/qtquick1/toys/tic-tac-toe/content/pics/o.png
deleted file mode 100644
index abc7ee020b..0000000000
--- a/examples/declarative/qtquick1/toys/tic-tac-toe/content/pics/o.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/qtquick1/toys/tic-tac-toe/content/pics/x.png b/examples/declarative/qtquick1/toys/tic-tac-toe/content/pics/x.png
deleted file mode 100644
index ddc65c83b8..0000000000
--- a/examples/declarative/qtquick1/toys/tic-tac-toe/content/pics/x.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/qtquick1/toys/tic-tac-toe/content/tic-tac-toe.js b/examples/declarative/qtquick1/toys/tic-tac-toe/content/tic-tac-toe.js
deleted file mode 100644
index 5a166b750f..0000000000
--- a/examples/declarative/qtquick1/toys/tic-tac-toe/content/tic-tac-toe.js
+++ /dev/null
@@ -1,149 +0,0 @@
-function winner(board)
-{
- for (var i=0; i<3; ++i) {
- if (board.children[i].state != ""
- && board.children[i].state == board.children[i+3].state
- && board.children[i].state == board.children[i+6].state)
- return true
-
- if (board.children[i*3].state != ""
- && board.children[i*3].state == board.children[i*3+1].state
- && board.children[i*3].state == board.children[i*3+2].state)
- return true
- }
-
- if (board.children[0].state != ""
- && board.children[0].state == board.children[4].state != ""
- && board.children[0].state == board.children[8].state != "")
- return true
-
- if (board.children[2].state != ""
- && board.children[2].state == board.children[4].state != ""
- && board.children[2].state == board.children[6].state != "")
- return true
-
- return false
-}
-
-function restartGame()
-{
- game.running = true
-
- for (var i=0; i<9; ++i)
- board.children[i].state = ""
-}
-
-function makeMove(pos, player)
-{
- board.children[pos].state = player
- if (winner(board)) {
- gameFinished(player + " wins")
- return true
- } else {
- return false
- }
-}
-
-function canPlayAtPos(pos)
-{
- return board.children[pos].state == ""
-}
-
-function computerTurn()
-{
- var r = Math.random();
- if (r < game.difficulty)
- smartAI();
- else
- randomAI();
-}
-
-function smartAI()
-{
- function boardCopy(a) {
- var ret = new Object;
- ret.children = new Array(9);
- for (var i = 0; i<9; i++) {
- ret.children[i] = new Object;
- ret.children[i].state = a.children[i].state;
- }
- return ret;
- }
-
- for (var i=0; i<9; i++) {
- var simpleBoard = boardCopy(board);
- if (canPlayAtPos(i)) {
- simpleBoard.children[i].state = "O";
- if (winner(simpleBoard)) {
- makeMove(i, "O")
- return
- }
- }
- }
- for (var i=0; i<9; i++) {
- var simpleBoard = boardCopy(board);
- if (canPlayAtPos(i)) {
- simpleBoard.children[i].state = "X";
- if (winner(simpleBoard)) {
- makeMove(i, "O")
- return
- }
- }
- }
-
- function thwart(a,b,c) { //If they are at a, try b or c
- if (board.children[a].state == "X") {
- if (canPlayAtPos(b)) {
- makeMove(b, "O")
- return true
- } else if (canPlayAtPos(c)) {
- makeMove(c, "O")
- return true
- }
- }
- return false;
- }
-
- if (thwart(4,0,2)) return;
- if (thwart(0,4,3)) return;
- if (thwart(2,4,1)) return;
- if (thwart(6,4,7)) return;
- if (thwart(8,4,5)) return;
- if (thwart(1,4,2)) return;
- if (thwart(3,4,0)) return;
- if (thwart(5,4,8)) return;
- if (thwart(7,4,6)) return;
-
- for (var i =0; i<9; i++) {
- if (canPlayAtPos(i)) {
- makeMove(i, "O")
- return
- }
- }
- restartGame();
-}
-
-function randomAI()
-{
- var unfilledPosns = new Array();
-
- for (var i=0; i<9; ++i) {
- if (canPlayAtPos(i))
- unfilledPosns.push(i);
- }
-
- if (unfilledPosns.length == 0) {
- restartGame();
- } else {
- var choice = unfilledPosns[Math.floor(Math.random() * unfilledPosns.length)];
- makeMove(choice, "O");
- }
-}
-
-function gameFinished(message)
-{
- messageDisplay.text = message
- messageDisplay.visible = true
- game.running = false
-}
-
diff --git a/examples/declarative/qtquick1/toys/tic-tac-toe/tic-tac-toe.qml b/examples/declarative/qtquick1/toys/tic-tac-toe/tic-tac-toe.qml
deleted file mode 100644
index 49d78a99d1..0000000000
--- a/examples/declarative/qtquick1/toys/tic-tac-toe/tic-tac-toe.qml
+++ /dev/null
@@ -1,123 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
-** the names of its contributors may be used to endorse or promote
-** products derived from this software without specific prior written
-** permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-import QtQuick 1.0
-import "content"
-import "content/tic-tac-toe.js" as Logic
-
-Rectangle {
- id: game
-
- property bool running: true
- property real difficulty: 1.0 //chance it will actually think
-
- width: display.width; height: display.height + 10
-
- Image {
- id: boardImage
- source: "content/pics/board.png"
- }
-
-
- Column {
- id: display
-
- Grid {
- id: board
- width: boardImage.width; height: boardImage.height
- columns: 3
-
- Repeater {
- model: 9
-
- TicTac {
- width: board.width/3
- height: board.height/3
-
- onClicked: {
- if (game.running && Logic.canPlayAtPos(index)) {
- if (!Logic.makeMove(index, "X"))
- Logic.computerTurn();
- }
- }
- }
- }
- }
-
- Row {
- spacing: 4
- anchors.horizontalCenter: parent.horizontalCenter
-
- Button {
- text: "Hard"
- pressed: game.difficulty == 1.0
- onClicked: { game.difficulty = 1.0 }
- }
- Button {
- text: "Moderate"
- pressed: game.difficulty == 0.8
- onClicked: { game.difficulty = 0.8 }
- }
- Button {
- text: "Easy"
- pressed: game.difficulty == 0.2
- onClicked: { game.difficulty = 0.2 }
- }
- }
- }
-
-
- Text {
- id: messageDisplay
- anchors.centerIn: parent
- color: "blue"
- style: Text.Outline; styleColor: "white"
- font.pixelSize: 50; font.bold: true
- visible: false
-
- Timer {
- running: messageDisplay.visible
- onTriggered: {
- messageDisplay.visible = false;
- Logic.restartGame();
- }
- }
- }
-}
diff --git a/examples/declarative/qtquick1/toys/tic-tac-toe/tic-tac-toe.qmlproject b/examples/declarative/qtquick1/toys/tic-tac-toe/tic-tac-toe.qmlproject
deleted file mode 100644
index 6351084ba9..0000000000
--- a/examples/declarative/qtquick1/toys/tic-tac-toe/tic-tac-toe.qmlproject
+++ /dev/null
@@ -1,16 +0,0 @@
-import QmlProject 1.1
-
-Project {
- mainFile: "tic-tac-toe.qml"
-
- /* Include .qml, .js, and image files from current directory and subdirectories */
- QmlFiles {
- directory: "."
- }
- JavaScriptFiles {
- directory: "."
- }
- ImageFiles {
- directory: "."
- }
-}