 |
Minesweeper2
V1.1.1
Game in C++ by Górka Mateusz
|
Mange a menu GUI on the begin of game.
More...
#include <Menu.hpp>
|
| Menu () |
| Construct a new Menu object. More...
|
|
| ~Menu ()=default |
| Destroy the Menu object (default) More...
|
|
void | draw (sf::RenderTarget &target, sf::RenderStates states) const override |
| Draw method. More...
|
|
void | update () |
| Update text values to display. More...
|
|
bool | click (const sf::RenderWindow &window) |
| Click manage on menu GUI. More...
|
|
void | output (int &argc, char **&argv) |
| Create argv and argc based on GUI menu. More...
|
|
void | change (unsigned short &val, const short int change, const short int minval, const short int maxval) |
| Change value. More...
|
|
|
static void | handling (int &argc, char **&argv) |
| Menu GUI handling. More...
|
|
static void | clean (const int argc, char **&argv) |
| Delete argv table. More...
|
|
static bool | inside (const sf::Vector2i &pos, const sf::Vector2i &coo, const sf::Vector2i &size) |
| Is position pos is in the rectangle of coordinates coo and sizes size More...
|
|
static bool | insideX (const sf::Vector2i &pos, const sf::Vector2i &coo, const sf::Vector2i &size) |
| Is pos.x is bigger than coo.x and smoller coo.x + size.x. More...
|
|
Mange a menu GUI on the begin of game.
◆ Menu()
Construct a new Menu object.
- Load menu GUI background texture
- Init spirte of menu background
- Load font
- Texts init
◆ ~Menu()
Destroy the Menu object (default)
◆ draw()
void Menu::draw |
( |
sf::RenderTarget & |
target, |
|
|
sf::RenderStates |
states |
|
) |
| const |
|
override |
◆ update()
Update text values to display.
- Update width txt
- Update height txt
- Update mines txt
- Update hints state
233 strm << out_width << ' '; strm >> s;
237 strm << out_height << ' '; strm >> s;
241 strm << out_mines << ' '; strm >> s;
◆ handling()
void Menu::handling |
( |
int & |
argc, |
|
|
char **& |
argv |
|
) |
| |
|
static |
Menu GUI handling.
- Postcondition
-
- Parameters
-
argc | - size of argv[] (out) |
argv | - values of init argument to game (out) |
- Create window and GUI object
- GUI loop
- Make w new argv listx`
51 "Minesweeper | maatiug",
52 Style::Close | Style::Titlebar );
60 while( window.isOpen() ){
63 while( window.pollEvent(event) ){
66 if (event.type == Event::Closed)
71 if( Mouse::isButtonPressed( Mouse::Left ) ){
73 if( menu.
click( window ) )
103 menu.
output( argc, argv );
◆ click()
bool Menu::click |
( |
const sf::RenderWindow & |
window | ) |
|
Click manage on menu GUI.
- Parameters
-
177 Vector2i mouse_pos = Mouse::getPosition(window);
◆ output()
void Menu::output |
( |
int & |
argc, |
|
|
char **& |
argv |
|
) |
| |
Create argv and argc based on GUI menu.
- Parameters
-
argc | - [out] length of argument list |
argv | - [out] argument list (array) |
- Clean existing argv
- Create new argv
133 argv =
new char*[ argc ];
140 argv[1] =
new char[3];
141 strm <<
"-w\0" <<
' ';
144 argv[2] =
new char[3];
149 argv[3] =
new char[3];
150 strm <<
"-h\0" <<
' ';
153 argv[4] =
new char[3];
158 argv[5] =
new char[3];
159 strm <<
"-m\0" <<
' ';
162 argv[6] =
new char[4];
168 argv[7] =
new char[4];
169 strm <<
"-H\0" <<
' ';
◆ change()
void Menu::change |
( |
unsigned short & |
val, |
|
|
const short int |
change, |
|
|
const short int |
minval, |
|
|
const short int |
maxval |
|
) |
| |
Change value.
- Parameters
-
val | - [out] changed values |
change | - change |
minval | - min value of val |
maxval | - max value of val |
◆ clean()
void Menu::clean |
( |
const int |
argc, |
|
|
char **& |
argv |
|
) |
| |
|
static |
Delete argv table.
- Parameters
-
argc | - size of argv[] |
argv | - char** array of arrays to delete |
◆ inside()
bool Menu::inside |
( |
const sf::Vector2i & |
pos, |
|
|
const sf::Vector2i & |
coo, |
|
|
const sf::Vector2i & |
size |
|
) |
| |
|
static |
Is position pos
is in the rectangle of coordinates coo
and sizes size
- coo is a bottom-left corner of rectangle
- [0,0] pos is a top-left corner of window
- Parameters
-
pos | - position |
coo | - cooridnates of rectangle |
size | - sizes of rectangle |
259 if( pos.y > coo.y && pos.y < coo.y + size.y )
260 if( pos.x > coo.x && pos.x < coo.x + size.x )
◆ insideX()
static bool Menu::insideX |
( |
const sf::Vector2i & |
pos, |
|
|
const sf::Vector2i & |
coo, |
|
|
const sf::Vector2i & |
size |
|
) |
| |
|
inlinestatic |
Is pos.x is bigger than coo.x and smoller coo.x + size.x.
- Parameters
-
pos | - position |
coo | - coordinates of 'line' |
size | - size of 'line' |
- Returns
- true -
-
false -
119 {
return pos.x > coo.x && pos.x < coo.x + size.x; }
◆ font
◆ menu_texture
sf::Texture Menu::menu_texture |
|
private |
Menu GUI background texture.
◆ menu_bg
Menu GUI background spirte.
◆ width_txt
Text to display width of the board.
◆ height_txt
sf::Text Menu::height_txt |
|
private |
Text to display height of the board.
◆ mines_txt
Text to display number mines on the board.
◆ hints_txt
Text to display number mines on the board.
◆ out_width
◆ out_height
◆ out_mines
Number of mines on the window.
◆ allowHints
bool Menu::allowHints {false} |
|
private |
Is hints will be allowed.
The documentation for this class was generated from the following files:
#define MENU_SIZE_HINTTXT
GUI Menu size of font hints state.
Definition: Const.hpp:95
#define MENU_X_MINUS
GUI Menu X of button '-'.
Definition: Const.hpp:77
#define MENU_XY_HINT
GUI Menu X, Y position of hints button.
Definition: Const.hpp:92
#define MENU_X_SMALL
GUI Menu X of button 'small'.
Definition: Const.hpp:70
#define GUI_MENU_W
Width of GUI menu window.
Definition: Const.hpp:67
#define MENU_X_PLUS
GUI Menu X of button '+'.
Definition: Const.hpp:79
#define GUI_MENU_H
Height of GUI menu window.
Definition: Const.hpp:68
#define SMALL_WIDTH
Width of small board.
Definition: Const.hpp:54
#define MENU_Y_WIDTH
GUI Menu Y of text of width.
Definition: Const.hpp:88
#define MENU_SIZE_VAL
GUI Menu size of font size of width, height and mines values.
Definition: Const.hpp:86
#define MENU_X_BIG
GUI Menu X of button 'big'.
Definition: Const.hpp:71
#define MENU_H_SIZES
GUI Menu height of sizes buttons.
Definition: Const.hpp:75
sf::Font LoadFontFromResource(const char *const name)
Create a new sf::Font and load it from resoruces.
Definition: Func.cpp:28
#define HUGE_WIDTH
Width of huge board.
Definition: Const.hpp:62
#define MENU_Y_HEIGHT
GUI Menu Y of text of height.
Definition: Const.hpp:89
#define MENU_Y_SIZES
GUI Menu Y of sizes buttons.
Definition: Const.hpp:73
#define MENU_X_2PLUS_B
GUI Menu X of button '++' for number of mines.
Definition: Const.hpp:82
#define HUGE_MINES
Mines of huge board.
Definition: Const.hpp:64
#define BIG_HEIGHT
Height of big board.
Definition: Const.hpp:59
sf::Texture LoadTextureFromResource(const char *const name)
Creates a new sf::Texture and loads it with Texture data from a resource (.rc) file https://github....
Definition: Func.cpp:6
#define BIG_MINES
Mines of big board.
Definition: Const.hpp:60
#define SLEEP_LOOP
Sleep time of game loop.
Definition: Const.hpp:45
#define MENU_X_VALUES
GUI Menu X of text values width, height, number of mines.
Definition: Const.hpp:87
#define BIG_WIDTH
Width of big board.
Definition: Const.hpp:58
#define MENU_W_SIZES
GUI Menu width of sizes buttons.
Definition: Const.hpp:74
#define MENU_X_2PLUS
GUI Menu X of button '++'.
Definition: Const.hpp:80
#define SLEEP_CLICK
Sleep time after click.
Definition: Const.hpp:46
#define MENU_X_HUGE
GUI Menu X of button 'huge'.
Definition: Const.hpp:72
#define SMALL_MINES
Mines of small board.
Definition: Const.hpp:56
#define HUGE_HEIGHT
Height of huge board.
Definition: Const.hpp:63
#define MENU_H_PM
GUI Menu height of buttons -, –, +, ++.
Definition: Const.hpp:84
#define MENU_W_PM
GUI Menu width of buttons -, –, +, ++.
Definition: Const.hpp:83
#define MENU_WH_HINT
GUI Menu width, height of hints button.
Definition: Const.hpp:93
#define MENU_XY_HINTTXT
GUI Menu position of off/on txt on hits button.
Definition: Const.hpp:94
#define MENU_Y_MINES
GUI Menu Y of text of number of mines.
Definition: Const.hpp:90
#define SMALL_HEIGHT
Height of small board.
Definition: Const.hpp:55
#define MENU_X_PLUS_B
GUI Menu X of button '+' for number of mines.
Definition: Const.hpp:81
#define MENU_X_2MINUS
GUI Menu X of button '–'.
Definition: Const.hpp:78
#define MENU_XY_START
GUI Menu X, Y position of start button.
Definition: Const.hpp:97