Warning, /education/gcompris/src/activities/oware/Oware.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - Oware.qml 0002 * 0003 * SPDX-FileCopyrightText: 2021 Harsh Kumar <hadron43@yahoo.com> 0004 * 0005 * Authors: 0006 * Harsh Kumar <hadron43@yahoo.com> 0007 * Timothée Giet <animtim@gmail.com> (redesign) 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 import QtQuick 2.12 0012 import GCompris 1.0 0013 0014 import "../../core" 0015 import "oware.js" as Activity 0016 0017 ActivityBase { 0018 id: activity 0019 0020 property bool twoPlayers: false 0021 0022 onStart: focus = true 0023 onStop: {} 0024 0025 pageComponent: Image { 0026 id: background 0027 anchors.fill: parent 0028 source: "qrc:/gcompris/src/activities/hanoi_real/resource/background.svg" 0029 sourceSize.width: width 0030 sourceSize.height: height 0031 fillMode: Image.PreserveAspectCrop 0032 signal start 0033 signal stop 0034 0035 Component.onCompleted: { 0036 activity.start.connect(start) 0037 activity.stop.connect(stop) 0038 } 0039 0040 // Add here the QML items you need to access in javascript 0041 QtObject { 0042 id: items 0043 property Item main: activity.main 0044 property alias background: background 0045 property alias bonus: bonus 0046 property alias board: board 0047 property alias player1score: player1score 0048 property alias player2score: player2score 0049 property alias hand1: hand1 0050 property alias hand2: hand2 0051 property alias animationSeed: animationSeed 0052 property alias teleportAnimation: teleportAnimation 0053 property alias delayAnimation: delayAnimation 0054 property alias captureAnimation: captureAnimation 0055 property alias invalidMoveAnimation: invalidMoveAnimation 0056 property alias instructionArea: instructionArea 0057 property alias selectedPit: teleportAnimation.fromPit 0058 property bool isDistributionAnimationPlaying: false 0059 property bool forceStop: false 0060 property bool gameOver: false 0061 property int playerWithFirstMove: Player.PLAYER2 0062 } 0063 0064 onStart: { Activity.start(items, twoPlayers) } 0065 onStop: { 0066 stopAllAnimation() 0067 Activity.stop() 0068 } 0069 0070 Item { 0071 id: topPanel 0072 anchors { 0073 top: parent.top 0074 left: parent.left 0075 right: parent.right 0076 } 0077 height: Math.min(parent.height / 6, parent.width / 6) 0078 0079 ScoreItem { 0080 id: player1score 0081 player: 1 0082 height: topPanel.height / 1.5 0083 width: height*11/8 0084 anchors { 0085 top: topPanel.top 0086 topMargin: 5 0087 left: topPanel.left 0088 leftMargin: 5 0089 } 0090 playerImageSource: "qrc:/gcompris/src/core/resource/player_1.svg" 0091 backgroundImageSource: "qrc:/gcompris/src/activities/bargame/resource/score_1.svg" 0092 playerItem.source: Activity.url + "seed.svg" 0093 playerItem.height: playerItem.parent.height * 0.35 0094 playerItem.anchors.leftMargin: playerItem.parent.height * 0.15 0095 playerItem.anchors.bottomMargin: playerItem.parent.height * 0.10 0096 } 0097 0098 Pit { 0099 id: hand1 0100 responsive: false 0101 label: false 0102 player: 1 0103 seeds: 0 0104 visible: player1score.playersTurn === true 0105 width: topPanel.height - 2 * anchors.topMargin 0106 anchors { 0107 top: topPanel.top 0108 topMargin: 10 0109 left: player1score.right 0110 leftMargin: 10 + 0.4 * player1score.width 0111 } 0112 } 0113 0114 Rectangle { 0115 id: instructionArea 0116 0117 visible: false 0118 color: "#373737" 0119 height: instruction.contentHeight * 1.1 0120 anchors { 0121 left: hand1.right 0122 right: hand2.left 0123 leftMargin: 20 * ApplicationInfo.ratio 0124 rightMargin: 20 * ApplicationInfo.ratio 0125 verticalCenter: parent.verticalCenter 0126 } 0127 0128 signal start(string message) 0129 onStart: { 0130 instruction.text = message 0131 instructionArea.visible = true 0132 instructionPauseAnimation.running = true 0133 } 0134 PauseAnimation { 0135 id: instructionPauseAnimation 0136 duration: 1000 0137 onStopped: { 0138 instructionArea.visible = false 0139 } 0140 } 0141 0142 GCText { 0143 id: instruction 0144 wrapMode: TextEdit.WordWrap 0145 fontSize: tinySize 0146 horizontalAlignment: Text.Center 0147 width: parent.width * 0.9 0148 color: "white" 0149 anchors.centerIn: instructionArea 0150 } 0151 } 0152 0153 Pit { 0154 id: hand2 0155 responsive: false 0156 label: false 0157 player: 2 0158 seeds: 0 0159 visible: player2score.playersTurn === true 0160 width: topPanel.height - 2 * anchors.topMargin 0161 anchors { 0162 top: topPanel.top 0163 topMargin: 10 0164 right: player2score.left 0165 rightMargin: 10 + 0.4 * player2score.width 0166 } 0167 } 0168 0169 ScoreItem { 0170 id: player2score 0171 player: 2 0172 height: topPanel.height / 1.5 0173 width: height*11/8 0174 anchors { 0175 top: topPanel.top 0176 topMargin: 5 0177 right: topPanel.right 0178 rightMargin: 5 0179 } 0180 playerImageSource: "qrc:/gcompris/src/core/resource/player_2.svg" 0181 backgroundImageSource: "qrc:/gcompris/src/activities/bargame/resource/score_2.svg" 0182 playerItem.source: Activity.url + "seed.svg" 0183 playerItem.height: playerItem.parent.height * 0.35 0184 playerItem.anchors.leftMargin: playerItem.parent.height * 0.10 0185 playerItem.anchors.bottomMargin: playerItem.parent.height * 0.10 0186 playerScaleOriginX: player2score.width 0187 } 0188 } 0189 0190 Item { 0191 id: layoutArea 0192 anchors { 0193 top: topPanel.bottom 0194 left: parent.left 0195 right: parent.right 0196 bottom: bar.top 0197 bottomMargin: bar.height * 0.2 0198 } 0199 } 0200 0201 Board { 0202 id: board 0203 anchors { 0204 horizontalCenter: layoutArea.horizontalCenter 0205 verticalCenter: layoutArea.verticalCenter 0206 } 0207 width: Math.min(layoutArea.width / 6, layoutArea.height / 4) * 6 0208 } 0209 0210 Image { 0211 id: animationSeed 0212 source: Activity.url + "seed.svg" 0213 visible: false 0214 height: width 0215 sourceSize.width: width 0216 property Pit fromPit 0217 property Pit toPit 0218 property int animationDurationMillis: 750 0219 0220 signal startAnimation(Pit from, Pit to) 0221 signal stop 0222 0223 onStartAnimation: { 0224 items.isDistributionAnimationPlaying = true 0225 animationSeed.fromPit = from 0226 animationSeed.toPit = to 0227 0228 var fromPos = Activity.getGlobalPos(animationSeed.fromPit) 0229 x = fromPos[0] + animationSeed.fromPit.width / 2 0230 y = fromPos[1] + animationSeed.fromPit.width / 2 0231 0232 var toPos = Activity.getGlobalPos(animationSeed.toPit) 0233 xAnim.to = toPos[0] + animationSeed.toPit.width / 2 0234 yAnim.to = toPos[1] + animationSeed.toPit.width / 2 0235 0236 width = animationSeed.fromPit.getSeedSize() 0237 sizeAnim.to = animationSeed.toPit.getSeedSize() 0238 0239 visible = true 0240 animationSeed.fromPit.seeds = animationSeed.fromPit.seeds - 1 0241 parallelAnimation.running = true 0242 } 0243 0244 ParallelAnimation { 0245 id: parallelAnimation 0246 alwaysRunToEnd: true 0247 NumberAnimation { 0248 id: xAnim 0249 target: animationSeed 0250 property: "x" 0251 duration: animationSeed.animationDurationMillis 0252 } 0253 NumberAnimation { 0254 id: yAnim 0255 target: animationSeed 0256 property: "y" 0257 duration: animationSeed.animationDurationMillis 0258 } 0259 PropertyAnimation { 0260 id: sizeAnim 0261 target: animationSeed 0262 property: "width" 0263 duration: animationSeed.animationDurationMillis 0264 } 0265 0266 onStopped: { 0267 audioEffects.play("qrc:/gcompris/src/core/resource/sounds/scroll.wav") 0268 animationSeed.visible = false 0269 animationSeed.toPit.seeds = animationSeed.toPit.seeds + 1 0270 if(items.forceStop || items.gameOver) 0271 return 0272 Activity.redistribute() 0273 } 0274 } 0275 } 0276 0277 Item { 0278 id: teleportAnimation 0279 property Pit fromPit 0280 property Pit toPit 0281 property int noOfSeeds 0282 property int animationDurationMillis: 750 0283 0284 signal start(Pit from, Pit to) 0285 0286 onStart: { 0287 teleportAnimation.fromPit = from 0288 teleportAnimation.toPit = to 0289 noOfSeeds = teleportAnimation.fromPit.seeds 0290 teleportSequenceAnimation.running = true 0291 } 0292 0293 SequentialAnimation { 0294 id: teleportSequenceAnimation 0295 PropertyAnimation { 0296 id: fromHighlightOnAnim 0297 target: teleportAnimation.fromPit 0298 property: "selected" 0299 to: true 0300 } 0301 PauseAnimation { duration: teleportAnimation.animationDurationMillis } 0302 PropertyAnimation { 0303 id: fromReduceAnim 0304 target: teleportAnimation.fromPit 0305 property: "seeds" 0306 to: 0 0307 } 0308 PropertyAnimation { 0309 id: toIncreaseAnim 0310 target: teleportAnimation.toPit 0311 property: "seeds" 0312 to: teleportAnimation.noOfSeeds 0313 } 0314 PauseAnimation { duration: teleportAnimation.animationDurationMillis } 0315 PauseAnimation { duration: teleportAnimation.animationDurationMillis } 0316 0317 onStopped: { 0318 if(items.forceStop || items.gameOver) { 0319 teleportAnimation.fromPit.selected = false; 0320 return; 0321 } 0322 Activity.redistribute(); 0323 } 0324 } 0325 } 0326 0327 Item { 0328 id: delayAnimation 0329 property int player 0330 property int index 0331 0332 signal start(var player_, var index_) 0333 0334 onStart: { 0335 player = player_ 0336 index = index_ 0337 pauseAnimation.running = true 0338 } 0339 0340 PauseAnimation { 0341 id: pauseAnimation 0342 duration: 750 0343 0344 onStopped: { 0345 if(items.forceStop || items.gameOver) 0346 return 0347 Activity.processMove(delayAnimation.player, delayAnimation.index) 0348 } 0349 } 0350 } 0351 0352 Item { 0353 id: captureAnimation 0354 property Pit fromPit 0355 property ScoreItem score 0356 property int finalScore 0357 property string originalHighlightColor 0358 0359 signal start(Pit fromPit_, ScoreItem score_) 0360 0361 onStart: { 0362 fromPit = fromPit_ 0363 score = score_ 0364 finalScore = fromPit_.seeds + score_.playerScore 0365 originalHighlightColor = fromPit_.highlightColor 0366 captureSequentialAnimation.running = true 0367 } 0368 0369 SequentialAnimation { 0370 id: captureSequentialAnimation 0371 PropertyAnimation { 0372 target: captureAnimation.fromPit 0373 property: "highlightColor" 0374 to: "#e77936" //orange 0375 } 0376 PropertyAnimation { 0377 target: captureAnimation.fromPit 0378 property: "highlight" 0379 to: true 0380 } 0381 PauseAnimation { duration: 500 } 0382 PropertyAnimation { 0383 target: captureAnimation.fromPit 0384 property: "seeds" 0385 to: 0 0386 } 0387 PropertyAnimation { 0388 target: captureAnimation.score 0389 property: "playerScore" 0390 to: captureAnimation.finalScore 0391 } 0392 PropertyAnimation { 0393 target: captureAnimation.fromPit 0394 property: "highlightColor" 0395 to: captureAnimation.originalHighlightColor 0396 } 0397 PropertyAnimation { 0398 target: captureAnimation.fromPit 0399 property: "highlight" 0400 to: false 0401 } 0402 PauseAnimation { duration: 500 } 0403 onStopped: { 0404 if(items.forceStop || items.gameOver) 0405 return 0406 Activity.checkCapture() 0407 } 0408 } 0409 } 0410 0411 Item { 0412 id: invalidMoveAnimation 0413 property Pit targetPit 0414 property string originalHighlightColor 0415 0416 signal start(Pit _targetPit) 0417 0418 onStart: { 0419 items.isDistributionAnimationPlaying = true 0420 targetPit = _targetPit 0421 originalHighlightColor = targetPit.highlightColor 0422 targetPit.highlightColor = "#DF543D" //red 0423 targetPit.highlight = true 0424 invalidMovePauseAnimation.running = true 0425 } 0426 0427 PauseAnimation { 0428 id: invalidMovePauseAnimation 0429 duration: 750 0430 onStopped: { 0431 invalidMoveAnimation.targetPit.highlightColor = invalidMoveAnimation.originalHighlightColor 0432 invalidMoveAnimation.targetPit.highlight = false 0433 items.isDistributionAnimationPlaying = false 0434 } 0435 } 0436 } 0437 0438 function stopAllAnimation() { 0439 items.forceStop = true 0440 invalidMovePauseAnimation.complete() 0441 parallelAnimation.complete() 0442 teleportSequenceAnimation.complete() 0443 pauseAnimation.complete() 0444 captureSequentialAnimation.complete() 0445 items.forceStop = false 0446 } 0447 0448 DialogHelp { 0449 id: dialogHelp 0450 onClose: home() 0451 } 0452 0453 Bar { 0454 id: bar 0455 level: items.currentLevel + 1 0456 content: BarEnumContent { value: help | home | reload } 0457 onHelpClicked: { 0458 displayDialog(dialogHelp) 0459 } 0460 onHomeClicked: activity.home() 0461 onReloadClicked: { 0462 stopAllAnimation() 0463 Activity.initLevel() 0464 } 0465 } 0466 0467 Bonus { 0468 id: bonus 0469 } 0470 } 0471 0472 }