added libs and oalist
[mines3d.git] / core / field.h
blobb4a3d67a2513604275587e6e537b153733ea5394
1 /** ************************************************************************************************
2 * @file board.h
3 *
4 * @brief One field of game board.
5 *
6 * Data structure representing one field, provides protected and unprotected access.
7 *
8 * @author Petr Kubiznak <kubiznak.petr@gmail.com>
9 *
10 * @since 2009-11-??
12 **************************************************************************************************/
14 #ifndef _FIELD_H
15 #define _FIELD_H
17 //**************************************************************************************************
19 // data bitfield masks
20 #define MASK_NEIGHBOURS 0x001F //!< Number of mines in the neighbourhood.
21 #define MASK_COVERED 0x0020 //!< Covered flag.
22 #define MASK_MARK 0x0040 //!< Mark flag.
23 #define MASK_MINE 0x0080 //!< Mine flag.
24 #define MASK_UNKNOWN 0x0100 //!< Unknown flag (second mark).
25 #define MASK_REMAINING 0x3E00 //!< Number of NOT MARKED mines in the neighbourhood.
26 #define MASK_REMAINING_SIGN 0x4000 //!< Sign of remaining mines count. Is set for minus.
28 // shifts of integer values
29 #define MASK_NEIGHBOURS_SHIFT 0
30 #define MASK_REMAINING_SHIFT 9
32 //**************************************************************************************************
34 /** Implements data structure representing one field of the board. */
35 class Field {
36 protected:
37 unsigned short int data; //!< data of the structure - bitfield of flags and values
39 /** Gets the number of UNMARKED mines arround this field.
40 * @return Number of hiden mines according to user marks. The number does not
41 * have to correspond to real unmarked number - it corresponds to what the USER THINKS
42 * that is the reality. */
43 inline int getRemainingNeighboursCntNE(void) const;
45 /** Sets the covered-bit.
46 * @param setVal Use true to cover the field, false to uncover. */
47 inline void setCovered(bool setVal);
49 public:
50 /** Creates new object of the class.
51 * @param val Bitfield content - be careful. Use default value to create implicit, covered field. */
52 Field(unsigned short int val = MASK_COVERED);
53 /** Frees allocated resources. */
54 ~Field(void);
56 /** Checks whether the field contains mine.
57 * @return True if mine is present in the field, false otherwise. */
58 bool hasMine(void) const;
59 /** Sets, whether the field contains a mine.
60 * @setVal Use true to set mine, false to unset. */
61 void setMine(bool setVal);
62 /** Checks whether the field is user-marked as mined.
63 * @return True if field is marked, false otherwise. */
64 bool hasMark(void) const;
65 /** Sets the user-mark.
66 * @setVal Use true to mark as mined, false to unmark.
67 * @throw AccessForbiddenException if the field is already uncovered. */
68 void setMark(bool setVal);
69 /** Checks whether the field is covered.
70 * @return True if it is covered, false if uncovered. */
71 bool isCovered(void) const;
72 /** Uncovers the field.
73 * @return Number of mines hidden in field arround this one. */
74 int uncover(void);
75 /** Stores the number of mines hidden arround this field.
76 * @param count Number of hiden mines. */
77 void setNeighboursCnt(int count);
78 /** Gets the number of mines arround this field.
79 * @return Number of hiden mines.
80 * @throw AccessForbiddenException if the field is still covered. */
81 int getNeighboursCnt(void) const;
82 /** Stores the number of UNMARKED mines hidden arround this field.
83 * @param count Number of UNMARKED hiden mines (according to user marks). The number does not
84 * have to correspond to real unmarked number - it corresponds to what the USER THINKS
85 * that is the reality. */
86 void setRemainingNeighboursCnt(int count);
87 /** Adds given increment to current value of UNMARKED mines hidden arround this field.
88 * @param increment Value to add to the actual value. */
89 void fixRemainingNeighboursCnt(int increment);
90 /** Gets the number of UNMARKED mines arround this field.
91 * @return Number of hiden mines according to user marks. The number does not
92 * have to correspond to real unmarked number - it corresponds to what the USER THINKS
93 * that is the reality.
94 * @throw AccessForbiddenException if the field is still covered. */
95 int getRemainingNeighboursCnt(void) const;
97 /** Casts the Field to int.
98 * @return The inner data representation, i.e. bitfield. */
99 operator int (void) const;
103 //**************************************************************************************************
105 #endif /* _FIELD_H */