Manages storage, initialization, movement of tiles, and saving/loading of a grid. DONT USE: IT'S DECPRECATED.
More...
#include <GridManager.h>
|
| GridManager () |
| Creates a new grid, initialized to GridManager::GOAL_GRID. More...
|
|
| GridManager (const std::string &saveFile) |
| Creates a new grid from a file. May throw exceptions from GridManager::load. More...
|
|
| GridManager (const std::array< std::array< std::uint8_t, 4 >, 4 > &newGrid) |
| Creates a new grid from an existing grid. May throw exceptions from GridManager::setGrid. More...
|
|
| GridManager (const std::uint8_t newGrid[4][4]) |
| Creates a new grid from an existing grid. May throw exceptions from GridManager::setGrid. More...
|
|
void | swapTile (const std::uint8_t tileX, const std::uint8_t tileY) |
| Swaps the tile at the given coordinates with the no tile. More...
|
|
void | swapTile (const std::uint8_t tileNum) |
| Swaps the tile given with the no tile. More...
|
|
std::uint8_t | getTile (const std::uint8_t tileX, const std::uint8_t tileY) |
| Gets the tile at the given coordinates. More...
|
|
std::uint8_t | getX (const std::uint8_t tileNum) |
| Gets the x coordinate of the given tile. More...
|
|
std::uint8_t | getY (const std::uint8_t tileNum) |
| Gets the y coordinate of the given tile. More...
|
|
bool | validMove (const std::int64_t tileNum) |
| Checks if the tile movement will be valid. More...
|
|
bool | validMove (const std::int64_t tileX, const std::int64_t tileY) |
| Checks if the tile movement will be valid. More...
|
|
bool | hasWon () |
| Checks if the grid is won. More...
|
|
void | setGrid (const std::array< std::array< std::uint8_t, 4 >, 4 > &newGrid) |
| Sets GridManager::gameGrid. More...
|
|
void | setGrid (const std::uint8_t newGrid[4][4]) |
| Sets GridManager::gameGrid. More...
|
|
std::array< std::array< std::uint8_t, 4 >, 4 > | getGrid () |
| Returns a copy of GridManager::gameGrid. More...
|
|
void | save (const std::string &saveFile) |
| Save the grid to disk. More...
|
|
void | load (const std::string &saveFile) |
| Load the grid from disk. More...
|
|
|
void | reIndex () |
| Reads the current gameGrid and updates the index. More...
|
|
|
std::array< std::array< std::uint8_t, 4 >, 4 > | gameGrid {} |
| The grid. More...
|
|
std::uint8_t | index [16][2] {} |
| The index to keep track of tile locations. More...
|
|
Manages storage, initialization, movement of tiles, and saving/loading of a grid. DONT USE: IT'S DECPRECATED.
- Author
- John Jekel
- Date
- 2017-2018
- Deprecated:
- Use Grid and GridHelp instead
◆ GridManager() [1/4]
GridManager::GridManager |
( |
| ) |
|
◆ GridManager() [2/4]
GridManager::GridManager |
( |
const std::string & |
saveFile | ) |
|
Creates a new grid from a file. May throw exceptions from GridManager::load.
- Parameters
-
saveFile | The file to load from |
◆ GridManager() [3/4]
GridManager::GridManager |
( |
const std::array< std::array< std::uint8_t, 4 >, 4 > & |
newGrid | ) |
|
Creates a new grid from an existing grid. May throw exceptions from GridManager::setGrid.
- Parameters
-
◆ GridManager() [4/4]
GridManager::GridManager |
( |
const std::uint8_t |
newGrid[4][4] | ) |
|
Creates a new grid from an existing grid. May throw exceptions from GridManager::setGrid.
- Parameters
-
◆ generateRandomGrid()
std::array< std::array< std::uint8_t, 4 >, 4 > GridManager::generateRandomGrid |
( |
| ) |
|
|
static |
Creates a new, random and valid grid, which can be assigned using GridManager::setGrid.
- Returns
- A new grid
◆ getGrid()
std::array< std::array< std::uint8_t, 4 >, 4 > GridManager::getGrid |
( |
| ) |
|
◆ getTile()
std::uint8_t GridManager::getTile |
( |
const std::uint8_t |
tileX, |
|
|
const std::uint8_t |
tileY |
|
) |
| |
Gets the tile at the given coordinates.
- Parameters
-
tileX | The x coordinate |
tileY | The y coordinate |
- Returns
- The tile
- Exceptions
-
◆ getX()
std::uint8_t GridManager::getX |
( |
const std::uint8_t |
tileNum | ) |
|
Gets the x coordinate of the given tile.
- Parameters
-
- Returns
- The x coordinate
- Exceptions
-
◆ getY()
std::uint8_t GridManager::getY |
( |
const std::uint8_t |
tileNum | ) |
|
Gets the y coordinate of the given tile.
- Parameters
-
- Returns
- The y coordinate
- Exceptions
-
◆ hasWon()
bool GridManager::hasWon |
( |
| ) |
|
◆ load()
void GridManager::load |
( |
const std::string & |
saveFile | ) |
|
Load the grid from disk.
- Parameters
-
◆ reIndex()
void GridManager::reIndex |
( |
| ) |
|
|
private |
Reads the current gameGrid and updates the index.
◆ save()
void GridManager::save |
( |
const std::string & |
saveFile | ) |
|
Save the grid to disk.
- Parameters
-
◆ setGrid() [1/2]
void GridManager::setGrid |
( |
const std::array< std::array< std::uint8_t, 4 >, 4 > & |
newGrid | ) |
|
Sets GridManager::gameGrid.
- Parameters
-
newGrid | The new grid to use |
- Exceptions
-
std::invalid_argument | If the grid is not valid |
◆ setGrid() [2/2]
void GridManager::setGrid |
( |
const std::uint8_t |
newGrid[4][4] | ) |
|
Sets GridManager::gameGrid.
- Parameters
-
newGrid | The new grid to use |
- Exceptions
-
std::invalid_argument | If the grid is not valid |
◆ swapTile() [1/2]
void GridManager::swapTile |
( |
const std::uint8_t |
tileX, |
|
|
const std::uint8_t |
tileY |
|
) |
| |
Swaps the tile at the given coordinates with the no tile.
- Parameters
-
tileX | The x coordinate |
tileY | The y coordinate |
- Exceptions
-
std::invalid_argument | The tile being moved is invalid or not next to the no tile |
◆ swapTile() [2/2]
void GridManager::swapTile |
( |
const std::uint8_t |
tileNum | ) |
|
Swaps the tile given with the no tile.
- Parameters
-
- Exceptions
-
std::invalid_argument | The tile being moved is invalid or not next to the no tile |
◆ validGrid() [1/2]
bool GridManager::validGrid |
( |
const std::array< std::array< std::uint8_t, 4 >, 4 > & |
grid | ) |
|
|
static |
Checks if a grid is valid.
- Parameters
-
- Returns
- If the grid is valid (true) or not (false)
◆ validGrid() [2/2]
bool GridManager::validGrid |
( |
const std::uint8_t |
grid[4][4] | ) |
|
|
static |
Checks if a grid is valid.
- Parameters
-
- Returns
- If the grid is valid (true) or not (false)
◆ validMove() [1/2]
bool GridManager::validMove |
( |
const std::int64_t |
tileNum | ) |
|
Checks if the tile movement will be valid.
- Parameters
-
- Returns
- If swapping the tile would work (true) or not (false)
◆ validMove() [2/2]
bool GridManager::validMove |
( |
const std::int64_t |
tileX, |
|
|
const std::int64_t |
tileY |
|
) |
| |
Checks if the tile movement will be valid.
- Parameters
-
tileX | The tile's x coordinate |
tileY | The tile's y coordinate |
- Returns
- If swapping the tile would work (true) or not (false)
◆ gameGrid
std::array<std::array<std::uint8_t, 4>, 4> Grid15::GridManager::gameGrid {} |
|
private |
◆ GOAL_GRID
constexpr std::uint8_t Grid15::GridManager::GOAL_GRID[4][4] |
|
static |
Initial value:{
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
}
The grid GridManager::gameGrid must be for GridManager::hasWon to be true.
◆ index
std::uint8_t Grid15::GridManager::index[16][2] {} |
|
private |
The index to keep track of tile locations.
◆ NO_TILE
constexpr std::size_t Grid15::GridManager::NO_TILE {0} |
|
static |
The number representing the lack of a tile.
◆ TILE_MAX
constexpr std::size_t Grid15::GridManager::TILE_MAX {15} |
|
static |
◆ TILE_MIN
constexpr std::size_t Grid15::GridManager::TILE_MIN {0} |
|
static |
◆ X_MAX
constexpr std::size_t Grid15::GridManager::X_MAX {3} |
|
static |
The maximum x coordinate.
◆ X_MIN
constexpr std::size_t Grid15::GridManager::X_MIN {0} |
|
static |
The mininum x coordinate.
◆ Y_MAX
constexpr std::size_t Grid15::GridManager::Y_MAX {3} |
|
static |
The maximum y coordinate.
◆ Y_MIN
constexpr std::size_t Grid15::GridManager::Y_MIN {0} |
|
static |
The mininum x coordinate.
The documentation for this class was generated from the following files: