From b0edb4219ea4df381d0235aa34b74799334aa0b2 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Wed, 28 Jan 2026 20:01:46 +0100 Subject: finished merging code and simplifying file structure --- src/Game.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/Game.cpp (limited to 'src/Game.cpp') diff --git a/src/Game.cpp b/src/Game.cpp new file mode 100644 index 0000000..7c7e2d3 --- /dev/null +++ b/src/Game.cpp @@ -0,0 +1,70 @@ +#include "Game.hpp" +#include "../Utils/Utils.hpp" + +#include +#include +#include +#include + +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; + } + } +} + +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; +} + +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 -- cgit v1.2.3