 |
Minesweeper2
V1.1.1
Game in C++ by Górka Mateusz
|
Interface and game organization.
More...
#include <Game.hpp>
|
bool | firstAction (const sf::Mouse::Button butt) const |
| Is it first mouse action now? More...
|
|
Interface and game organization.
◆ Game() [1/2]
◆ Game() [2/2]
Game::Game |
( |
const int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Construct a new Game object.
- Parameters
-
argc | - number of args |
argv | - values of argso |
If user don't give console args, it will open a GUI menu
Console arguments:
-w
- width of the board
-h
- height of the board
-m
- number of mines
-H
- hints in the game on
--h
, --help
flag
- Unknow argument handling
- Postcondition
-
47 if( argv[
id][0] ==
'-' ){
48 switch( argv[
id][1] ){
52 strm << argv[ ++id ] <<
' ';
58 strm << argv[ ++id ] <<
' ';
64 strm << argv[ ++id ] <<
' ';
75 if( argv[
id][2] ==
'h' ){
83 cerr <<
"!!! Warning: unknow input argument" << endl
84 <<
"! " << argv[id] << endl;
88 cerr <<
"!!! Warning: unknow input argument" << endl
89 <<
"! " << argv[id] << endl;
◆ ~Game()
Destroy the Game object (default destructor)
◆ click()
void Game::click |
( |
const sf::RenderWindow & |
window, |
|
|
const sf::Mouse::Button |
butt |
|
) |
| |
Click managment.
- Parameters
-
window | - window handle |
butt | - mouse button |
- Check the click is in the window
- First action on the board: uncover the field.
- Second action on the covered field: flag the field. If field is uncovered: if it's possible uncover fields around.
- If board isn't created, second move is create and uncover too.
- After correct move:
- Start the game
- If clicked on the board, uncover fields yet
128 Vector2i mouse_pos = Mouse::getPosition(window);
131 if( mouse_pos.x < 0 || mouse_pos.x >
width() )
return;
132 if( mouse_pos.y < 0 || mouse_pos.y >
height() )
return;
◆ time()
Stopwatch clock.
- Returns
- int -
◆ changeClock()
bool Game::changeClock |
( |
| ) |
|
|
inline |
Is needed to change clock on the screen? + Change stopwatch value.
- Postcondition
- stopwatch value change
- Returns
- true - yes
-
false - no
◆ isOn()
bool Game::isOn |
( |
| ) |
const |
|
inline |
Is game on?
- Returns
- true - yes
-
false - no
◆ finish()
◆ start()
Start the game.
- Stopwatch clear
- Clear board
- Restart the board
- Start running mode
◆ firstAction()
bool Game::firstAction |
( |
const sf::Mouse::Button |
butt | ) |
const |
|
inlineprivate |
Is it first mouse action now?
- Parameters
-
- Returns
- true - yes
-
false - no
96 {
return butt == sf::Mouse::Left ? ! this->
buttRev : this->
buttRev; }
◆ position()
Vector2D Game::position |
( |
const sf::Vector2i & |
pos | ) |
|
|
staticprivate |
Convert coordinates.
- Parameters
-
pos | - position on the window |
- Returns
- Vector2D - position on the board
◆ update()
Update values on the interface (stopwatch, score)
- Update info in the window
- Check the hint
◆ draw()
void Game::draw |
( |
sf::RenderTarget & |
target, |
|
|
sf::RenderStates |
states |
|
) |
| const |
|
override |
◆ width()
short int Game::width |
( |
| ) |
const |
|
inline |
Width of game window.
- Returns
- short int - width
◆ height()
short int Game::height |
( |
| ) |
const |
|
inline |
Height of game window.
- Returns
- short int - height
◆ board
◆ display
Care about display a game.
◆ buttRev
bool Game::buttRev {false} |
|
private |
Current button mode. 0 - normal, 1 - revers button.
◆ running
bool Game::running {false} |
|
private |
◆ clock
◆ stopwatch
◆ lastClickTime
int Game::lastClickTime {0} |
|
private |
Time of last on the board click (or last hint serching)
◆ allowHint
bool Game::allowHint {false} |
|
private |
The documentation for this class was generated from the following files:
void board(sf::RenderTarget &target, const Board *const board) const
Display board on the window.
Definition: Display.cpp:121
#define DEFAULT_X_SIZE
Default X size of board.
Definition: Const.hpp:9
void stopwatch(unsigned int seconds)
Update a value of stopwatch time.
Definition: Display.cpp:89
bool firstAction(const sf::Mouse::Button butt) const
Is it first mouse action now?
Definition: Game.hpp:95
short int width() const
Width of game window.
Definition: Game.hpp:122
int time() const
Stopwatch clock.
Definition: Game.hpp:53
void drawStart(sf::RenderTarget &target) const
Draw start button on interface.
Definition: Display.hpp:101
#define GUI_MARGIN_T
GUI top margin.
Definition: Const.hpp:20
void set(unsigned int w, unsigned int h, unsigned int m)
Set values on the board.
Definition: Board.cpp:208
void hideHint()
Hide a hint.
Definition: Display.hpp:119
Vector2D * hintPos
Position of hint, NULL if no hint to display.
Definition: Display.hpp:49
Board board
Board of game.
Definition: Game.hpp:13
bool allowHint
Is hint is allowed.
Definition: Game.hpp:23
void click(const sf::RenderWindow &window, const sf::Mouse::Button butt)
Click managment.
Definition: Game.cpp:126
#define HINT_TIME
Time to display a hint after correct click [s].
Definition: Const.hpp:11
bool running
Is game running on?
Definition: Game.hpp:17
void mineCounter(short signed int mine)
Update value of mine on the display.
Definition: Display.cpp:99
bool created() const
Is array created?
Definition: Board.hpp:93
short int noFlaggedMines() const
Number of no flagged mines on the board.
Definition: Board.hpp:70
int lastClickTime
Time of last on the board click (or last hint serching)
Definition: Game.hpp:21
Display display
Care about display a game.
Definition: Game.hpp:14
const char *const HELP_INFO
Help messege.
Definition: Game.cpp:13
void config(const Vector2D &size)
Config a Display class.
Definition: Display.cpp:30
int h() const
Height of board.
Definition: Board.hpp:85
#define DEFAULT_Y_SIZE
Default Y size of board.
Definition: Const.hpp:8
static Vector2D position(const sf::Vector2i &pos)
Convert coordinates.
Definition: Game.cpp:174
bool buttRev
Current button mode. 0 - normal, 1 - revers button.
Definition: Game.hpp:16
bool uncover(const Vector2D &click)
Uncover the choosen field.
Definition: Board.cpp:23
void restart()
Restart the board.
Definition: Board.cpp:223
void draw(sf::RenderTarget &target) const
Draw a interface of the game.
Definition: Display.cpp:106
#define FIELD_SIZE
Sizes of field on the board.
Definition: Const.hpp:19
int w() const
Width of board.
Definition: Board.hpp:78
#define DEFAULT_MINE
Default number of mines.
Definition: Const.hpp:10
bool isOn() const
Is game on?
Definition: Game.hpp:75
void start()
Start the game.
Definition: Game.cpp:113
Vector2D_t< short int > Vector2D
Vector2D typedef.
Definition: Vector2D.hpp:126
int stopwatch
Stopwatch value.
Definition: Game.hpp:20
bool hint(Vector2D *&pos) const
Find a hint for player with AI.
Definition: Board.cpp:114
End game exception.
Definition: Error.hpp:60
bool action(const Vector2D &click)
Do second action on selected field.
Definition: Board.cpp:76
sf::Clock clock
Stopwatch clock.
Definition: Game.hpp:19
void changeButt(const bool mode)
Change a view of mode button.
Definition: Display.cpp:75
short int height() const
Height of game window.
Definition: Game.hpp:129