Minesweeper2  V1.1.1 Game in C++ by Górka Mateusz
main.cpp File Reference
#include "SFML/Graphics.hpp"
#include "Game.hpp"
#include "Error.hpp"
#include <iostream>

Functions

int main (int argc, char *argv[])
 Main function. More...
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main function.

Parameters
argc- number of args
argv- values of arg
Returns
int - error code
Return values
0- correct close
  1. Choose sizes of the board.

< Main object of game

  1. Create window
  2. Game loop
17  {
18 
19  try {
21  Game game( argc, argv );
22 
23 
25  RenderWindow window(
26  VideoMode( game.width(), game.height() ),
27  "Minesweeper | maatiug",
28  Style::Close | Style::Titlebar );
29  Event event;
30 
31 
33  bool change = true;
34 
35  while( window.isOpen() ){
36 
37  //* Process events
38  while( window.pollEvent(event) ){
39 
40  // Close window: exit
41  if (event.type == Event::Closed)
42  window.close();
43 
44  try {
45  // Buttons
46  if( ! change ){
47  if( Mouse::isButtonPressed( Mouse::Left ) ){
48  game.click( window, Mouse::Left );
49  sf::sleep( milliseconds(SLEEP_CLICK ) );
50  }
51 
52  if( Mouse::isButtonPressed( Mouse::Right ) ){
53  game.click( window, Mouse::Right );
54  sf::sleep( milliseconds(SLEEP_CLICK ) );
55  }
56 
57  change = true;
58  }
59 
60  }
61  catch( const EndGame& exc ){
62  cout << "End game: " << exc.what() << endl;
63  sf::sleep( milliseconds( SLEEP_ENDGAME ) );
64  game.finish();
65  }
66  }
67 
68  //* Clock
69  if( game.changeClock() ) change = true;
70 
71  //* Display
72  if( change ){
73  // Update game display
74  game.update();
75  // Clear screen
76  window.clear();
77  // Draw the string
78  window.draw( game );
79  // Update the window
80  window.display();
81 
82  change = false;
83  }
84 
85  sf::sleep( milliseconds( SLEEP_LOOP ) );
86 
87  }
88 
89  }
90  catch( const Error& err ){
91  cerr << "!!! Break of program: " << endl;
92  cerr << "! " << err.what() << endl;
93  }
94 
95  return 0;
96 }
EndGame::what
const char * what() const
Definition: Error.hpp:66
SLEEP_ENDGAME
#define SLEEP_ENDGAME
Sleep after end game click.
Definition: Const.hpp:47
Error::what
virtual const char * what() const
Definition: Error.hpp:16
SLEEP_LOOP
#define SLEEP_LOOP
Sleep time of game loop.
Definition: Const.hpp:45
SLEEP_CLICK
#define SLEEP_CLICK
Sleep time after click.
Definition: Const.hpp:46
Error
Error virtual class.
Definition: Error.hpp:14
EndGame
End game exception.
Definition: Error.hpp:60
Game
Interface and game organization.
Definition: Game.hpp:11