summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordawidg81 <dawidgorski.m@gmail.com>2026-01-26 17:15:33 +0100
committerdawidg81 <dawidgorski.m@gmail.com>2026-01-26 17:15:33 +0100
commitb492bfb0d4cafe69edf69f196911f1b0e64c43df (patch)
tree3efa371f146aa98eb4c712137ee07a8199520816 /src
parent445e27aa9479dbb269aaaf349ed830bcd88905ad (diff)
added utilities; recovered custom difficulty editing
Diffstat (limited to 'src')
-rw-r--r--src/game/Game.hpp2
-rw-r--r--src/game/edit.cpp20
-rw-r--r--src/utils/Utils.hpp11
-rw-r--r--src/utils/catchInputInt.cpp15
-rw-r--r--src/utils/catchReturn.cpp11
-rw-r--r--src/utils/utils.hpp10
6 files changed, 57 insertions, 12 deletions
diff --git a/src/game/Game.hpp b/src/game/Game.hpp
index 7518a84..767ab94 100644
--- a/src/game/Game.hpp
+++ b/src/game/Game.hpp
@@ -15,7 +15,7 @@ private:
int mines;
public:
- void editDiff();
+ int editDiff();
void initDiff(int diff);
void initBoard();
void displayBoard();
diff --git a/src/game/edit.cpp b/src/game/edit.cpp
index 53605ca..b2d2542 100644
--- a/src/game/edit.cpp
+++ b/src/game/edit.cpp
@@ -1,9 +1,27 @@
#include "Game.hpp"
+#include "../utils/Utils.hpp"
#include <cstdlib>
#include <cstdio>
#include <iostream>
+#include <string>
+
+int Game::editDiff(){
+ Utils util;
-void Game::editDiff(){
std::cout << "Now editing custom difficulty" << std::endl;
+
+ std::cout << "Board width: ";
+ util.catchInputInt(Game::boardWidth);
+ if(util.catchReturn(util.catchInputInt(Game::boardWidth)) != 0) return 1;
+
+ std::cout << "Board height: ";
+ util.catchInputInt(Game::boardHeight);
+ if(util.catchReturn(util.catchInputInt(Game::boardHeight)) != 0) return 1;
+
+ std::cout << "Mines: ";
+ util.catchInputInt(Game::mines);
+ if(util.catchReturn(util.catchInputInt(Game::mines)) != 0) return 1;
+
+ return 0;
} \ No newline at end of file
diff --git a/src/utils/Utils.hpp b/src/utils/Utils.hpp
new file mode 100644
index 0000000..7df9e3d
--- /dev/null
+++ b/src/utils/Utils.hpp
@@ -0,0 +1,11 @@
+#include <string>
+
+#ifndef UTILS_HPP
+
+class Utils{
+ public:
+ int catchInputInt(int input);
+ int catchReturn(int renum);
+};
+
+#endif \ No newline at end of file
diff --git a/src/utils/catchInputInt.cpp b/src/utils/catchInputInt.cpp
new file mode 100644
index 0000000..0dc8fc9
--- /dev/null
+++ b/src/utils/catchInputInt.cpp
@@ -0,0 +1,15 @@
+#include "Utils.hpp"
+
+#include <cstdio>
+#include <iostream>
+
+int Utils::catchInputInt(int input){
+ std::cin >> input;
+
+ if (std::cin.fail()) {
+ std::cout << "error: Input failed" << std::endl;
+ return 1;
+ }
+
+ return 0;
+} \ No newline at end of file
diff --git a/src/utils/catchReturn.cpp b/src/utils/catchReturn.cpp
new file mode 100644
index 0000000..c3d6722
--- /dev/null
+++ b/src/utils/catchReturn.cpp
@@ -0,0 +1,11 @@
+#include "Utils.hpp"
+
+#include <iostream>
+#include <ostream>
+
+int Utils::catchReturn(int renum){
+ if (renum != 0) {
+ std::cout << "Received error signal, sending further" << std::endl;
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp
deleted file mode 100644
index 19ae230..0000000
--- a/src/utils/utils.hpp
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <string>
-
-#ifndef UTILS_HPP
-
-class Utils{
- public:
- void input(std::string input);
-};
-
-#endif \ No newline at end of file