Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Commit c8c158c

Browse files
committed
Final
I throw this project - may be return..... :(
1 parent eb2df62 commit c8c158c

File tree

8 files changed

+53
-57
lines changed

8 files changed

+53
-57
lines changed

Minesweeper/Minesweeper.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@
110110
<LanguageStandard>stdcpp17</LanguageStandard>
111111
</ClCompile>
112112
<Link>
113-
<SubSystem>Console</SubSystem>
113+
<SubSystem>Windows</SubSystem>
114114
<EnableCOMDATFolding>true</EnableCOMDATFolding>
115115
<OptimizeReferences>true</OptimizeReferences>
116116
<GenerateDebugInformation>true</GenerateDebugInformation>
117117
<AdditionalLibraryDirectories>$(SolutionDir)ExLibs\SFML\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
118-
<AdditionalDependencies>winmm.lib;opengl32.lib;freetype.lib;gdi32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;openal32.lib;sfml-graphics-s.lib;sfml-window-s.lib;sfml-audio-s.lib;sfml-system-s.lib;%(AdditionalDependencies)</AdditionalDependencies>
118+
<AdditionalDependencies>sfml-main.lib;winmm.lib;opengl32.lib;freetype.lib;gdi32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;openal32.lib;sfml-graphics-s.lib;sfml-window-s.lib;sfml-audio-s.lib;sfml-system-s.lib;%(AdditionalDependencies)</AdditionalDependencies>
119119
</Link>
120120
</ItemDefinitionGroup>
121121
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">

Minesweeper/src/game/Loader/DataLoader.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#include "DataLoader.h"
22

3-
#include <iostream>
4-
#include <vector>
5-
63
namespace fs = std::filesystem;
74

85
DataLoader::DataLoader(std::string_view path)
@@ -36,7 +33,6 @@ DataLoader::DataLoader(std::string_view path)
3633
std::unique_ptr<sf::Texture> DataLoader::getTexture(std::string_view name) const
3734
{
3835
if (auto it = textureStorage.find(name.data()); it != textureStorage.end()) {
39-
4036
return std::make_unique<sf::Texture>(it->second);
4137
}
4238
return std::make_unique<sf::Texture>();
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#pragma once
22

3-
#include<map>
4-
#include<string>
5-
#include<string_view>
6-
#include<SFML/Graphics.hpp>
7-
#include<filesystem>
8-
#include<memory>
3+
#include <SFML/Graphics.hpp>
4+
#include <iostream>
5+
#include <vector>
6+
#include <map>
7+
#include <string>
8+
#include <string_view>
9+
#include <filesystem>
10+
#include <memory>
911

1012
class DataLoader
1113
{
@@ -15,12 +17,8 @@ class DataLoader
1517
std::unique_ptr<sf::Texture> getTexture(std::string_view name) const;
1618
std::unique_ptr<sf::Font> getFont(std::string_view name) const;
1719
~DataLoader() = default;
18-
private:
19-
2020
private:
2121
std::map<std::string, sf::Texture> textureStorage;
2222
std::map<std::string, sf::Font> fontStorage;
23-
//std::map<std::string, sf::> soundStorage;
24-
//also can use any :)
2523
};
2624

Minesweeper/src/game/Map/chunk.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ class Chunk
88
sf::Sprite& getSprite();
99
void setRect(sf::IntRect);
1010
~Chunk() = default;
11+
private:
12+
const int closeChunk = 10;
13+
const int emptyCeil = 0;
1114
public:
12-
int logic = 0;
13-
int draws = 10;
14-
std::pair<int, int> pos = {-1,-1};
15+
int whatIs = emptyCeil;
16+
int whatDraw = closeChunk;
17+
std::pair<int, int> position = {-1,-1};
1518
private:
1619
sf::Sprite chunk;
1720
};

Minesweeper/src/game/Map/map.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Field::Field(int bombs, int sizeMap, int size) :
1010

1111
void 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

9496
void Field::switchRect(Chunk& chunk,int start)

Minesweeper/src/game/Map/map.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#include <SFML/Graphics.hpp>
2-
32
#include <vector>
43
#include <random>
54
#include <iostream>
6-
75
#include "chunk.h"
86

97
class Field
@@ -26,12 +24,12 @@ class Field
2624
};
2725
//10 10 32
2826
Field(int bombs,int sizeMap,int size);
29-
Chunk* contains(const sf::Vector2f&);
27+
Chunk& contains(const sf::Vector2f&);
3028
void switchRect(Chunk&,int);
3129
std::vector<std::vector<Chunk>>& getField();
3230
void generate();
33-
void setTexture(sf::Texture* texture);
34-
void Open(Chunk* chunk);
31+
void setTexture(const sf::Texture* texture);
32+
void Open(Chunk& chunk);
3533
~Field() = default;
3634
private:
3735
std::vector<std::vector<Chunk>> chunks;

Minesweeper/src/game/game.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,38 +50,37 @@ void Game::HandleEvent()
5050
void Game::collision(int key)
5151
{
5252
auto mousePos = static_cast<sf::Vector2f>(sf::Mouse::getPosition(window));
53-
if (auto chunk = field.contains(mousePos); chunk != nullptr) {
54-
updateCeil(key, chunk);
55-
}
53+
auto& chunk = field.contains(mousePos);
54+
updateCeil(key, chunk);
5655
}
5756

5857
//awful code
59-
void Game::updateCeil(int key,Chunk*& chunk)
58+
void Game::updateCeil(int key,Chunk& chunk)
6059
{
6160
if (key == sf::Mouse::Left) {
62-
field.switchRect(*chunk, chunk->logic);
63-
if (chunk->logic == Field::bomb) {
61+
field.switchRect(chunk, chunk.whatIs);
62+
if (chunk.whatIs == Field::bomb) {
6463
message.setString("You Lose");
6564
state = States::lose;
6665
}
6766
else {
6867
field.Open(chunk);
6968
}
70-
chunk->draws = chunk->logic;
69+
chunk.whatDraw = chunk.whatIs;
7170
}
7271
else if (key == sf::Mouse::Right) {
73-
if (chunk->draws == Field::flag) {
72+
if (chunk.whatDraw == Field::flag) {
7473
flags--;
75-
if (chunk->logic == Field::bomb) {
74+
if (chunk.whatIs == Field::bomb) {
7675
scores--;
7776
}
78-
chunk->draws = Field::close;
79-
chunk->setRect(sf::IntRect(Field::close * 32, 0, 32, 32));
77+
chunk.whatDraw = Field::close;
78+
chunk.setRect(sf::IntRect(Field::close * 32, 0, 32, 32));
8079
}
81-
else if (flags<=bombs && chunk->draws == Field::close) {
82-
chunk->draws = Field::flag;
83-
chunk->setRect(sf::IntRect(Field::flag * 32, 0, 32, 32));
84-
if (chunk->logic == Field::bomb) {
80+
else if (flags<=bombs && chunk.whatDraw == Field::close) {
81+
chunk.whatDraw = Field::flag;
82+
chunk.setRect(sf::IntRect(Field::flag * 32, 0, 32, 32));
83+
if (chunk.whatIs == Field::bomb) {
8584
scores++;
8685
}
8786
flags++;

Minesweeper/src/game/game.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Game
1717
void HandleEvent();
1818
void drawEntity();
1919
void collision(int key);
20-
void updateCeil(int key, Chunk*& chunk);
20+
void updateCeil(int key, Chunk& chunk);
2121
private:
2222
sf::RenderWindow window;
2323
Field field;

0 commit comments

Comments
 (0)