Add Minesweeper and Bug Screenshots

This commit is contained in:
Matti 2024-11-15 01:57:31 +01:00
parent 98808ae921
commit ebb8e43e32
6 changed files with 94 additions and 1 deletions

View File

@ -6,11 +6,13 @@
#include "Aufg3/Phonebook.h" #include "Aufg3/Phonebook.h"
#include "Aufg4/CrimeStats.h" #include "Aufg4/CrimeStats.h"
#include "Aufg5/Mastermind.h" #include "Aufg5/Mastermind.h"
#include "Aufg6/MineSweeper.h"
int main() { int main() {
// Aufg1Main(); // Aufg1Main();
// Aufg2Main(); // Aufg2Main();
// Aufg3Main(); // Aufg3Main();
// Aufg4Main(); // Aufg4Main();
Aufg5Main(); // Aufg5Main();
Aufg6Main();
} }

View File

@ -11,6 +11,8 @@ void Aufg5Main();
std::vector<std::string> generateSecretCode(int size, int optionsPerDigit); std::vector<std::string> generateSecretCode(int size, int optionsPerDigit);
int getRandomNumberInRange(int min, int max);
std::vector<std::string> getCodeGuessFromConsole(); std::vector<std::string> getCodeGuessFromConsole();
std::vector<std::string> convertStringToGuess(std::string &guessAsString); std::vector<std::string> convertStringToGuess(std::string &guessAsString);

BIN
Aufg6/Bullshit_Bug.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
Aufg6/Bullshit_Bug2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

79
Aufg6/MineSweeper.cpp Normal file
View File

@ -0,0 +1,79 @@
#include <iostream>
#include "../Aufg5/Mastermind.h"
struct MineSweeperBoard {
std::string field[16][16];
int bombCounter = 0;
void debugBoard(std::string character) {
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
field[i][j] = character;
}
}
}
bool hasBomb(int i1, int i2) {
return field[i1][i2] == "x";
}
void spreadBombs() {
while (bombCounter < 99) {
field[getRandomNumberInRange(0,15)][getRandomNumberInRange(0,15)] = "x";
bombCounter++;
}
}
std::string countNeighbourBombs(int i, int j) {
i--;
j--;
int counter;
for (int k = 0; k < 3; k++) {
for (int l = 0; l < 3; l++) {
if ((i+k < 16) && (j+l < 16) && (i-l >= 0) && (j-l >= 0)) {
if (field[i+k][j+l] == "x") {
counter++;
}
}
}
}
return std::to_string(counter);
}
void calculateExplosiveNeighbours() {
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
if (field[i][j] != "x") {
field[i][j] = countNeighbourBombs(i, j);
}
}
}
}
void printBoard() {
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
std::cout << field[i][j] << " ";
}
std::cout << std::endl;
}
}
};
void Aufg6Main() {
MineSweeperBoard board;
board.printBoard();
std::cout << "Empty Board? ==============" << std::endl << std::endl;
board.spreadBombs();
board.printBoard();
std::cout << "Bombed Board? ==============" << std::endl << std::endl;
board.calculateExplosiveNeighbours();
board.printBoard();
std::cout << "Solved Board? ==============" << std::endl << std::endl;
board.debugBoard(".");
board.field[14][14] = "x";
board.field[13][13] = "x";
board.field[13][15] = "x";
board.calculateExplosiveNeighbours();
board.printBoard();
}

10
Aufg6/MineSweeper.h Normal file
View File

@ -0,0 +1,10 @@
//
// Created by DH10MBO on 15.11.2024.
//
#ifndef MINESWEEPER_H
#define MINESWEEPER_H
void Aufg6Main();
#endif //MINESWEEPER_H