summaryrefslogtreecommitdiffstats
path: root/animals/memory.qml
blob: 583be7fda94b9217d3eebffc628c65c036f8968a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import Qt 4.7
import Qt.labs.gestures 1.0

import "memory.js" as MemoryLogic

Rectangle {
    Component.onCompleted: MemoryLogic.createBoard();

    width: 1200
    height: 500

    id: gameBoard

    property int blockSize: 150;
    property bool started: false;

    gradient: Gradient {
        GradientStop {
            position: 0.00;
            color: "#0FFF1B";
        }
        GradientStop {
            position: 1.00;
            color: "#0070ff";
        }
    }

    // last seen front
    property Animal visibleAnimal;
    // is the current card the first one
    property bool firstAnimal : true;

    function animalFlipped(animal) {
        if (animal == visibleAnimal) {
            return;
        }

        if (firstAnimal) {
            visibleAnimal = animal;
            firstAnimal = false;
        } else {
            firstAnimal = true;
            if (visibleAnimal != animal && visibleAnimal != null) {
                if (visibleAnimal.type != animal.type) {
                    console.log("not the same type");
                    visibleAnimal.hide();
                    animal.hide();
                } else {
                    MemoryLogic.finishedTiles(animal, visibleAnimal);
                }
            }
            visibleAnimal = animal;
        }
    }
}