summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.Game.cpp.swp (renamed from src/Utils/.Utils.hpp.swp)bin12288 -> 12288 bytes
-rw-r--r--src/Game.cpp131
-rw-r--r--src/Game.hpp (renamed from src/Game/Game.hpp)0
-rw-r--r--src/Game/display.cpp14
-rw-r--r--src/Game/edit.cpp25
-rw-r--r--src/Game/init.cpp38
-rw-r--r--src/Utils/Utils.hpp11
-rw-r--r--src/Utils/catch.cpp22
-rw-r--r--src/main.cpp2
9 files changed, 132 insertions, 111 deletions
diff --git a/src/Utils/.Utils.hpp.swp b/src/.Game.cpp.swp
index 08be885..1e31022 100644
--- a/src/Utils/.Utils.hpp.swp
+++ b/src/.Game.cpp.swp
Binary files differ
diff --git a/src/Game.cpp b/src/Game.cpp
new file mode 100644
index 0000000..1ed4b50
--- /dev/null
+++ b/src/Game.cpp
@@ -0,0 +1,131 @@
+#include "Game.hpp"
+
+#include <cstdlib>
+#include <cstdio>
+#include <iostream>
+#include <string>
+
+void Game::initDiff(int diff) {
+ switch (diff) {
+ case 0:
+ boardWidth = 9;
+ boardHeight = 9;
+ mines = 9;
+ break;
+ case 1:
+ boardWidth = 16;
+ boardHeight = 16;
+ mines = 12;
+ break;
+ case 2:
+ boardWidth = 30;
+ boardHeight = 16;
+ mines = 16;
+ break;
+ case 3:
+ std::cout << "Editing game parameters\n";
+ break;
+ }
+}
+
+void Game::initBoard() {
+ // Bomb map (boolean): 0 or false is no bomb, 1 or true is bomb;
+ // clearing bomb map
+ for (int i = 0; i < boardHeight; i++) {
+ for (int j = 0; j < boardWidth; j++) {
+ for(int k = 0; k < mines; k++){
+ bombMap[i][j] = 0;
+ }
+ }
+ }
+
+ // initializing bomb map
+ for (int i = 0; i < boardHeight; i++) {
+ for (int j = 0; j < boardWidth; j++) {
+ for(int k = 0; k < mines; k++){
+ bombMap[i][j] = rand() % 2;
+ }
+ }
+ }
+
+ // initializing tile map for display
+ for (int i = 0; i < boardHeight; i++) {
+ for (int j = 0; j < boardWidth; j++) {
+ tileMap[i][j] = 0;
+ }
+ }
+}
+
+int Game::editDiff(){
+
+ std::cout << "Now editing custom difficulty" << std::endl;
+
+ std::cout << "Board width: ";
+ std::cin >> boardWidth;
+
+ if (boardWidth > MAX_W) {
+ std::cout << "Board width can't be more than " << MAX_W << " tiles." << std::endl;
+ return 1;
+ }
+
+ std::cout << "Board height: ";
+ std::cin >> boardHeight;
+
+ if (boardHeight > MAX_H) {
+ std::cout << "Board height can't be more than " << MAX_H << " tiles." << std::endl;
+ return 1;
+ }
+
+ std::cout << "Mines: ";
+ std::cin >> mines;
+
+ if (mines > 8 || mines > (boardWidth * boardHeight)) {
+ std::cout << "There can't be more than " << mines << " mines." << std::endl;
+ return 1;
+ }
+
+ return 0;
+}
+
+/* Tile map:
+
+0 - unrevealed tile
+1 - revealed tile
+2 - revealed tile with 1 bomb around
+3 - revealed tile with 2 bomb around
+4 - revealed tile with 3 bomb around
+5 - revealed tile with 4 bomb around
+6 - revealed tile with 5 bomb around
+7 - revealed tile with 6 bomb around
+8 - revealed tile with 7 bomb around
+9 - revealed tile with 8 bomb around
+
+*/
+void Game::displayBoard() {
+ for (int i = 0; i < boardHeight; i++) {
+ for (int j = 0; j < boardWidth; j++) {
+ if (tileMap[i][j] == 0) {
+ putchar('#');
+ } else if (tileMap[i][j] == 1) {
+ putchar('.');
+ } else if (tileMap[i][j] == 2) {
+ putchar('1');
+ } else if (tileMap[i][j] == 3) {
+ putchar('2');
+ } else if (tileMap[i][j] == 4) {
+ putchar('3');
+ } else if (tileMap[i][j] == 5) {
+ putchar('4');
+ } else if (tileMap[i][j] == 6) {
+ putchar('5');
+ } else if (tileMap[i][j] == 7) {
+ putchar('6');
+ } else if (tileMap[i][j] == 8) {
+ putchar('7');
+ } else if (tileMap[i][j] == 9) {
+ putchar('8');
+ }
+ }
+ putchar('\n');
+ }
+}
diff --git a/src/Game/Game.hpp b/src/Game.hpp
index 767ab94..767ab94 100644
--- a/src/Game/Game.hpp
+++ b/src/Game.hpp
diff --git a/src/Game/display.cpp b/src/Game/display.cpp
deleted file mode 100644
index 4fb16cb..0000000
--- a/src/Game/display.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "Game.hpp"
-
-#include <cstdlib>
-#include <cstdio>
-#include <iostream>
-
-
-void Game::displayBoard() {
- for (int i = 0; i < boardHeight; i++) {
- for (int j = 0; j < boardWidth; j++)
- putchar(tileMap[i][j]);
- putchar('\n');
- }
-} \ No newline at end of file
diff --git a/src/Game/edit.cpp b/src/Game/edit.cpp
deleted file mode 100644
index af89e65..0000000
--- a/src/Game/edit.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "Game.hpp"
-#include "../Utils/Utils.hpp"
-
-#include <cstdlib>
-#include <cstdio>
-#include <iostream>
-#include <string>
-
-int Game::editDiff(){
- Utils util;
-
- std::cout << "Now editing custom difficulty" << std::endl;
-
- std::cout << "Board width: ";
- if(util.catchReturn(util.catchInputInt(Game::boardWidth)) != 0) return 1;
- std::cout << Game::boardWidth;
-
- std::cout << "Board height: ";
- if(util.catchReturn(util.catchInputInt(Game::boardHeight)) != 0) return 1;
-
- std::cout << "Mines: ";
- if(util.catchReturn(util.catchInputInt(Game::mines)) != 0) return 1;
-
- return 0;
-} \ No newline at end of file
diff --git a/src/Game/init.cpp b/src/Game/init.cpp
deleted file mode 100644
index a572fbc..0000000
--- a/src/Game/init.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "Game.hpp"
-
-#include <cstdlib>
-#include <cstdio>
-#include <iostream>
-
-void Game::initDiff(int diff) {
- switch (diff) {
- case 0:
- boardWidth = 9;
- boardHeight = 9;
- mines = 9;
- break;
- case 1:
- boardWidth = 16;
- boardHeight = 16;
- mines = 12;
- break;
- case 2:
- boardWidth = 30;
- boardHeight = 16;
- mines = 16;
- break;
- case 3:
- std::cout << "Editing game parameters\n";
- break;
- }
-}
-
-void Game::initBoard() {
- for (int i = 0; i < boardHeight; i++)
- for (int j = 0; j < boardWidth; j++)
- bombMap[i][j] = rand() % 2;
-
- for (int i = 0; i < boardHeight; i++)
- for (int j = 0; j < boardWidth; j++)
- tileMap[i][j] = 0;
-} \ No newline at end of file
diff --git a/src/Utils/Utils.hpp b/src/Utils/Utils.hpp
deleted file mode 100644
index 32c07ed..0000000
--- a/src/Utils/Utils.hpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <string>
-
-#ifndef UTILS_HPP
-
-class Utils{
-public:
- int catchInputInt(int* input);
- int catchReturn(int renum);
-};
-
-#endif
diff --git a/src/Utils/catch.cpp b/src/Utils/catch.cpp
deleted file mode 100644
index 37ebefe..0000000
--- a/src/Utils/catch.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "Utils.hpp"
-
-#include <iostream>
-#include <ostream>
-
-int Utils::catchInputInt(int* input){
- std::cin >> input;
-
- if (std::cin.fail()) {
- std::cout << "error: Input failed" << std::endl;
- return 1;
- }
-
- return 0;
-}
-
-int Utils::catchReturn(int renum){
- if (renum != 0) {
- std::cout << "Received error signal, sending further" << std::endl;
- }
- return 0;
-}
diff --git a/src/main.cpp b/src/main.cpp
index 3e1c1cc..88b8ffa 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,5 +1,5 @@
#include <iostream>
-#include "Game/Game.hpp"
+#include "Game.hpp"
using namespace std;
int main(){