Advertisement
Touch_Grass

Untitled

May 14th, 2023
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 5.19 KB | Source Code | 0 0
  1. import QtQuick
  2. import QtQuick.Window
  3. import QtQuick.Controls
  4. import QtQml.Models 2.2
  5.  
  6.  
  7. Window {
  8.     property int money: 100
  9.  
  10.     width: 640
  11.     height: 280
  12.     visible: true
  13.     title: qsTr("Roll the Dice")
  14.  
  15.     id: window
  16.  
  17.     Column {
  18.         width: parent.width
  19.         height: parent.height
  20.  
  21.  
  22.         id: mainColumn
  23.  
  24.         Row {
  25.             anchors.horizontalCenter: parent.horizontalCenter
  26.             width: parent.width
  27.             height: parent.height / 8
  28.  
  29.             id: headerRow
  30.  
  31.             Text {
  32.                 text: "Bet: "
  33.                 font.pointSize: parent.parent.height/20
  34.                 font.family: "Calibri"
  35.             }
  36.             TextField {
  37.                 id: bet
  38.                 placeholderText: "0"
  39.                 font.pointSize: parent.parent.height/20
  40.                 font.family: "Calibri"
  41.             }
  42.  
  43.             Text {
  44.                 text: "Difficulty(easy,medium,hard): "
  45.                 font.pointSize: parent.parent.height/20
  46.                 font.family: "Calibri"
  47.             }
  48.             TextField {
  49.                 id: dif
  50.                 placeholderText: "eg: easy"
  51.                 font.pointSize: parent.parent.height/20
  52.                 font.family: "Calibri"
  53.             }
  54.             Text {
  55.                 id: mone
  56.                 text: "Money: 100"
  57.                 font.pointSize: parent.parent.height/20
  58.                 font.family: "Calibri"
  59.             }
  60.         }
  61.  
  62.         Row {
  63.             Button {
  64.                 id: play
  65.  
  66.                 x: parent.width
  67.  
  68.                 background: Rectangle {
  69.                     radius: 100
  70.                     color: "lightGreen"
  71.                 }
  72.                 text: "Play"
  73.  
  74.                 anchors.centerIn: parent.Center
  75.  
  76.                 font.pointSize: parent.parent.height/20
  77.  
  78.                 width: parent.parent.width/3
  79.                 height: parent.parent.height/7
  80.  
  81.                 onClicked : {
  82.                     let win = false;
  83.                     let mode = dif.text;
  84.                     let work = true;
  85.  
  86.                     function getRandomInt(min, max) {
  87.                       min = Math.ceil(min);
  88.                       max = Math.floor(max);
  89.                       return Math.floor(Math.random() * (max - min + 1)) + min;
  90.                     }
  91.  
  92.                     if (money > 0) {
  93.                         switch(mode) {
  94.                         case "easy":
  95.                             if (getRandomInt(1,3) === 1) {
  96.                                 money += parseInt(bet.text) * 2;
  97.                                 win = true;
  98.                             }
  99.                             break;
  100.                         case "medium":
  101.                             if (getRandomInt(1,6) === 1) {
  102.                                 money += parseInt(bet.text) * 3;
  103.                                 win = true;
  104.                             }
  105.                             break;
  106.                         case "hard":
  107.                             if (getRandomInt(1,12) === 1) {
  108.                                 money += parseInt(bet.text) * 6;
  109.                                 win = true;
  110.                             }
  111.                             break;
  112.                         default:
  113.                             work = false;
  114.                             break;
  115.                         }
  116.                     }else {
  117.                         window.close();
  118.                     }
  119.  
  120.                     if (work == true) {
  121.                         if (money > 0) {
  122.                             if (win === true) {
  123.                                 results.text = "Results: \nCongratulations! You Win!";
  124.                             }
  125.                             else {
  126.                                 results.text = "Results: \nYou lost... rip";
  127.                                 money -= parseInt(bet.text);
  128.                                 mone.text = "Money: " + money;
  129.                             }
  130.                         }else {
  131.                             window.close();
  132.                         }
  133.                     }else {
  134.                         results.text = "Result: \nBro select a difficulty......";
  135.                     }
  136.  
  137.                     mone.text = "Money: " + money;
  138.  
  139.                     res.open();
  140.                 }
  141.             }
  142.         }
  143.     }
  144.  
  145.     Popup {
  146.         id: res
  147.  
  148.         x: parent.width/3
  149.         y: parent.height/3
  150.  
  151.         width: parent.width/2.5
  152.         height: parent.height/2
  153.  
  154.         Row {
  155.             Text {
  156.                 id: results
  157.                 text: "Results:"
  158.                 height: parent.height/3
  159.                 font.family: "Calibri"
  160.                 font.pointSize: parent.parent.height/10
  161.             }
  162.         }
  163.  
  164.         Button {
  165.             id: close
  166.             text: "Close"
  167.  
  168.             y: parent.height/1.4
  169.  
  170.             width: parent.width/1.5
  171.             height: parent.height/5
  172.  
  173.             font.family: "Calibri"
  174.             font.pointSize: parent.height/7
  175.  
  176.             background : Rectangle {
  177.                 radius: 1000
  178.                 color: "lightGray"
  179.             }
  180.  
  181.             onClicked: {
  182.                 res.close();
  183.             }
  184.         }
  185.     }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement