Browse Source

Some minor fixes to the functions

Rafael Arce Nazario 9 years ago
parent
commit
efa24a77f5
2 changed files with 31 additions and 12 deletions
  1. 28
    9
      functions.cpp
  2. 3
    3
      mainwindow.cpp

+ 28
- 9
functions.cpp View File

115
 // Functions for the dice roller
115
 // Functions for the dice roller
116
 //========================================================
116
 //========================================================
117
 
117
 
118
-//This is the correct dice roller
118
+#include <iostream>
119
+using namespace std;
119
 void MainWindow::diceAlpha(){
120
 void MainWindow::diceAlpha(){
120
     int total = diceFinal01 + diceFinal02 + 2;
121
     int total = diceFinal01 + diceFinal02 + 2;
121
     line[0]->setText(QString::number(total));
122
     line[0]->setText(QString::number(total));
122
 }
123
 }
123
 
124
 
124
-//This version sums the first dice twice
125
 void MainWindow::diceBeta(){
125
 void MainWindow::diceBeta(){
126
     int total = diceFinal01 + diceFinal01 + 2;
126
     int total = diceFinal01 + diceFinal01 + 2;
127
     line[0]->setText(QString::number(total));
127
     line[0]->setText(QString::number(total));
128
 }
128
 }
129
 
129
 
130
-//This one substracts the second dice to the first one
131
 void MainWindow::diceGamma(){
130
 void MainWindow::diceGamma(){
132
     int total = diceFinal01 - diceFinal02;
131
     int total = diceFinal01 - diceFinal02;
133
     line[0]->setText(QString::number(total));
132
     line[0]->setText(QString::number(total));
134
 }
133
 }
135
 
134
 
136
-//This one takes the number 6 as a 12
137
 void MainWindow::diceDelta(){
135
 void MainWindow::diceDelta(){
138
     int total = diceFinal01 + diceFinal02;
136
     int total = diceFinal01 + diceFinal02;
139
     line[0]->setText(QString::number(total));
137
     line[0]->setText(QString::number(total));
402
     if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59)
400
     if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59)
403
         return false;
401
         return false;
404
 
402
 
405
-    if (zone.length() < 1 || !zone[0].isLetter()  || toupper(zone.toStdString()[0]) ==  'J') return false;
403
+    if (zone.length() < 1 || zone[0] < 'A' ||
404
+        zone[0] > 'Z'  || toupper(zone.toStdString()[0]) ==  'J')
405
+        return false;
406
+
406
     return true;
407
     return true;
407
 }
408
 }
408
 
409
 
437
 
438
 
438
     hours = (hours + (24 + diff) ) % 24;
439
     hours = (hours + (24 + diff) ) % 24;
439
 
440
 
440
-    return QString::number(hours)  + QString::number(minutes);
441
+    QString qstHours = QString::number(hours);
442
+    if (qstHours.length() == 1) qstHours.prepend("0");
443
+
444
+    QString qstMin = QString::number(minutes);
445
+    if (qstMin.length() == 1) qstMin.prepend("0");
446
+
447
+    return qstHours + qstMin;
441
 }
448
 }
442
 
449
 
443
 QString zuluGamma(int hours, int minutes, char zone) {
450
 QString zuluGamma(int hours, int minutes, char zone) {
448
     else if (zone <= 'Y')     diff = -(zone - 'N');
455
     else if (zone <= 'Y')     diff = -(zone - 'N');
449
     else                      diff = 0;
456
     else                      diff = 0;
450
 
457
 
451
-    hours = (hours + (24 - diff) ) % 24;
458
+    hours = (hours + (24 + diff) ) % 24;
452
 
459
 
453
-    return QString::number(hours) + QString::number(minutes);
460
+    QString qstHours = QString::number(hours);
461
+    if (qstHours.length() == 1) qstHours.prepend("0");
462
+
463
+    QString qstMin = QString::number(minutes);
464
+    if (qstMin.length() == 1) qstMin.prepend("0");
465
+
466
+    return qstHours + qstMin;
454
 }
467
 }
455
 
468
 
456
 QString zuluDelta(int hours, int minutes, char zone) {
469
 QString zuluDelta(int hours, int minutes, char zone) {
462
 
475
 
463
     hours = (hours + (24 - diff) ) % 24;
476
     hours = (hours + (24 - diff) ) % 24;
464
 
477
 
465
-    return QString::number(hours)  + QString::number(minutes);
478
+    QString qstHours = QString::number(hours);
479
+    if (qstHours.length() == 1) qstHours.prepend("0");
480
+
481
+    QString qstMin = QString::number(minutes);
482
+    if (qstMin.length() == 1) qstMin.prepend("0");
483
+
484
+    return qstHours + qstMin;
466
 }
485
 }
467
 
486
 
468
 
487
 

+ 3
- 3
mainwindow.cpp View File

389
         diceFinal01 = a;
389
         diceFinal01 = a;
390
         diceFinal02 = b;
390
         diceFinal02 = b;
391
         if (option == "Version Alpha")
391
         if (option == "Version Alpha")
392
-            diceBeta();
392
+            diceAlpha();
393
         else if (option == "Version Beta")
393
         else if (option == "Version Beta")
394
-            diceGamma();
394
+            diceBeta();
395
         else if (option == "Version Gamma")
395
         else if (option == "Version Gamma")
396
-            diceAlpha();
396
+            diceGamma();
397
         else
397
         else
398
             diceAlpha();
398
             diceAlpha();
399
     }
399
     }