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

0001 /* GCompris - NineMenMorris.qml
0002  *
0003  * SPDX-FileCopyrightText: 2016 Pulkit Gupta <pulkitnsit@gmail.com>
0004  *
0005  * Authors:
0006  *   Pulkit Gupta <pulkitnsit@gmail.com>
0007  *
0008  *   SPDX-License-Identifier: GPL-3.0-or-later
0009 */
0010 import QtQuick 2.12
0011 
0012 import "../../core"
0013 import "nine_men_morris.js" as Activity
0014 import "."
0015 
0016 ActivityBase {
0017     id: activity
0018 
0019     property bool twoPlayer: false
0020     onStart: focus = true
0021     onStop: {}
0022 
0023     pageComponent: Image {
0024     id: background
0025         anchors.fill: parent
0026         source: "qrc:/gcompris/src/activities/tic_tac_toe/resource/background.svg"
0027         sourceSize.width: width
0028         sourceSize.height: height
0029         fillMode: Image.PreserveAspectCrop
0030         signal start
0031         signal stop
0032 
0033         Component.onCompleted: {
0034             activity.start.connect(start)
0035             activity.stop.connect(stop)
0036         }
0037 
0038         // Needed to get keyboard focus on Tutorial
0039         Keys.forwardTo: tutorialSection
0040 
0041         // Add here the QML items you need to access in javascript
0042         QtObject {
0043             id: items
0044             property Item main: activity.main
0045             property alias dragPointsModel: dragPointsModel
0046             property alias dragPoints: dragPoints
0047             property alias piecesLayout: piecesLayout
0048 
0049             property alias firstInitial: firstInitial
0050             property alias firstPlayerPieces: firstPlayerPieces
0051             property alias firstPlayerPiecesModel: firstPlayerPiecesModel
0052             property alias firstPieceNumberCount: firstPieceNumber.count
0053             property alias player1score: player1score
0054 
0055             property alias secondInitial: secondInitial
0056             property alias secondPlayerPieces: secondPlayerPieces
0057             property alias secondPlayerPiecesModel: secondPlayerPiecesModel
0058             property alias secondPieceNumberCount: secondPieceNumber.count
0059             property alias player2score: player2score
0060 
0061             property alias trigTuxMove: trigTuxMove
0062 
0063             property bool gameDone
0064             property int turn
0065             property bool playSecond
0066             property bool firstPhase
0067             property bool pieceBeingMoved
0068 
0069             property int currentLevel: activity.currentLevel
0070             property alias bonus: bonus
0071             property alias instructionTxt: instruction.text
0072             property alias tutorialSection: tutorialSection
0073         }
0074 
0075         onStart: Activity.start(items, twoPlayer)
0076         onStop: Activity.stop()
0077 
0078         // Tux move delay
0079         Timer {
0080             id: trigTuxMove
0081             repeat: false
0082             interval: 1500
0083             onTriggered: {
0084                 Activity.doMove()
0085                 items.player2score.endTurn()
0086                 items.player1score.beginTurn()
0087             }
0088         }
0089 
0090         Image {
0091             id: board
0092             source: Activity.url + "board.svg"
0093             sourceSize.width: Math.min(background.height - 1.4 * player1score.height - 1.2 * bar.height,
0094                                        background.width - 2.2 * firstInitial.width)
0095             anchors {
0096                 verticalCenter: parent.verticalCenter
0097                 horizontalCenter: parent.horizontalCenter
0098                 verticalCenterOffset : -0.25 * player1score.height
0099             }
0100 
0101             Repeater {
0102                 id: dragPoints
0103                 model: dragPointsModel
0104                 delegate: point
0105                 Component {
0106                     id: point
0107                     DragPoint {
0108                         id: dragPoint
0109                         x: posX * parent.width - width / 2
0110                         y: posY * parent.height - height / 2
0111                         index: myIndex
0112                         firstPhase: items.firstPhase
0113                         pieceBeingMoved: items.pieceBeingMoved
0114                     }
0115                 }
0116             }
0117 
0118             Repeater {
0119                 id: piecesLayout
0120                 model: dragPointsModel
0121                 delegate: piecePoint
0122                 Component {
0123                     id: piecePoint
0124                     Item {
0125                         width: parent.width * 0.05
0126                         height: width
0127                         x: posX * parent.width - width * 0.5
0128                         y: posY * parent.height - height * 0.5
0129                     }
0130                 }
0131             }
0132         }
0133 
0134         ListModel {
0135             id: dragPointsModel
0136         }
0137 
0138         Rectangle {
0139             id: firstInitial
0140             anchors {
0141                 left: player1score.left
0142                 top: player1score.bottom
0143                 topMargin: player1score.height * 0.5
0144             }
0145             width: player1score.width * 1.2
0146             height: player1score.height * 1.2
0147             visible: items.firstPhase
0148             opacity: 1.0
0149             radius: 10
0150             border.width: 2
0151             border.color: "white"
0152             color: "#373737"
0153 
0154             Repeater {
0155                 id: firstPlayerPieces
0156                 model: firstPlayerPiecesModel
0157                 delegate: firstPieceInitial
0158                 Component {
0159                     id: firstPieceInitial
0160                     Piece {
0161                         id: firstPiece
0162                         state: "1"
0163                         firstPhase: items.firstPhase
0164                         sourceSize.height: Math.min(firstInitial.height * 0.8, firstInitial.width * 0.4)
0165                         x: firstInitial.width * 0.06
0166                         anchors.verticalCenter: firstInitial.verticalCenter
0167                         chance: items.turn % 2
0168                         playSecond: items.playSecond
0169                         gameDone: items.gameDone
0170                         pieceBeingMoved: items.pieceBeingMoved
0171                     }
0172                 }
0173             }
0174 
0175             GCText {
0176                 id: firstPieceNumber
0177                 anchors {
0178                     verticalCenter: parent.verticalCenter
0179                     right: parent.right
0180                     rightMargin: parent.width * 0.1
0181                 }
0182                 fontSize: mediumSize
0183                 color: "white"
0184                 horizontalAlignment: Text.AlignHCenter
0185                 property int count: 9
0186                 text: "×%1".arg(count)
0187             }
0188         }
0189 
0190         ListModel {
0191             id: firstPlayerPiecesModel
0192         }
0193 
0194         Rectangle {
0195             id: secondInitial
0196             anchors {
0197                 right: player2score.right
0198                 top: player2score.bottom
0199                 topMargin: player2score.height * 0.5
0200             }
0201             width: firstInitial.width
0202             height: firstInitial.height
0203             visible: items.firstPhase
0204             opacity: 1.0
0205             radius: 10
0206             border.width: 2
0207             border.color: "white"
0208             color: "#373737"
0209 
0210             Repeater {
0211                 id: secondPlayerPieces
0212                 model: secondPlayerPiecesModel
0213                 delegate: secondPieceInitial
0214                 Component {
0215                     id: secondPieceInitial
0216                     Piece {
0217                         id: secondPiece
0218                         state: "2"
0219                         firstPhase: items.firstPhase
0220                         sourceSize.height: Math.min(secondInitial.height * 0.8, secondInitial.width * 0.4)
0221                         x: secondInitial.width * 0.06
0222                         anchors.verticalCenter: secondInitial.verticalCenter
0223                         chance: items.turn % 2
0224                         playSecond: items.playSecond
0225                         gameDone: items.gameDone
0226                         pieceBeingMoved: items.pieceBeingMoved
0227                     }
0228                 }
0229             }
0230 
0231             GCText {
0232                 id: secondPieceNumber
0233                 anchors {
0234                     verticalCenter: parent.verticalCenter
0235                     right: parent.right
0236                     rightMargin: parent.width * 0.1
0237                 }
0238                 fontSize: mediumSize
0239                 color: "white"
0240                 horizontalAlignment: Text.AlignHCenter
0241                 property int count: 9
0242                 text: "×%1".arg(count)
0243             }
0244         }
0245 
0246         ListModel {
0247             id: secondPlayerPiecesModel
0248         }
0249 
0250         // Instruction section starts
0251         GCText {
0252             id: instruction
0253             anchors {
0254                 horizontalCenter: parent.horizontalCenter
0255                 top: parent.top
0256                 topMargin: 5
0257             }
0258             fontSizeMode: Text.Fit
0259             minimumPixelSize: 10
0260             color: "white"
0261             horizontalAlignment: Text.AlignHLeft
0262             width: implicitWidth
0263             height: implicitHeight
0264             z: 2
0265         }
0266 
0267         Rectangle {
0268             id: instructionContainer
0269             anchors.top: instruction.top
0270             anchors.horizontalCenter: parent.horizontalCenter
0271             width: instruction.width + 20
0272             height: instruction.height + 2
0273             opacity: 1.0
0274             radius: 10
0275             border.width: 2
0276             border.color: "white"
0277             color: "#373737"
0278         }
0279         // Instruction section ends
0280 
0281         // Player scores section start
0282         ScoreItem {
0283             id: player2score
0284             player: 2
0285             height: Math.min(background.height / 9, Math.min(background.width / 9, bar.height * 1.2))
0286             width: height * 11 / 8
0287             anchors {
0288                 top: background.top
0289                 topMargin: 5
0290                 right: background.right
0291                 rightMargin: 5
0292             }
0293             playerImageSource: "qrc:/gcompris/src/core/resource/player_2.svg"
0294             backgroundImageSource: Activity.url + "score_1.svg"
0295             playerScaleOriginX: player2score.width
0296             playerItem.source: Activity.url + "black_piece.svg"
0297             playerItem.height: playerItem.parent.height * 0.35
0298             playerItem.anchors.leftMargin: playerItem.parent.height * 0.10
0299             playerItem.anchors.bottomMargin: playerItem.parent.height * 0.10
0300         }
0301 
0302         ScoreItem {
0303             id: player1score
0304             player: 1
0305             height: Math.min(background.height / 9, Math.min(background.width / 9, bar.height * 1.2))
0306             width: height * 11 / 8
0307             anchors {
0308                 top: background.top
0309                 topMargin: 5
0310                 left: background.left
0311                 leftMargin: 5
0312             }
0313             playerImageSource: "qrc:/gcompris/src/core/resource/player_1.svg"
0314             backgroundImageSource: Activity.url + "score_2.svg"
0315             playerItem.source: Activity.url + "white_piece.svg"
0316             playerItem.height: playerItem.parent.height * 0.35
0317             playerItem.anchors.leftMargin: playerItem.parent.height * 0.15
0318             playerItem.anchors.bottomMargin: playerItem.parent.height * 0.10
0319         }
0320         // Player scores section ends
0321 
0322         // Tutorial section starts
0323         Image {
0324             id: tutorialImage
0325             source: background.source
0326             sourceSize.width: width
0327             sourceSize.height: height
0328             fillMode: Image.PreserveAspectCrop
0329             anchors.fill: parent
0330             z: 5
0331             visible: twoPlayer ? false : true
0332             Tutorial {
0333                 id: tutorialSection
0334                 tutorialDetails: Activity.tutorialInstructions
0335                 onSkipPressed: {
0336                         Activity.initLevel()
0337                     tutorialImage.visible = false
0338                 }
0339             }
0340         }
0341         // Tutorial section ends
0342 
0343         DialogHelp {
0344             id: dialogHelp
0345             onClose: home()
0346         }
0347 
0348         Bar {
0349             id: bar
0350             level: items.currentLevel + 1
0351             content: BarEnumContent { value: twoPlayer ? (help | home | reload)
0352                                                        : tutorialImage.visible ? (help | home)
0353                                                        : (help | home | level | reload) }
0354             onHelpClicked: {
0355                 displayDialog(dialogHelp)
0356             }
0357             onPreviousLevelClicked: Activity.previousLevel()
0358             onNextLevelClicked: Activity.nextLevel()
0359             onHomeClicked: home()
0360             onReloadClicked: {
0361                 Activity.reset()
0362             }
0363         }
0364 
0365         Bonus {
0366             id: bonus
0367         }
0368     }
0369 
0370 }