added range of TextFields

This commit is contained in:
Max 2018-11-26 19:33:59 +01:00
parent 6a25683375
commit 6288bac43a
5 changed files with 106 additions and 48 deletions

View file

@ -8,12 +8,13 @@ Item {
property int sum: 0
property int nextNum: 0
property int lastNum: 0
property int actualNums: 0
property int min: 0
property int actualNumCount: 0
property int min: 1
property int max: 9
property int tickInterval: 1000
property int numCount: 10
property bool negate: false
property bool endPageVisibility: false
property string endPageLabelText: "You Lose!"
signal pageOpened()
@ -21,10 +22,6 @@ Item {
calculator.state = "starting"
}
onNumCountChanged: {
initNums()
}
states: [
State {
name: "starting"
@ -79,6 +76,7 @@ Item {
Component {
id: calculatorEndPageComp
CalculatorEndPage {
id: calculatorEndPage
}
}
@ -117,18 +115,29 @@ Item {
randNum = Math.floor((Math.random()*(range+1))+min)
}
nextNum = randNum
actualNums += 1
calculator.sum += randNum
actualNumCount += 1
}
function start(min, max){
function start(min, max) {
calculator.nextNumber()
calculator.state = "running"
}
function initNums() {
while (nums.length < numCount) {
nums.push(0)
console.log(nums.length)
function reset() {
calculator.state = "starting"
calculator.sum = 0
calculator.actualNumCount = 0
calculator.endPageLabelText = "You Lose!"
calculator.endPageVisibility = false
calculator.lastNum = 0
calculator.nextNum = 0
}
function checkSum(sumInputText) {
if (calculator.sum === parseInt(sumInputText)) {
calculator.endPageLabelText = "You Won!"
}
calculator.endPageVisibility = true
}
}

View file

@ -7,43 +7,80 @@ Page {
signal pageOpened()
onPageOpened: {
rectAnim.start()
startRectAnim2.start()
TextField {
id: sumInput
placeholderText: "sum"
visible: !won.visible
validator: IntValidator {bottom: -1000000; top: 1000000;}
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
topMargin: parent.height * 0.1
}
Keys.onReturnPressed: calculator.checkSum(sumInput.text)
}
Label {
id: won
text: calculator.endPageLabelText
font.pixelSize: parent.width * 0.2
visible: calculator.endPageVisibility
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
topMargin: parent.height * 0.2
}
}
Rectangle {
id: rect
anchors.fill: parent
property string col: "darkgreen"
color: col
/*
Row {
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
bottomMargin: parent.height * 0.2
}
height: childrenRect.height
width: childrenRect.width
spacing: root.height * 0.1
Timer {
id: startRectAnim2
interval: 5000
running: false
repeat: false
onTriggered: {
rectAnim2.start()
RoundButton {
id: homeButton
height: parent.width * 0.2
width: height
text: "home"
onClicked: {
game.state = "starting"
calculator.reset()
}
}
ColorAnimation {
id: rectAnim
target: rect
property: "color"
from: "darkGreen"
to: "yellow"
duration: 5000
RoundButton {
id: startButtons
height: parent.width * 0.2
width: height
text: "start"
onClicked: {
calculator.reset()
calculator.state = "starting"
}
}
ColorAnimation {
id: rectAnim2
target: rect
property: "color"
from: "yellow"
to: "darkRed"
duration: 5000
}
*/
RoundButton {
id: homeButton
height: parent.width * 0.2
width: height
text: "home"
visible: endPageVisibility
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
bottomMargin: parent.height * 0.1
}
onClicked: {
calculator.reset()
calculator.state = "starting"
}
}
}

View file

@ -65,7 +65,7 @@ Page {
running: calculator.state === "running"
onTriggered: {
if(calculator.actualNums < calculator.numCount){
if (calculator.actualNumCount < calculator.numCount) {
nextNumber()
tick.start()
}

View file

@ -32,40 +32,48 @@ Page {
id: tickInterval
text: calculator.tickInterval
placeholderText: "interval"
validator: IntValidator {bottom: 1; top: 100000;}
horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
}
TextField {
id: numCount
text: calculator.numCount
placeholderText: "numbercount"
validator: IntValidator {bottom: 1; top: 100000;}
horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
}
TextField {
id: min
text: calculator.min
placeholderText: "min"
validator: IntValidator {bottom: -100000; top: 100000;}
horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
}
TextField {
id: max
text: calculator.max
placeholderText: "max"
validator: IntValidator {bottom: -100000; top: 100000;}
horizontalAlignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
Keys.onReturnPressed: root.start()
}
RoundButton {
@ -78,11 +86,15 @@ Page {
Layout.leftMargin: parent.width * 0.05
Layout.rightMargin: parent.width * 0.05
onClicked: {
updateVars()
calculator.start()
root.start()
}
}
}
function start() {
root.updateVars()
calculator.start()
}
function updateVars() {
calculator.tickInterval = tickInterval.text
calculator.numCount = numCount.text

View file

@ -13,11 +13,11 @@ Window {
id: game
anchors.fill: parent
state: "idle"
state: "starting"
states: [
State {
name: "idle"
name: "starting"
PropertyChanges {
target: mainStack
currPage: startPageComp