diff --git a/Makefile b/Makefile index d7f1e3a..b371d0b 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,12 @@ dir: build: dir g++ -Wall -pedantic -ansi -std=c++17 ./src/*.cpp -o ./build/minesweeper.bin + +columns=16 +rows=9 +mines=15 run: - ./build/minesweeper.bin + ./build/minesweeper.bin $(columns) $(rows) $(mines) clean: rm -rf ./build/ diff --git a/README.md b/README.md index 113ccb4..8494f10 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,16 @@ Having `g++` with C++ 17 support, just run this inside the cloned repository: make ``` +## Customize game + +You can choose the number of rows and columns on the board and the number of mines. + +For this, use the columns, rows and mines optional variables when run make: + +```sh +make columns=10 rows=4 mines=8 +``` + That's it. Compiled using my Pop!_OS. I have no idea of how to run it in other environments. ## Disclaimer diff --git a/src/main.cpp b/src/main.cpp index d822f9b..df3a9fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,14 +13,25 @@ bool is_number(const std::string& s) [](unsigned char c) { return !std::isdigit(c); }) == s.end(); } -int main() { +int main(int argc, char *argv[]) { + + if (argc != 4) { + std::cout << "Please, give correct number of arguments."; + return 0; + } + + int COLUMNS, ROWS, MINES; + COLUMNS = std::stoi(argv[1]); + ROWS = std::stoi(argv[2]); + MINES = std::stoi(argv[3]); + srand(time(NULL)); std::string input_x, input_y; int x, y; char operation; std::string message = "Let's wait for your first move. Hope you're not nervous."; - Game::MineField field (16, 9, 15); + Game::MineField field (COLUMNS, ROWS, MINES); while (true) { std::system("clear || cls");