@@ -10,6 +10,8 @@ Field::Field(int bombs, int sizeMap, int size) :
1010
1111void  Field::generate ()
1212{
13+ 	chunks.clear ();
14+ 	chunks.resize (sizeMap + 2 );
1315	chunks[0 ].resize (sizeMap + 2 );
1416	chunks[sizeMap + 1 ].resize (sizeMap + 2 );
1517	for  (size_t  i = 1 ; i <= sizeMap; i++)
@@ -20,21 +22,21 @@ void Field::generate()
2022			sf::Sprite tmp (TileMapTexture, sf::IntRect (Type::close * size, 0 , size, size));
2123			tmp.setPosition (i * size, j * size);
2224			chunks[i][j].setSprite (tmp);
23- 			chunks[i][j].pos  = { i,j };
25+ 			chunks[i][j].position  = { i,j };
2426		}
2527	}
2628
2729	for  (size_t  i = 0 ; i <= bombs; i++)
2830	{
2931		int  x = dist (gen), y = dist (gen);
30- 		chunks[x][y].logic  = Type::bomb;
32+ 		chunks[x][y].whatIs  = Type::bomb;
3133		for  (int  dx = -1 ; dx < 2 ; dx++)
3234		{
3335			for  (int  dy = -1 ; dy < 2 ; dy++)
3436			{
3537				auto  w = x + dx, z = y + dy;
36- 				if  ((dx != 0  || dy != 0 ) && chunks[w][z].logic  != 9 )
37- 					chunks[w][z].logic  += 1 ;
38+ 				if  ((dx != 0  || dy != 0 ) && chunks[w][z].whatIs  != Type::bomb )
39+ 					chunks[w][z].whatIs  += 1 ;
3840			}
3941		}
4042	}
@@ -44,51 +46,51 @@ void Field::generate()
4446	{
4547		for  (size_t  j = 1 ; j <= sizeMap; j++)
4648		{
47- 			std::cout << chunks[j][i].logic  << "  "  ;
49+ 			std::cout << chunks[j][i].whatIs  << "  "  ;
4850		}
4951		std::cout << " \n "  ;
5052	}
5153
5254}
5355
54- void  Field::setTexture (sf::Texture* texture)
56+ void  Field::setTexture (const   sf::Texture* texture)
5557{
5658	TileMapTexture = *texture;
5759}
5860
59- void  Field::Open (Chunk*  chunk)
61+ void  Field::Open (Chunk&  chunk)
6062{
61- 	if  (chunk-> draws  == 0 )
63+ 	if  (chunk. whatDraw  == Type::empty )
6264		return ;
63- 	if  (chunk-> logic  == 0 ) {
64- 		chunk-> draws  = 0 ;
65+ 	if  (chunk. whatIs  == Type::empty ) {
66+ 		chunk. whatDraw  = Type::empty ;
6567		for  (int  dx = -1 ; dx < 2 ; dx++)
6668		{
6769			for  (int  dy = -1 ; dy < 2 ; dy++)
6870			{
69- 				auto  [x, y] = chunk-> pos ;
71+ 				auto  [x, y] = chunk. position ;
7072				auto  w = x + dx, z = y + dy;
7173				if  (w >= 1  && z >= 1  && w <= sizeMap && z <= sizeMap) {
72- 					if  (chunk-> logic  == 0 ) {
73- 						chunks[w][z].setRect (sf::IntRect (chunks[w][z].logic  * 32 , 0 , 32 , 32 ));
74- 						Open (& chunks[w][z]);
74+ 					if  (chunk. whatIs  == 0 ) {
75+ 						chunks[w][z].setRect (sf::IntRect (chunks[w][z].whatIs  * 32 , 0 , 32 , 32 ));
76+ 						Open (chunks[w][z]);
7577					}
7678				}
7779			}
7880		}
7981	}
8082}
8183
82- Chunk*  Field::contains (const  sf::Vector2f& pos)
84+ Chunk&  Field::contains (const  sf::Vector2f& pos)
8385{
8486	for  (size_t  i = 1 ; i <= sizeMap; i++) {
8587		for  (size_t  j = 1 ; j <= sizeMap; j++) {
8688			if  (chunks[i][j].getSprite ().getGlobalBounds ().contains (pos)) {
87- 				return  & chunks[i][j];
89+ 				return  chunks[i][j];
8890			}
8991		}
9092	}
91- 	return  nullptr ;
93+ 	return  chunks[ 0 ][ 0 ] ;
9294}
9395
9496void  Field::switchRect (Chunk& chunk,int  start)
0 commit comments