summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordawidg81 <dawidgorski.m@gmail.com>2026-01-25 15:10:55 +0100
committerdawidg81 <dawidgorski.m@gmail.com>2026-01-25 15:10:55 +0100
commitc87681ddf664a50f4d9aa6c059def1ff6610392a (patch)
tree8473bfd07f79170aa2c798f7f87467a390a0bd1a /src
parentad966d9e84d63f9000be1c5abe7126e55a934211 (diff)
cleaned game.cpp
Diffstat (limited to 'src')
-rw-r--r--src/game/game.cpp141
1 files changed, 43 insertions, 98 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 80f25bf..4f4d1f9 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -1,101 +1,46 @@
-#include <cstdio>
-#include <cstdlib>
-#include <iostream>
-#include <sys/stat.h>
#include "globals.hpp"
-using namespace std;
-
-bool inGame = false;
-
-class Game{
-private:
- static constexpr int MAX_W = 32;
- static constexpr int MAX_H = 32;
-
- int boardWidth;
- int boardHeight;
-
- bool bombMap[MAX_H][MAX_W];
- int tileMap[MAX_H][MAX_W];
-
- int mines;
-
-public:
- void 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:
- cout << "Editing game parameters\n";
-
- cout << "Board Width: ";
- cin >> boardWidth;
-
- if(boardWidth > 32){
- cout << "Board width can't be more than 32 cells.\n";
- } else if(boardWidth < 8){
- cout << "Board width can't be less than 8 cells.\n";
- }
-
- cout << "Board Height: ";
- cin >> boardHeight;
-
- if(boardHeight > 32){
- cout << "Board height can't be more than 32 cells.\n";
- }else if(boardHeight < 8){
- cout << "Board height can't be less than 8 cells.\n";
- }
-
- cout << "Mines: ";
- cin >> mines;
-
- if(mines > 16){
- cout << "There can't be more than 16 mines.\n";
- }
-
- break;
- }
- }
-
- void initBoard(){
- for(int i = 0; i < boardHeight; i++){
- for(int j = 0; j < boardWidth; j++){
- // false = no bomb; true = bomb;
- bombMap[i][j] = rand() % 2;
- }
- }
-
- for (int i = 0; i < boardHeight; i++) {
- for (int j = 0; j < boardWidth; j++) {
- // 0 = unrevealed tile
- // 1 = revealed tile
- // from 2 to 10 - revealed tiles with numbers
- tileMap[i][j] = 0;
- }
- }
- }
+#include <cstdlib>
+#include <cstdio>
+#include <iostream>
- void displayBoard(){
- for (int i = 0; i < boardHeight; i++) {
- for (int j = 0; j < boardWidth; j++) {
- putchar(tileMap[i][j]);
- }
- }
- }
-};
+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;
+}
+
+void Game::displayBoard() {
+ for (int i = 0; i < boardHeight; i++) {
+ for (int j = 0; j < boardWidth; j++)
+ putchar(tileMap[i][j]);
+ putchar('\n');
+ }
+}