Warning, /education/marble/examples/cpp/marble-game/ClickOnThat.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2014 Abhinav Gangwar <abhgang@gmail.com>
0004 //
0005 
0006 
0007 import QtQuick 2.0
0008 import QtQuick.Controls 1.2
0009 import QtQuick.Controls.Styles 1.2
0010 
0011 Rectangle {
0012     id: clickOnThat
0013     objectName: "clickOnThat"
0014 
0015     color: "#C2D1B2"
0016 
0017     signal nextQuestionRequested()
0018     signal gameQuitRequested()
0019     signal answerDisplayRequested()
0020     signal questionsTimeout()
0021 
0022     property int panelWidth: 200
0023     property int panelHeight: 600
0024 
0025     width: panelWidth
0026     height: panelHeight
0027 
0028     // Display the button to show correct Answer
0029     property bool showCorrectAnswer: false
0030 
0031     // Result Display
0032     property bool showResult: false
0033     property string result: qsTr("Undetermined")
0034     property int score: 0
0035     property bool scoreDetermined: false
0036     property int totalQuestionsAsked: 0  // Total no. of questions that user is asked
0037     property int maximumQuestions: 0
0038 
0039     property bool showQuestion: false
0040     property string countryName: qsTr("Undetermined")
0041 
0042     Rectangle {
0043         id: gameDescription
0044         width: panelWidth
0045         height: panelHeight/10
0046         anchors.top: parent.top
0047         anchors.topMargin: 10
0048 
0049         color: "#C2D1B2"
0050 
0051         Rectangle {
0052             id: gameName
0053             width: parent.width/2
0054             height: parent.height
0055             anchors.left: parent.left
0056             anchors.leftMargin: 5
0057             border.width: 1
0058             border.color: "#000000"
0059 
0060             radius: 6
0061             smooth: true
0062             color: "#696969"
0063 
0064             Text {
0065                 width: parent.width
0066                 wrapMode: Text.WordWrap
0067                 horizontalAlignment: Text.AlignHCenter
0068                 anchors.verticalCenter: parent.verticalCenter
0069                 color: "white"
0070 
0071                 text: qsTr("Click On That Country")
0072             }
0073         }
0074 
0075         CustomButton {
0076             id: quitGameButton
0077             buttonWidth: parent.width/2
0078             buttonHeight: parent.height
0079 
0080             normalColor: "#696969"
0081             borderColor: "#000000"
0082 
0083             labelText: qsTr("Quit Game")
0084             labelSize: parent.width/15
0085             labelColor: "white"
0086 
0087             anchors.left: gameName.right
0088             anchors.leftMargin: 5
0089 
0090             anchors.top: parent.top
0091             anchors.right: parent.right
0092             anchors.rightMargin: 5
0093 
0094             onButtonClick: {
0095                 gameQuitRequested();
0096                 resetOptions();
0097             }
0098         }
0099     }
0100 
0101     Rectangle {
0102         id: question
0103 
0104         anchors.top: gameDescription.bottom
0105         anchors.topMargin: parent.height/17
0106         anchors.left: parent.left
0107         anchors.leftMargin: 10
0108         anchors.right: parent.right
0109         anchors.rightMargin: 10
0110         height: panelHeight/8
0111         color: "#A9A9A9"
0112         radius: width*0.5
0113         smooth: true
0114         border.width: 1
0115         border.color: "#696969"
0116 
0117         visible: true
0118 
0119         Text {
0120             id: questionText
0121             color: "white"
0122             width: parent.width
0123             height: parent.height/2
0124             horizontalAlignment: Text.AlignHCenter
0125             font.pixelSize: parent.height/5
0126             text: qsTr("Click on")
0127         }
0128 
0129         Text {
0130             id: country
0131             anchors.top: questionText.bottom
0132             anchors.topMargin: 5
0133             width: parent.width
0134             height: parent.height/2
0135             horizontalAlignment: Text.AlignHCenter
0136 
0137             font.pixelSize: parent.height/5
0138             font.bold: true
0139             color: "white"
0140             text: qsTr(countryName)
0141         }
0142     }
0143 
0144     CustomButton {
0145         id: nextButton
0146         anchors.top: question.bottom
0147         anchors.topMargin: 20
0148         anchors.horizontalCenter: parent.horizontalCenter
0149         buttonWidth: panelWidth*4/5
0150         buttonHeight: panelHeight/14
0151         normalColor: "#696969"
0152         borderColor: "#000000"
0153 
0154         labelText: qsTr("Next")
0155         labelColor: "#ffffff";
0156         onButtonClick: {
0157             nextQuestionRequested()
0158         }
0159     }
0160 
0161     Rectangle {
0162         id: resultDisplay
0163 
0164         anchors.left: parent.left
0165         anchors.leftMargin: 20
0166         anchors.right: parent.right
0167         anchors.rightMargin: 20
0168         anchors.top: nextButton.bottom
0169         anchors.topMargin: 20
0170 
0171         color: "#80FFFF"
0172         border.width: 1
0173         border.color: "#262626"
0174         radius: 40
0175         smooth: true
0176 
0177         height: panelHeight/6
0178 
0179         visible: showResult
0180 
0181         Text {
0182             id: text
0183             anchors.left: parent.left
0184             anchors.leftMargin: 25
0185             anchors.right: parent.right
0186             anchors.rightMargin: 5
0187             anchors.verticalCenter: parent.verticalCenter
0188 
0189             wrapMode: Text.WordWrap
0190             text: qsTr(result)
0191         }
0192     }
0193 
0194     CustomButton {
0195         id: viewCorrectAnswer
0196 
0197         anchors.top: resultDisplay.bottom
0198         anchors.topMargin: 20
0199         anchors.left: parent.left
0200         anchors.leftMargin: 10
0201         anchors.right: parent.right
0202         anchors.rightMargin: 10
0203 
0204         buttonHeight: panelHeight*5/(6*14)
0205         borderColor: "#696969"
0206         labelColor: "green"
0207         labelText: qsTr("View Answer")
0208 
0209         visible: showCorrectAnswer
0210 
0211         onButtonClick: {
0212             answerDisplayRequested();
0213         }
0214     }
0215 
0216     Rectangle {
0217         id: scoreDisplay
0218 
0219         anchors.left: parent.left
0220         anchors.leftMargin:10
0221         anchors.right: parent.right
0222         anchors.rightMargin: 10
0223         anchors.top: viewCorrectAnswer.bottom
0224         anchors.topMargin: 20
0225         border.width: 1
0226         border.color: "#696969"
0227 
0228         height: panelHeight/8
0229 
0230         color: "#808080"
0231 
0232         Text {
0233             id: scoreContent
0234             color: "white"
0235             width: parent.width
0236             horizontalAlignment: Text.AlignHCenter
0237             font.pixelSize: 18
0238             text: {
0239                 qsTr("Your Progress \n\n" + score + "/" + totalQuestionsAsked)
0240             }
0241         }
0242     }
0243 
0244     Timer {
0245         id: timer
0246         interval: 700
0247         repeat: false
0248         onTriggered: {
0249             questionsTimeout();
0250         }
0251     }
0252 
0253     onQuestionsTimeout: {
0254         timer.stop();
0255         showCorrectAnswer = false;
0256         nextQuestionRequested();
0257     }
0258 
0259     function initGame() {
0260         score = 0;
0261         totalQuestionsAsked = 0;
0262     }
0263 
0264     function resetOptions() {
0265         result = "Undetermined";
0266         showResult = false;
0267         showQuestion = false;
0268     }
0269 
0270     function setQuestion( name ) {
0271         if ( maximumQuestions > 0 ) {
0272             resetOptions();
0273             ++totalQuestionsAsked;
0274             countryName = name;
0275             scoreDetermined = false;
0276             showQuestion = true;
0277         }
0278         else {
0279             gameQuitRequested()
0280         }
0281         maximumQuestions = maximumQuestions - 1;
0282     }
0283 
0284     function displayResult( correct ) {
0285         showResult = true
0286         if ( correct && !scoreDetermined ) {
0287             ++score
0288             scoreDetermined = true;
0289             result = "<font face=\"verdana\" size=\"4\" color=\"#00ff00\"><b>Hooray !! Right Answer</b></font>"
0290             timer.start();
0291         }
0292         else {
0293             /**
0294              * Stop timer ( so that the game
0295              * doesn't switch to next question
0296              * automatically ) and let the user
0297              * choose whether he/she wants
0298              * to see the correct answer.
0299              **/
0300             if ( timer.running == true ) {
0301                 timer.stop();
0302             }
0303 
0304             result = "<p align=\"center\"> <font face=\"verdana\" size=\"4\" color=\"#ff0000\"><b>Oops, Wrong Answer</b></font> </p>"
0305             showCorrectAnswer = true;
0306         }
0307     }
0308     
0309     function setMaximumQuestions( questionsCount ) {
0310         maximumQuestions = questionsCount;
0311     }
0312 }