initial commit
forgot the makefiles forgor the readme makefile crap yet again sss
This commit is contained in:
32
include/Board.h
Normal file
32
include/Board.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <random>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include "Cell.h"
|
||||
|
||||
class Board
|
||||
{
|
||||
public:
|
||||
Board(int w, int h, short mines);
|
||||
Cell revealCellAt(int x, int y);
|
||||
void gameOver();
|
||||
void flagCellAt(int x, int y);
|
||||
Vector2 getBoardSize() const;
|
||||
bool isGameOver();
|
||||
void revealEmptyCells(int x, int y);
|
||||
Cell::State getCellStateAt(int x, int y);
|
||||
int getMineCount() const;
|
||||
void regenerateBoard();
|
||||
bool isGameWon() const;
|
||||
|
||||
private:
|
||||
Vector2 size;
|
||||
short mines;
|
||||
bool b_gameOver = false;
|
||||
bool isFirstClick = true;
|
||||
std::vector<std::vector<Cell>> cells;
|
||||
|
||||
bool checkWinCondition() const;
|
||||
};
|
||||
46
include/Cell.h
Normal file
46
include/Cell.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "Vector2.h"
|
||||
|
||||
class Cell
|
||||
{
|
||||
public:
|
||||
enum class Content
|
||||
{
|
||||
Empty = 0,
|
||||
One,
|
||||
Two,
|
||||
Three,
|
||||
Four,
|
||||
Five,
|
||||
Six,
|
||||
Seven,
|
||||
Eight,
|
||||
Mine
|
||||
};
|
||||
|
||||
enum class State
|
||||
{
|
||||
Hidden,
|
||||
Revealed,
|
||||
Flagged,
|
||||
NotAMine
|
||||
};
|
||||
|
||||
friend class Board;
|
||||
|
||||
Cell() = default;
|
||||
Cell(int x, int y);
|
||||
Cell(Vector2 &initPos);
|
||||
|
||||
State getState() const;
|
||||
void reveal();
|
||||
void toggleFlag();
|
||||
Content getContent() const;
|
||||
void setContent(Content newContent);
|
||||
|
||||
private:
|
||||
State state = State::Hidden;
|
||||
Content content = Content::Empty;
|
||||
Vector2 position;
|
||||
};
|
||||
48
include/Vector2.h
Normal file
48
include/Vector2.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
struct Vector2
|
||||
{
|
||||
/**
|
||||
* The position vector.
|
||||
*/
|
||||
int x, y;
|
||||
|
||||
/**
|
||||
* The Vector2 initializer.
|
||||
*/
|
||||
Vector2(int x = 0, int y = 0);
|
||||
|
||||
/**
|
||||
* Addition.
|
||||
*/
|
||||
Vector2 operator+(const Vector2 &other) const;
|
||||
/**
|
||||
* Subtraction.
|
||||
*/
|
||||
Vector2 operator-(const Vector2 &other) const;
|
||||
/**
|
||||
* Multiplication (by scalar).
|
||||
*/
|
||||
Vector2 operator*(float scalar) const;
|
||||
/**
|
||||
* Division (by scalar).
|
||||
*/
|
||||
Vector2 operator/(float scalar) const;
|
||||
|
||||
/**
|
||||
* Addition.
|
||||
*/
|
||||
Vector2 &operator+=(const Vector2 &other);
|
||||
/**
|
||||
* Subtraction.
|
||||
*/
|
||||
Vector2 &operator-=(const Vector2 &other);
|
||||
/**
|
||||
* Multiplication (by scalar).
|
||||
*/
|
||||
Vector2 &operator*=(float scalar);
|
||||
/**
|
||||
* Division (by scalar).
|
||||
*/
|
||||
Vector2 &operator/=(float scalar);
|
||||
};
|
||||
Reference in New Issue
Block a user