summaryrefslogtreecommitdiffstats
path: root/examples/declarative/tic-tac-toe/tic-tac-toe.qml
blob: ca66a465e1d0f39ce92a38547c1f6b4e693152a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import Qt 4.7
import "content"
import "content/tic-tac-toe.js" as Logic

Item {
    id: game
    property bool show: false;
    width: 440
    height: 480
    anchors.fill: parent
    property real difficulty: 1.0; //chance it will actually think

    Image {
        id: boardimage
        anchors.verticalCenter: parent.verticalCenter
        anchors.horizontalCenter: parent.horizontalCenter
        source: "content/pics/board.png"
    }

    Grid {
        id: board
        anchors.fill: boardimage

        columns: 3

        Repeater {
            model: 9
            TicTac {
                width: board.width/3
                height: board.height/3
                onClicked: {
                    if (!endtimer.running) {
                        if (!Logic.makeMove(index,"X"))
                            Logic.computerTurn()
                    }
                }
            }
        }

        Timer {
            id: endtimer
            interval: 1600
            onTriggered: { msg.opacity = 0; Logic.restart() }
        }
    }

    Row {
        spacing: 4
        anchors.top: board.bottom
        anchors.horizontalCenter: board.horizontalCenter
        Button {
            text: "Hard"
            onClicked: game.difficulty=1.0;
            down: game.difficulty == 1.0
        }
        Button {
            text: "Moderate"
            onClicked: game.difficulty=0.8;
            down: game.difficulty == 0.8
        }
        Button {
            text: "Easy"
            onClicked: game.difficulty=0.2;
            down: game.difficulty == 0.2
        }
    }

    Text {
        id: msg
        opacity: 0
        anchors.centerIn: parent
        color: "blue"
        styleColor: "white"
        style: Text.Outline
        font.pixelSize: 50
        font.bold: true
    }
}