wm: mastermind-qt

Download patch

ref: 8141c826b18673081f7dc489e2797c643a1bbb6c
parent: d0e937b8a10c007b2f58009512efa4e861eeb8df
author: mkf <mkf@hp.lan>
date: Wed Apr 26 17:42:11 EDT 2023

hopefully got buttons right this time

--- a/main.cpp
+++ b/main.cpp
@@ -12,6 +12,7 @@
 // debug it, if you can
 // remove resize grip
 // XXXs in code
+// get rid of QString::fromStdString(std::(to_string(...)))
 
 int main(int argc, char *argv[])
 {
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -166,15 +166,17 @@
     /* you pressed cancel "by mistake" ? too bad! your fault. */
     return res;
 }
-void MainWindow::action_giveup(){
+void MainWindow::action_giveup()
+{
     QMessageBox m;
+    QAbstractButton *y;
     m.setText("But-But... are you really totally 100% completely sure about it?");
     m.setIcon(QMessageBox::Question);
-    m.addButton(QString::fromStdString("Yea"), QMessageBox::AcceptRole);
-    m.addButton(QString::fromStdString("Nay!"), QMessageBox::RejectRole);
-    switch(m.exec())
+    y = m.addButton("Yea", QMessageBox::AcceptRole);
+    m.addButton("Nay!", QMessageBox::RejectRole);
+    m.exec();
+    if(m.clickedButton() == y)
     {
-        case QMessageBox::AcceptRole:
             action_newgame();
     }
 }
@@ -212,17 +214,19 @@
         ui->treeHistory->setEnabled(false);
 
         QMessageBox m;
+        QAbstractButton *retry, *newgame, *leave;
         m.setWindowTitle("INSERT COIN");
         m.setText("I'm afraid you have failed to acheive what"
                   " you had to do, and now we are all in"
                   " brink of impading doom...");
         m.setIcon(QMessageBox::Critical);
-        m.addButton(QString::fromStdString("another chance?"), QMessageBox::AcceptRole);
-        m.addButton(QString::fromStdString("dices were packed! new game and i shall win!"), QMessageBox::RejectRole);
-        m.addButton(QString::fromStdString("God has forsaken me, *leaving in shame*"), QMessageBox::DestructiveRole);
-        switch(m.exec())
+        retry = m.addButton(QString::fromStdString("another chance?"), QMessageBox::AcceptRole);
+        newgame = m.addButton(QString::fromStdString("dices were packed! new game and i shall win!"), QMessageBox::RejectRole);
+        leave = m.addButton(QString::fromStdString("God has forsaken me, *leaving in shame*"), QMessageBox::DestructiveRole);
+        m.exec();
+        /* fun(?) fact: switch doesn't work with non numerical types! */
+        if(m.clickedButton() == retry)
         {
-            case QMessageBox::AcceptRole:
                 /* maybe we should move these into a funcation?
                  * or maybe we should not... carry on */
                 ui->lcdLives->display(++lives);
@@ -230,14 +234,11 @@
                 ui->spinGuess->setEnabled(true);
                 ui->textChecked->setEnabled(true);
                 ui->treeHistory->setEnabled(true);
-                break;
-            case QMessageBox::RejectRole:
+        }
+        else if(m.clickedButton() == newgame)
                 action_newgame();
-                break;
-            case QMessageBox::DestructiveRole:
+        else if(m.clickedButton() == leave)
                 close();
-                break;
-        }
     }
     else
     {