~baltix/gcompris-qt/0.97.1

« back to all changes in this revision

Viewing changes to src/activities/braille_fun/braille_fun.js

  • Committer: Mantas Kriaučiūnas
  • Date: 2020-07-06 18:07:11 UTC
  • Revision ID: baltix@gmail.com-20200706180711-g254osu02cn8bc8p
GCompris-QT 0.97.1 with Lithuanian translation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GCompris - braille_fun.js
 
2
 *
 
3
 * Copyright (C) 2014 Arkit Vora <arkitvora123@gmail.com>
 
4
 *
 
5
 * Authors:
 
6
 *   Srishti Sethi (GTK+ version)
 
7
 *   Arkit Vora <arkitvora123@gmail.com> (Qt Quick port)
 
8
 *
 
9
 *   This program is free software; you can redistribute it and/or modify
 
10
 *   it under the terms of the GNU General Public License as published by
 
11
 *   the Free Software Foundation; either version 3 of the License, or
 
12
 *   (at your option) any later version.
 
13
 *
 
14
 *   This program is distributed in the hope that it will be useful,
 
15
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *   GNU General Public License for more details.
 
18
 *
 
19
 *   You should have received a copy of the GNU General Public License
 
20
 *   along with this program; if not, see <https://www.gnu.org/licenses/>.
 
21
 */
 
22
.pragma library
 
23
.import QtQuick 2.6 as Quick
 
24
.import "qrc:/gcompris/src/core/core.js" as Core
 
25
 
 
26
var currentLevel = 0
 
27
var numberOfLevel = 3
 
28
var items
 
29
var currentQuestion
 
30
var maxSubLevel;
 
31
var set = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
 
32
var questionArray = [];
 
33
 
 
34
var url = "qrc:/gcompris/src/activities/braille_fun/resource/"
 
35
 
 
36
function start(items_ ) {
 
37
    items = items_
 
38
    currentLevel = 0
 
39
    initLevel()
 
40
}
 
41
 
 
42
function stop() {
 
43
    items.animateX.stop()
 
44
}
 
45
 
 
46
function initQuestion() {
 
47
    items.question = questionArray[currentQuestion]
 
48
    items.charBg.clickable(true)
 
49
    items.charBg.clearAllLetters()
 
50
    items.animateX.restart()
 
51
}
 
52
 
 
53
function nextQuestion() {
 
54
    if(++currentQuestion == set.length) {
 
55
        nextLevel()
 
56
    } else {
 
57
        initQuestion()
 
58
    }
 
59
}
 
60
 
 
61
function initLevel() {
 
62
    items.bar.level = currentLevel + 1
 
63
    currentQuestion = 0
 
64
    items.score.numberOfSubLevels = set.length;
 
65
    items.score.currentSubLevel = 0;
 
66
    questionArray = []
 
67
 
 
68
    switch(currentLevel) {
 
69
    case 0:
 
70
        for(var i = 0;  i < set.length; i++) {
 
71
            questionArray[i] = set[i];
 
72
        }
 
73
        break
 
74
    case 1:
 
75
        for(var i = 0;  i < set.length; i++) {
 
76
            questionArray[i] = set[i] +
 
77
                    set[Math.floor(Math.random() * set.length)];
 
78
        }
 
79
        break
 
80
    case 2:
 
81
        for(var i = 0;  i < set.length; i++) {
 
82
            questionArray[i] = set[i] +
 
83
                    set[Math.floor(Math.random() * set.length)] +
 
84
                    set[Math.floor(Math.random() * set.length)];
 
85
        }
 
86
        break
 
87
    }
 
88
 
 
89
    initQuestion()
 
90
    items.cardRepeater.model = currentLevel + 1;
 
91
}
 
92
 
 
93
function nextLevel() {
 
94
    if(numberOfLevel <= ++currentLevel ) {
 
95
        currentLevel = 0
 
96
    }
 
97
    initLevel();
 
98
}
 
99
 
 
100
function previousLevel() {
 
101
    if(--currentLevel < 0) {
 
102
        currentLevel = numberOfLevel - 1
 
103
    }
 
104
    initLevel();
 
105
}