added range of TextFields
This commit is contained in:
parent
6a25683375
commit
6288bac43a
5 changed files with 106 additions and 48 deletions
|
@ -8,12 +8,13 @@ Item {
|
||||||
property int sum: 0
|
property int sum: 0
|
||||||
property int nextNum: 0
|
property int nextNum: 0
|
||||||
property int lastNum: 0
|
property int lastNum: 0
|
||||||
property int actualNums: 0
|
property int actualNumCount: 0
|
||||||
property int min: 0
|
property int min: 1
|
||||||
property int max: 9
|
property int max: 9
|
||||||
property int tickInterval: 1000
|
property int tickInterval: 1000
|
||||||
property int numCount: 10
|
property int numCount: 10
|
||||||
property bool negate: false
|
property bool endPageVisibility: false
|
||||||
|
property string endPageLabelText: "You Lose!"
|
||||||
|
|
||||||
signal pageOpened()
|
signal pageOpened()
|
||||||
|
|
||||||
|
@ -21,10 +22,6 @@ Item {
|
||||||
calculator.state = "starting"
|
calculator.state = "starting"
|
||||||
}
|
}
|
||||||
|
|
||||||
onNumCountChanged: {
|
|
||||||
initNums()
|
|
||||||
}
|
|
||||||
|
|
||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: "starting"
|
name: "starting"
|
||||||
|
@ -79,6 +76,7 @@ Item {
|
||||||
Component {
|
Component {
|
||||||
id: calculatorEndPageComp
|
id: calculatorEndPageComp
|
||||||
CalculatorEndPage {
|
CalculatorEndPage {
|
||||||
|
id: calculatorEndPage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,18 +115,29 @@ Item {
|
||||||
randNum = Math.floor((Math.random()*(range+1))+min)
|
randNum = Math.floor((Math.random()*(range+1))+min)
|
||||||
}
|
}
|
||||||
nextNum = randNum
|
nextNum = randNum
|
||||||
actualNums += 1
|
calculator.sum += randNum
|
||||||
|
actualNumCount += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function start(min, max){
|
function start(min, max) {
|
||||||
calculator.nextNumber()
|
calculator.nextNumber()
|
||||||
calculator.state = "running"
|
calculator.state = "running"
|
||||||
}
|
}
|
||||||
|
|
||||||
function initNums() {
|
function reset() {
|
||||||
while (nums.length < numCount) {
|
calculator.state = "starting"
|
||||||
nums.push(0)
|
calculator.sum = 0
|
||||||
console.log(nums.length)
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,43 +7,80 @@ Page {
|
||||||
|
|
||||||
signal pageOpened()
|
signal pageOpened()
|
||||||
|
|
||||||
onPageOpened: {
|
TextField {
|
||||||
rectAnim.start()
|
id: sumInput
|
||||||
startRectAnim2.start()
|
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
|
Row {
|
||||||
anchors.fill: parent
|
anchors {
|
||||||
property string col: "darkgreen"
|
horizontalCenter: parent.horizontalCenter
|
||||||
color: col
|
bottom: parent.bottom
|
||||||
|
bottomMargin: parent.height * 0.2
|
||||||
|
}
|
||||||
|
height: childrenRect.height
|
||||||
|
width: childrenRect.width
|
||||||
|
spacing: root.height * 0.1
|
||||||
|
|
||||||
Timer {
|
RoundButton {
|
||||||
id: startRectAnim2
|
id: homeButton
|
||||||
interval: 5000
|
height: parent.width * 0.2
|
||||||
running: false
|
width: height
|
||||||
repeat: false
|
text: "home"
|
||||||
|
onClicked: {
|
||||||
onTriggered: {
|
game.state = "starting"
|
||||||
rectAnim2.start()
|
calculator.reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorAnimation {
|
RoundButton {
|
||||||
id: rectAnim
|
id: startButtons
|
||||||
target: rect
|
height: parent.width * 0.2
|
||||||
property: "color"
|
width: height
|
||||||
from: "darkGreen"
|
text: "start"
|
||||||
to: "yellow"
|
onClicked: {
|
||||||
duration: 5000
|
calculator.reset()
|
||||||
|
calculator.state = "starting"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ColorAnimation {
|
}
|
||||||
id: rectAnim2
|
*/
|
||||||
target: rect
|
|
||||||
property: "color"
|
RoundButton {
|
||||||
from: "yellow"
|
id: homeButton
|
||||||
to: "darkRed"
|
height: parent.width * 0.2
|
||||||
duration: 5000
|
width: height
|
||||||
|
text: "home"
|
||||||
|
visible: endPageVisibility
|
||||||
|
anchors {
|
||||||
|
horizontalCenter: parent.horizontalCenter
|
||||||
|
bottom: parent.bottom
|
||||||
|
bottomMargin: parent.height * 0.1
|
||||||
|
}
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
calculator.reset()
|
||||||
|
calculator.state = "starting"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ Page {
|
||||||
running: calculator.state === "running"
|
running: calculator.state === "running"
|
||||||
|
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
if(calculator.actualNums < calculator.numCount){
|
if (calculator.actualNumCount < calculator.numCount) {
|
||||||
nextNumber()
|
nextNumber()
|
||||||
tick.start()
|
tick.start()
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,40 +32,48 @@ Page {
|
||||||
id: tickInterval
|
id: tickInterval
|
||||||
text: calculator.tickInterval
|
text: calculator.tickInterval
|
||||||
placeholderText: "interval"
|
placeholderText: "interval"
|
||||||
|
validator: IntValidator {bottom: 1; top: 100000;}
|
||||||
horizontalAlignment: Qt.AlignHCenter
|
horizontalAlignment: Qt.AlignHCenter
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.leftMargin: parent.width * 0.05
|
Layout.leftMargin: parent.width * 0.05
|
||||||
Layout.rightMargin: parent.width * 0.05
|
Layout.rightMargin: parent.width * 0.05
|
||||||
|
Keys.onReturnPressed: root.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
TextField {
|
TextField {
|
||||||
id: numCount
|
id: numCount
|
||||||
text: calculator.numCount
|
text: calculator.numCount
|
||||||
placeholderText: "numbercount"
|
placeholderText: "numbercount"
|
||||||
|
validator: IntValidator {bottom: 1; top: 100000;}
|
||||||
horizontalAlignment: Qt.AlignHCenter
|
horizontalAlignment: Qt.AlignHCenter
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.leftMargin: parent.width * 0.05
|
Layout.leftMargin: parent.width * 0.05
|
||||||
Layout.rightMargin: parent.width * 0.05
|
Layout.rightMargin: parent.width * 0.05
|
||||||
|
Keys.onReturnPressed: root.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
TextField {
|
TextField {
|
||||||
id: min
|
id: min
|
||||||
text: calculator.min
|
text: calculator.min
|
||||||
placeholderText: "min"
|
placeholderText: "min"
|
||||||
|
validator: IntValidator {bottom: -100000; top: 100000;}
|
||||||
horizontalAlignment: Qt.AlignHCenter
|
horizontalAlignment: Qt.AlignHCenter
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.leftMargin: parent.width * 0.05
|
Layout.leftMargin: parent.width * 0.05
|
||||||
Layout.rightMargin: parent.width * 0.05
|
Layout.rightMargin: parent.width * 0.05
|
||||||
|
Keys.onReturnPressed: root.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
TextField {
|
TextField {
|
||||||
id: max
|
id: max
|
||||||
text: calculator.max
|
text: calculator.max
|
||||||
placeholderText: "max"
|
placeholderText: "max"
|
||||||
|
validator: IntValidator {bottom: -100000; top: 100000;}
|
||||||
horizontalAlignment: Qt.AlignHCenter
|
horizontalAlignment: Qt.AlignHCenter
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.leftMargin: parent.width * 0.05
|
Layout.leftMargin: parent.width * 0.05
|
||||||
Layout.rightMargin: parent.width * 0.05
|
Layout.rightMargin: parent.width * 0.05
|
||||||
|
Keys.onReturnPressed: root.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
RoundButton {
|
RoundButton {
|
||||||
|
@ -78,11 +86,15 @@ Page {
|
||||||
Layout.leftMargin: parent.width * 0.05
|
Layout.leftMargin: parent.width * 0.05
|
||||||
Layout.rightMargin: parent.width * 0.05
|
Layout.rightMargin: parent.width * 0.05
|
||||||
onClicked: {
|
onClicked: {
|
||||||
updateVars()
|
root.start()
|
||||||
calculator.start()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function start() {
|
||||||
|
root.updateVars()
|
||||||
|
calculator.start()
|
||||||
|
}
|
||||||
|
|
||||||
function updateVars() {
|
function updateVars() {
|
||||||
calculator.tickInterval = tickInterval.text
|
calculator.tickInterval = tickInterval.text
|
||||||
calculator.numCount = numCount.text
|
calculator.numCount = numCount.text
|
||||||
|
|
4
main.qml
4
main.qml
|
@ -13,11 +13,11 @@ Window {
|
||||||
id: game
|
id: game
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
state: "idle"
|
state: "starting"
|
||||||
|
|
||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: "idle"
|
name: "starting"
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: mainStack
|
target: mainStack
|
||||||
currPage: startPageComp
|
currPage: startPageComp
|
||||||
|
|
Loading…
Reference in a new issue