Minesweeper2  V1.1.1 Game in C++ by Górka Mateusz
Game.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Board.hpp"
4 #include "Display.hpp"
5 #include "Const.hpp"
6 #include "SFML/Graphics.hpp"
7 
11 class Game : public sf::Drawable {
12 private:
15 
16  bool buttRev {false};
17  bool running {false};
18 
19  sf::Clock clock;
20  int stopwatch {0};
21  int lastClickTime {0};
22 
23  bool allowHint {false};
24 
25 public:
27  Game() = delete;
28 
34  Game( const int argc, char* argv[] );
35 
39  ~Game() = default;
40 
41 public:
47  void click( const sf::RenderWindow& window, const sf::Mouse::Button butt );
48 
53  inline int time() const { return stopwatch; }
54 
61  inline bool changeClock(){
62  if( running )
63  if( stopwatch != clock.getElapsedTime().asSeconds() ){
64  stopwatch = clock.getElapsedTime().asSeconds();
65  return true;
66  }
67  return false;
68  }
69 
75  inline bool isOn() const
76  { return running; }
77 
81  void finish();
82 
86  void start();
87 
88 private:
95  inline bool firstAction( const sf::Mouse::Button butt ) const
96  { return butt == sf::Mouse::Left ? ! this->buttRev : this->buttRev; }
97 
103  static Vector2D position( const sf::Vector2i& pos );
104 
105 public:
109  void update();
110 
116  void draw( sf::RenderTarget& target, sf::RenderStates states ) const override;
117 
122  inline short int width() const
123  { return this->board.w()*FIELD_SIZE; }
124 
129  inline short int height() const
130  { return this->board.h()*FIELD_SIZE + GUI_MARGIN_T; }
131 
132 };
Game::changeClock
bool changeClock()
Is needed to change clock on the screen? + Change stopwatch value.
Definition: Game.hpp:61
Display.hpp
Vector2D_t< short int >
Game::firstAction
bool firstAction(const sf::Mouse::Button butt) const
Is it first mouse action now?
Definition: Game.hpp:95
Game::width
short int width() const
Width of game window.
Definition: Game.hpp:122
Game::time
int time() const
Stopwatch clock.
Definition: Game.hpp:53
Game::~Game
~Game()=default
Destroy the Game object (default destructor)
GUI_MARGIN_T
#define GUI_MARGIN_T
GUI top margin.
Definition: Const.hpp:20
Game::board
Board board
Board of game.
Definition: Game.hpp:13
Game::allowHint
bool allowHint
Is hint is allowed.
Definition: Game.hpp:23
Game::click
void click(const sf::RenderWindow &window, const sf::Mouse::Button butt)
Click managment.
Definition: Game.cpp:126
Const.hpp
Board
Board of game.
Definition: Board.hpp:11
Game::running
bool running
Is game running on?
Definition: Game.hpp:17
Game::lastClickTime
int lastClickTime
Time of last on the board click (or last hint serching)
Definition: Game.hpp:21
Game::display
Display display
Care about display a game.
Definition: Game.hpp:14
Board::h
int h() const
Height of board.
Definition: Board.hpp:85
Game::Game
Game()=delete
Constructor deleted.
Game::position
static Vector2D position(const sf::Vector2i &pos)
Convert coordinates.
Definition: Game.cpp:174
Game::buttRev
bool buttRev
Current button mode. 0 - normal, 1 - revers button.
Definition: Game.hpp:16
Game::update
void update()
Update values on the interface (stopwatch, score)
Definition: Game.cpp:186
Game::finish
void finish()
Finish the game.
Definition: Game.cpp:107
FIELD_SIZE
#define FIELD_SIZE
Sizes of field on the board.
Definition: Const.hpp:19
Board::w
int w() const
Width of board.
Definition: Board.hpp:78
Board.hpp
Game::isOn
bool isOn() const
Is game on?
Definition: Game.hpp:75
Game::start
void start()
Start the game.
Definition: Game.cpp:113
Game::stopwatch
int stopwatch
Stopwatch value.
Definition: Game.hpp:20
Game
Interface and game organization.
Definition: Game.hpp:11
Game::clock
sf::Clock clock
Stopwatch clock.
Definition: Game.hpp:19
Game::height
short int height() const
Height of game window.
Definition: Game.hpp:129
Game::draw
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
Draw method.
Definition: Game.cpp:178
Display
Care about display on the interface.
Definition: Display.hpp:11