import QtQuick 2.5
import fbx.application 1.0
import QtGraphicalEffects 1.0

Application {
property int rand: Math.random()* 100
property bool win: false

Image{
source: "Background.jpg"
anchors.fill: parent
}

LinearGradient {
anchors.fill: parent
start: Qt.point(0, 0)
end: Qt.point(350, parent.height)
gradient: Gradient {
GradientStop { position: 0.0; color: "#600000bb" }
GradientStop { position: 0.5; color: "#60000077" }
GradientStop { position: 1.0; color: "#60202020" }
}
}

Text {
id: txtRand
focus: true
anchors.centerIn: parent
text: "Trouver quelle est la valeur du nombre aléatoire."
horizontalAlignment: Text.AlignHCenter
color: "#eeffffff"
font.pixelSize: 40

Keys.onReturnPressed: {
if (!txtInput.focus) {
focus = false
txtInput.focus = true
txtInput.selectAll()
}
}
}

TextInput{
id: txtInput
focus: false
anchors.top: txtRand.bottom
anchors.horizontalCenter: txtRand.horizontalCenter
color: "#ddffffff"
selectionColor: "#99909090"
font.pixelSize: 30
text: "Rentrez une valeur comprise entre 0 et 99"

validator: IntValidator{bottom: 0; top: 99;}

onAccepted: {
if((!win))
{
if(rand == text)
{
txtRand.text = "Bien Joué !\nVous pouvez maintenant réessayer."
win = true
}
else if(rand < text)
txtRand.text = "C'est moins"
else if(rand > text)
txtRand.text = "C'est plus"

focus = false
txtRand.focus = true
}

if(win){
win = false
text = "Rentrez une valeur comprise entre 0 et 100"
rand = Math.random()* 100
}
}
}
}