-
Notifications
You must be signed in to change notification settings - Fork 0
/
sweepminer.h
52 lines (42 loc) · 1.25 KB
/
sweepminer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef MINESWEEPER_H
#define MINESWEEPER_H
#include <string>
#include <iostream>
using namespace std;
//Struct for a 2D position with an x and y value
struct Position
{
int x, y;
bool operator == (Position& other) { return x == other.x && y == other.y; }
Position addPosition(int delta_x, int delta_y) { return Position(x + delta_x, y + delta_y); }
Position(int x, int y) { this->x = x; this->y = y; }
};
//Class representing a Minesweeper-esque game to sweep for bombs.
class Sweepminer
{
const string flag = "\033[31mF\033[0m"; //String for printing the red F for a bomb
int** board;
int width, height;
void allocateBoard();
void deallocateBoard();
int getDistanceAtPosition(Position pos) const { return board[pos.y][pos.x]; }
int setDistanceAtPosition(Position pos, int dist) { board[pos.y][pos.x] = dist; }
public:
void populateBoard(const int& bomb_count);
void generateDistances(Position pos, int distance);
void printBoard();
Sweepminer(int width, int height, int num_bombs = 3, int seed = 1024)
{
this->width = width;
this->height = height;
allocateBoard();
//Fill the board with bombs
srand(seed);
populateBoard(num_bombs);
}
~Sweepminer()
{
deallocateBoard();
}
};
#endif