Warning, /education/gcompris/src/activities/tic_tac_toe/TicTacToe.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - TicTacToe.qml
0002  *
0003  * SPDX-FileCopyrightText: 2014 Pulkit Gupta <pulkitgenius@gmail.com>
0004  *
0005  * Authors:
0006  *   Pulkit Gupta <pulkitgenius@gmail.com>
0007  *
0008  *   SPDX-License-Identifier: GPL-3.0-or-later
0009  */
0010 import QtQuick 2.12
0011 
0012 import "../../core"
0013 import "tic_tac_toe.js" as Activity
0014 
0015 import GCompris 1.0
0016 
0017 ActivityBase {
0018     id: activity
0019 
0020     property bool twoPlayer: false
0021     onStart: focus = true
0022     onStop: {}
0023 
0024     pageComponent: Image {
0025         id: background
0026         anchors.fill: parent
0027         source: Activity.url + "background.svg"
0028         sourceSize.width: width
0029         sourceSize.height: height
0030         fillMode: Image.PreserveAspectCrop
0031         signal start
0032         signal stop
0033 
0034         Component.onCompleted: {
0035             activity.start.connect(start)
0036             activity.stop.connect(stop)
0037         }
0038 
0039         // Add here the QML items you need to access in javascript
0040         QtObject {
0041             id: items
0042             property Item main: activity.main
0043             property alias background: background
0044 
0045             property alias player1score: player1score
0046             property alias player2score: player2score
0047 
0048             property alias pieces: pieces
0049             property alias createPiece: createPiece
0050             property alias repeater: repeater
0051             property alias columns: grid.columns
0052             property alias rows: grid.rows
0053             property alias magnify: magnify
0054             property alias demagnify: demagnify
0055             property bool gameDone
0056             property int counter
0057             property int playSecond
0058             property int currentLevel: activity.currentLevel
0059             property alias bonus: bonus
0060         }
0061 
0062         onStart: Activity.start(items, twoPlayer)
0063         onStop: Activity.stop()
0064 
0065         Image {
0066             id: board
0067             source: Activity.url + "board.svg"
0068             sourceSize.width: 4 * Math.min(background.width / 4, background.height / 6)
0069             anchors {
0070                 verticalCenter: parent.verticalCenter
0071                 horizontalCenter: parent.horizontalCenter
0072             }
0073 
0074             ListModel {
0075                 id: pieces
0076             }
0077 
0078             Grid {
0079                 id: grid
0080                 rows: 3
0081                 columns: 3
0082                 anchors {
0083                 fill: parent
0084                 left: parent.left
0085                 leftMargin: parent.width/18
0086                 top: parent.top
0087                 topMargin: board.width/20
0088                 }
0089                 spacing: board.width/16
0090                 Repeater {
0091                     id: repeater
0092                     model: pieces
0093                     delegate: blueSquare
0094                     Component {
0095                         id: blueSquare
0096                         Rectangle {
0097                             width: (grid.height/4)*1.1
0098                             height: (grid.height/4)*1.1
0099                             border.color: "transparent"
0100                             border.width: 5
0101                             radius: 10
0102                             state: "INITIAL"
0103                             color: "#c7ecfb"
0104                             Piece {
0105                                 anchors.fill: parent
0106                                 state: stateTemp
0107                             }
0108                             states: [
0109                                 State {
0110                                     name: "INITIAL"
0111                                     PropertyChanges {
0112                                         target: area
0113                                         visible: true
0114                                     }
0115                                 },
0116                                 State {
0117                                     name: "DONE"
0118                                     PropertyChanges {
0119                                         target: area;
0120                                         visible: false;
0121                                     }
0122                                 }
0123                             ]
0124                             MouseArea {
0125                                 id: area
0126                                 enabled: !magnify.running && !items.gameDone
0127                                 hoverEnabled: enabled
0128                                 width: parent.width
0129                                 height: parent.height
0130                                 onEntered: { border.color = "#62db53" }
0131                                 onExited: { border.color = "transparent" }
0132                                 onClicked: { Activity.handleCreate(parent) }
0133                             }
0134                         }
0135                     }
0136                 }
0137                 Piece {
0138                     id: createPiece
0139                     state: (items.counter + items.playSecond) % 2 ? "2": "1"
0140                     width: (grid.height/4)*1.1
0141                     height: (grid.height/4)*1.1
0142                     opacity: 0
0143                 }
0144             }
0145         }
0146 
0147         PropertyAnimation {
0148             id: demagnify
0149             target: createPiece
0150             properties: "scale"
0151             from: 1.0
0152             to: 0.0
0153             duration: 1
0154         }
0155         PropertyAnimation {
0156             id: magnify
0157             target: createPiece
0158             properties: "scale"
0159             from: 0.0
0160             to: 1.0
0161             duration: 1000
0162             onStarted: activity.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/smudge.wav')
0163             onStopped: { Activity.continueGame() }
0164         }
0165 
0166         ScoreItem {
0167             id: player1score
0168             player: 1
0169             height: Math.min(background.height/7, Math.min(background.width/7, bar.height * 1.05))
0170             width: height*11/8
0171             anchors {
0172                 top: background.top
0173                 topMargin: 5
0174                 left: background.left
0175                 leftMargin: 5
0176             }
0177             playerImageSource: "qrc:/gcompris/src/core/resource/player_1.svg"
0178             backgroundImageSource: Activity.url + "score_1.svg"
0179             playerItem.source: Activity.url + "cross.svg"
0180             playerItem.height: playerItem.parent.height * 0.4
0181             playerItem.anchors.leftMargin: playerItem.parent.height * 0.15
0182             playerItem.anchors.bottomMargin: playerItem.parent.height * 0.05
0183         }
0184 
0185         ScoreItem {
0186             id: player2score
0187             player: 2
0188             height: Math.min(background.height/7, Math.min(background.width/7, bar.height * 1.05))
0189             width: height*11/8
0190             anchors {
0191                 top: background.top
0192                 topMargin: 5
0193                 right: background.right
0194                 rightMargin: 5
0195             }
0196             playerImageSource: "qrc:/gcompris/src/core/resource/player_2.svg"
0197             backgroundImageSource: Activity.url + "score_2.svg"
0198             playerScaleOriginX: player2score.width
0199             playerItem.source: Activity.url + "circle.svg"
0200             playerItem.height: playerItem.parent.height * 0.4
0201             playerItem.anchors.leftMargin: playerItem.parent.height * 0.15
0202             playerItem.anchors.bottomMargin: playerItem.parent.height * 0.15
0203         }
0204 
0205         DialogHelp {
0206             id: dialogHelp
0207             onClose: home()
0208         }
0209 
0210         Bar {
0211             id: bar
0212             level: items.currentLevel + 1
0213             content: BarEnumContent { value: (twoPlayer ? (help | home | reload) : (help | home | level | reload))}
0214             onHelpClicked: {
0215                 displayDialog(dialogHelp)
0216             }
0217             onPreviousLevelClicked: Activity.previousLevel()
0218             onNextLevelClicked: Activity.nextLevel()
0219             onHomeClicked: activity.home()
0220             onReloadClicked: {
0221                 Activity.reset()
0222             }
0223         }
0224 
0225         Bonus {
0226             id: bonus
0227         }
0228     }
0229 }