mines
Loading...
Searching...
No Matches
Game Class Referenceexport
module mines

Game. More...

Public Member Functions

std::optional< std::chrono::milliseconds > get_current_timer ()
 Get the current value of the timer.
const Boardget_board ()
 Get the board.
void uncover_cell (std::uint32_t x, std::uint32_t y)
 Uncover a cell.
void mark_cell (std::uint32_t x, std::uint32_t y)
 Place a mark on a cell.
void flag_cell (std::uint32_t x, std::uint32_t y)
 Place a flag on a cell.
void reset_cell (std::uint32_t x, std::uint32_t y)
 Reset flag or mark placed on a cell.
bool is_lost ()
 Get whether the game was lost.
bool is_won ()
 Get whether the game was won.
void new_board (std::uint32_t width, std::uint32_t height, std::uint32_t mines)
 Set up a new board.
void set_player_name (std::string player_name)
 Set the player name.

Static Public Member Functions

static Game create (std::uint32_t width, std::uint32_t height, std::uint32_t mines, std::string player_name, std::string save_path)
 Construct a game.

Detailed Description

Game.

Contains high level game logic without a coupled user interface. Typically used with the user interface GameView.

Member Function Documentation

◆ create()

Game Game::create ( std::uint32_t width,
std::uint32_t height,
std::uint32_t mines,
std::string player_name,
std::string save_path )
inlinestatic

Construct a game.

Parameters
widthWidth of the board.
heightHeight of the board.
minesNumber of mines.
player_namePlayer name.
Returns
New game.
Exceptions
TooManyMinesThe number of mines is more than what is possible given the size of the minefield.
InvalidSaveDataSave data that was attempted to be deserialized is invalid.

◆ flag_cell()

void Game::flag_cell ( std::uint32_t x,
std::uint32_t y )
inline

Place a flag on a cell.

Does nothing if the game ended, or the cell is uncovered or already flagged.

Parameters
xCell X position.
yCell Y position.

◆ get_board()

const Board & Game::get_board ( )
inline

Get the board.

Returns
Board.

◆ get_current_timer()

std::optional< std::chrono::milliseconds > Game::get_current_timer ( )
inline

Get the current value of the timer.

Returns
Current value of the timer, if the game has started, or no value if the game has not started.

◆ is_lost()

bool Game::is_lost ( )
inline

Get whether the game was lost.

Returns
Whether the game was lost.

◆ is_won()

bool Game::is_won ( )
inline

Get whether the game was won.

Returns
Whether the game was won.

◆ mark_cell()

void Game::mark_cell ( std::uint32_t x,
std::uint32_t y )
inline

Place a mark on a cell.

Does nothing if the game ended, or the cell is uncovered or already marked.

Parameters
xCell X position.
yCell Y position.

◆ new_board()

void Game::new_board ( std::uint32_t width,
std::uint32_t height,
std::uint32_t mines )
inline

Set up a new board.

Resets the game to it's initial state.

Parameters
widthWidth of the new board.
heightHeight of the new board.
minesNumber of mines.

◆ reset_cell()

void Game::reset_cell ( std::uint32_t x,
std::uint32_t y )
inline

Reset flag or mark placed on a cell.

Does nothing if the game ended, or the cell is not marked nor flagged.

Parameters
xCell X position.
yCell Y position.

◆ set_player_name()

void Game::set_player_name ( std::string player_name)
inline

Set the player name.

Parameters
player_nameNew player name.

◆ uncover_cell()

void Game::uncover_cell ( std::uint32_t x,
std::uint32_t y )
inline

Uncover a cell.

If this is the first time a cell is uncovered during a game, the minefield is generated with the guarantee that this cell is not a mine.

Causes a game over if the cell is a mine. Does nothing if the game ended, or the cell is flagged or already uncovered.

Parameters
xCell X position.
yCell Y position.

The documentation for this class was generated from the following file: