Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick
- import QtQuick.Window
- import QtQuick.Controls
- import QtQml.Models 2.2
- Window {
- property int money: 100
- width: 640
- height: 280
- visible: true
- title: qsTr("Roll the Dice")
- id: window
- Column {
- width: parent.width
- height: parent.height
- id: mainColumn
- Row {
- anchors.horizontalCenter: parent.horizontalCenter
- width: parent.width
- height: parent.height / 8
- id: headerRow
- Text {
- text: "Bet: "
- font.pointSize: parent.parent.height/20
- font.family: "Calibri"
- }
- TextField {
- id: bet
- placeholderText: "0"
- font.pointSize: parent.parent.height/20
- font.family: "Calibri"
- }
- Text {
- text: "Difficulty(easy,medium,hard): "
- font.pointSize: parent.parent.height/20
- font.family: "Calibri"
- }
- TextField {
- id: dif
- placeholderText: "eg: easy"
- font.pointSize: parent.parent.height/20
- font.family: "Calibri"
- }
- Text {
- id: mone
- text: "Money: 100"
- font.pointSize: parent.parent.height/20
- font.family: "Calibri"
- }
- }
- Row {
- Button {
- id: play
- x: parent.width
- background: Rectangle {
- radius: 100
- color: "lightGreen"
- }
- text: "Play"
- anchors.centerIn: parent.Center
- font.pointSize: parent.parent.height/20
- width: parent.parent.width/3
- height: parent.parent.height/7
- onClicked : {
- let win = false;
- let mode = dif.text;
- let work = true;
- function getRandomInt(min, max) {
- min = Math.ceil(min);
- max = Math.floor(max);
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- if (money > 0) {
- switch(mode) {
- case "easy":
- if (getRandomInt(1,3) === 1) {
- money += parseInt(bet.text) * 2;
- win = true;
- }
- break;
- case "medium":
- if (getRandomInt(1,6) === 1) {
- money += parseInt(bet.text) * 3;
- win = true;
- }
- break;
- case "hard":
- if (getRandomInt(1,12) === 1) {
- money += parseInt(bet.text) * 6;
- win = true;
- }
- break;
- default:
- work = false;
- break;
- }
- }else {
- window.close();
- }
- if (work == true) {
- if (money > 0) {
- if (win === true) {
- results.text = "Results: \nCongratulations! You Win!";
- }
- else {
- results.text = "Results: \nYou lost... rip";
- money -= parseInt(bet.text);
- mone.text = "Money: " + money;
- }
- }else {
- window.close();
- }
- }else {
- results.text = "Result: \nBro select a difficulty......";
- }
- mone.text = "Money: " + money;
- res.open();
- }
- }
- }
- }
- Popup {
- id: res
- x: parent.width/3
- y: parent.height/3
- width: parent.width/2.5
- height: parent.height/2
- Row {
- Text {
- id: results
- text: "Results:"
- height: parent.height/3
- font.family: "Calibri"
- font.pointSize: parent.parent.height/10
- }
- }
- Button {
- id: close
- text: "Close"
- y: parent.height/1.4
- width: parent.width/1.5
- height: parent.height/5
- font.family: "Calibri"
- font.pointSize: parent.height/7
- background : Rectangle {
- radius: 1000
- color: "lightGray"
- }
- onClicked: {
- res.close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement