Minesweeper2  V1.1.1 Game in C++ by Górka Mateusz
Field Class Reference

Field of the board. More...

#include <Field.hpp>

Public Member Functions

 Field ()
 Construct a new Field object. More...
 
 Field (uint8_t v)
 Construct a new Field object. More...
 
 Field (FieldCode code)
 Construct a new Field object. More...
 
 Field (const Field &field)
 Copy constructor. More...
 
 ~Field ()=default
 Destroy the Field object (default destructor) More...
 
uint8_t & operator* ()
 Operator of one side *. More...
 
uint8_t val () const
 Return value of field. More...
 
void val (const uint8_t value)
 Set value of field and cover. More...
 
void flag ()
 Set flag on the field. More...
 
void unflag ()
 Delete flag from the field. More...
 
void uncover ()
 Uncover the field. More...
 
bool flagged () const
 Is field flagged? ** flagged field is covered! **. More...
 
bool uncovered () const
 Is field uncovered? (no covered, no flag) More...
 
bool covered () const
 Is field covered? (is covered) More...
 
bool hidden () const
 todo Zamiania uncover, covered, hidden More...
 
bool mine () const
 Is the mine?! More...
 
bool empty () const
 Is the field empty? More...
 

Private Attributes

uint8_t code
 Value of fields code. More...
 

Detailed Description

Field of the board.

  • last 4 bites
    number posible vales code hex
    0 empty -—0000 0x00
    1 - 8 number of mines around 0x01-0x8
    15 mine -—1001 0x09
  • fisrt 4 bites
    States code hex
    cover 0000-— 0x00
    flag 0001-— 0x10
    uncover 0010-— 0x20

Constructor & Destructor Documentation

◆ Field() [1/4]

Field::Field ( )
inline

Construct a new Field object.

34 : code(0x0){}

◆ Field() [2/4]

Field::Field ( uint8_t  v)
inline

Construct a new Field object.

Parameters
v- uint8_t
40 { this->val( v ); }

◆ Field() [3/4]

Field::Field ( FieldCode  code)
inline

Construct a new Field object.

Parameters
code- FieldCode
47  { this->val( static_cast<uint8_t>( code ) ); }

◆ Field() [4/4]

Field::Field ( const Field field)
inline

Copy constructor.

Parameters
field-
53 : code(field.code){}

◆ ~Field()

Field::~Field ( )
default

Destroy the Field object (default destructor)

Member Function Documentation

◆ operator*()

uint8_t& Field::operator* ( )
inline

Operator of one side *.

Returns
uint8_t -
66  { return code; }

◆ val() [1/2]

uint8_t Field::val ( ) const
inline

Return value of field.

Returns
uint8_t - value of field
73  { return (uint8_t) code & 0x0F; }

◆ val() [2/2]

void Field::val ( const uint8_t  value)
inline

Set value of field and cover.

Parameters
value- new value
Postcondition
After that field allways be covered!
81  { code = value; code &= 0x0F; }

◆ flag()

void Field::flag ( )
inline

Set flag on the field.

88  { code &= 0x0F; code |= 0x10; }

◆ unflag()

void Field::unflag ( )
inline

Delete flag from the field.

94  { code &= 0x0F; /*code |= 0x00; //hack */ }

◆ uncover()

void Field::uncover ( )
inline

Uncover the field.

100  { code &= 0x0F; code |= 0x20; }

◆ flagged()

bool Field::flagged ( ) const
inline

Is field flagged? ** flagged field is covered! **.

Returns
true - yes
false - no
110  { return ( code & 0xF0 ) == 0x10; }

◆ uncovered()

bool Field::uncovered ( ) const
inline

Is field uncovered? (no covered, no flag)

Returns
true - yes
false - no
119  { return ( code & 0xF0 ) == 0x20; }

◆ covered()

bool Field::covered ( ) const
inline

Is field covered? (is covered)

Returns
true - yes
false - no
127  { return ( code & 0xF0 ) == 0x00; }

◆ hidden()

bool Field::hidden ( ) const
inline

todo Zamiania uncover, covered, hidden

Warning
uncoverAble change to covered covered to hidden

Is value of fields hidden? (is cover or flagged)

Returns
true - yes
false - no
142  { return ( code & 0xF0 ) != 0x20; }

◆ mine()

bool Field::mine ( ) const
inline

Is the mine?!

Returns
true - yes
false - no
150  { return ( code & 0x0F ) == 0x09; }

◆ empty()

bool Field::empty ( ) const
inline

Is the field empty?

Returns
true - yes
false - no
158  { return ( code & 0x0F ) == 0x00; }

Member Data Documentation

◆ code

uint8_t Field::code
private

Value of fields code.


The documentation for this class was generated from the following file:
Field::val
uint8_t val() const
Return value of field.
Definition: Field.hpp:72
Field::code
uint8_t code
Value of fields code.
Definition: Field.hpp:28