1 /** ************************************************************************************************
4 * @brief Playing 3D board.
6 * Provides access to playing elements and enables to control the game.
8 * @author Petr Kubiznak <kubiznak.petr@gmail.com>
12 **************************************************************************************************/
17 //**************************************************************************************************
23 //**************************************************************************************************
25 // predefined game levels (board size and mines count)
26 static const int PRESETS
[3][4] = {
27 { 3, 5, 5, 4 }, //!< rookie (3 layers, 5 rows, 5 columns, 4 mines)
28 { 5, 8, 8, 20 }, //!< advanced
29 { 8, 12, 12, 100 } //!< suicide
32 //**************************************************************************************************
34 /** Implements game board, provides access to game elements (fields). */
37 Field
***board
; //!< Game board, i.e. 3d array of fields.
38 int layers
, rows
, cols
; //!< Size of game board.
39 int minesCount
; //!< Number of mines on the board.
41 /** Puts mines on the board (call once).
42 * @return Zero on success, 1 on fail (too much mines to place on the board). */
44 /** Sets number of mines in neighborhood of each field.
46 int numberBoard(void);
49 /** Enum of all possible game modes (levels). */
50 enum GameMode
{ModeRookie
=0, ModeAdvanced
=1, ModeSuicide
=2, ModeCustom
=3};
53 /** Creates new 3D game board.
54 * @param w Width of the board.
55 * @param h Height of the board.
56 * @param d Depth of the board.
57 * @param minesCount Number of mines to place on the board. */
58 Board(int w
, int h
, int d
, int minesCount
);
59 /** Destroys the board. */
62 /** Returns number of layers of the board.
63 * @return Number of layers. */
64 int getLayersCount(void) const;
65 /** Returns number of rows of the board.
66 * @return Number of rows. */
67 int getRowsCount(void) const;
68 /** Returns number of columns of the board.
69 * @return Number of columns. */
70 int getColsCount(void) const;
71 /** Returns number of mines on the board.
72 * @return Total number of mines. */
73 int getMinesCount(void) const;
75 /** Returns one field on specified position.
76 * @param layer z-coordinate
77 * @param row y-coordinate
78 * @param col x-coordinate
79 * @return Reference to the field. */
80 Field
& getField(int layer
, int row
, int col
) const;
81 /** Returns one field on specified position.
82 * @param layer z-coordinate
83 * @param row y-coordinate
84 * @param col x-coordinate
85 * @return Reference to the field. */
86 Field
& operator () (int layer
, int row
, int col
) const;
88 /** Prints the whole game board CONTENT, i.e. uncovered (for debug use only). */
89 void print(void) const;
90 /* Prints the whole game board in the visible form.
91 * @param os Output stream.
92 * @param board Board to print.
93 * @return Given output stream. */
94 friend ostream
& operator << (ostream
&os
, const Board
&board
);
96 /** Uncoveres given field and, if no mines are there and in the neigbourhood, uncoveres also
98 * @param layer z-coordinate
99 * @param row y-coordinate
100 * @param col x-coordinate
101 * @return True if mine is present on given field, false otherwise. */
102 bool uncover(int layer
, int row
, int col
);
103 /** Checks, whether all the not-mined fields are uncovered.
104 * @return True if no not-mined field remains, false otherwise. */
105 bool isCleared(void) const;
106 /** Returns number of fields MARKED as mined by the user.
107 * @return Number of marked fields. */
108 int getMarkedCount(void) const;
110 /** Returns game mode of this board.
111 * @return ModeRookie, ModeAdvanced, ModeSuicide or ModeCustom, depending on size of this board
112 * and number of placed mines. */
113 Board::GameMode
getMode(void) const;
114 /** Returns game mode of a board with given size and mines count.
115 * @param layers z-coordinate
116 * @param rows y-coordinate
117 * @param cols x-coordinate
118 * @param mines Number of mines placed at the board.
119 * @return ModeRookie, ModeAdvanced, ModeSuicide or ModeCustom, depending on size of this board
120 * and number of placed mines. */
121 static Board::GameMode
getMode(int layers
, int rows
, int cols
, int mines
);
124 #endif /* _BOARD_H */