diff options
| author | dawidg81 <dawidgorski.m@gmail.com> | 2026-01-25 14:51:03 +0100 |
|---|---|---|
| committer | dawidg81 <dawidgorski.m@gmail.com> | 2026-01-25 14:51:03 +0100 |
| commit | 9a258f7070c9a7e7f599bc7050190cdd0aa25351 (patch) | |
| tree | bd7133efec549f4a7096bb6cb5d0001577d29f1e | |
| parent | 01235704222d95a3c8b9db4bb1a5153b9bcea900 (diff) | |
object programming implementation
| -rw-r--r-- | src/game/game.cpp | 107 |
1 files changed, 60 insertions, 47 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp index 2b5df1f..ebd180d 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1,69 +1,82 @@ #include <cstdlib> #include <iostream> +#include <sys/stat.h> #include "globals.hpp" using namespace std; bool inGame = false; -void game(int diff){ +class Game{ +private: + static constexpr int MAX_W = 32; + static constexpr int MAX_H = 32; + int boardWidth; int boardHeight; - int board[boardWidth][boardHeight]; + + bool bombmap[MAX_H][MAX_W]; + int displaymap[MAX_H][MAX_W]; + int mines; - 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"; +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; + 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"; - } + 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; + 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"; - } + 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; + cout << "Mines: "; + cin >> mines; - if(mines > 16){ - cout << "There can't be more than 16 mines.\n"; - } + if(mines > 16){ + cout << "There can't be more than 16 mines.\n"; + } - break; + break; + } } - for(int i = 0; i < boardHeight; i++){ - for(int j = 0; j < boardWidth; j++){ - board[i][j] = rand() % 1; + void initBoard(){ + for(int i = 0; i < boardHeight; i++){ + for(int j = 0; j < boardWidth; j++){ + bombmap[i][j] = rand() % 1; + } } } -} +}; |
