Skip to content
This repository was archived by the owner on Oct 21, 2020. It is now read-only.

Commit 086ee13

Browse files
author
KonstantinProgger
committed
Окно выигрыша
1 parent 934486c commit 086ee13

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ install(TARGETS tag_puzzle DESTINATION /usr/bin)
3333

3434
install(FILES ${PROJECT_SOURCE_DIR}/res/DejaVuSansMono.ttf ${PROJECT_SOURCE_DIR}/res/tag_icon.png ${PROJECT_SOURCE_DIR}/res/icon.svg ${PROJECT_SOURCE_DIR}/res/Wallpaper.ogg DESTINATION /usr/share/tag_game/res/)
3535

36-
install(FILES ${PROJECT_SOURCE_DIR}/res/tag_puzzle.desktop DESTINATION /usr/share/applications)
36+
install(FILES ${PROJECT_SOURCE_DIR}/res/tag_puzzle.desktop DESTINATION ~/.local/share/applications/)

src/tag_puzzle.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ void tag_puzzle::field_init() {
2929

3030
bits[null_index] = 0;
3131

32+
timer.restart();
33+
3234
srand(time(0));
3335
for(int i{0}; i < 500; i++) this->move_bit((Direction)(rand() % 4));
3436
}
3537

3638
void tag_puzzle::move_bit(Direction step) {
39+
if(timer.getElapsedTime().asSeconds() > 1) if(is_win()) return;
40+
3741
int row = null_index / 4;
3842
int collumn = null_index % 4;
3943

@@ -106,4 +110,44 @@ void tag_puzzle::draw(sf::RenderTarget &target, sf::RenderStates states) const {
106110
target.draw(bit_num, states);
107111
target.draw(bit, states);
108112
}
113+
114+
for(int i{0}; i < 15; i++){
115+
if(bits[i] != i + 1) return;
116+
}
117+
118+
sf::RectangleShape win_place;
119+
win_place.setSize(sf::Vector2f(300, 200));
120+
win_place.setFillColor(sf::Color::Red);
121+
win_place.setPosition(sf::Vector2f(130, 175));
122+
win_place.setOutlineThickness(5.f);
123+
win_place.setOutlineColor(sf::Color::White);
124+
125+
target.draw(win_place, states);
126+
127+
bit_num.setString("You WIN!");
128+
bit_num.setCharacterSize(48);
129+
bit_num.setFillColor(sf::Color::White);
130+
bit_num.setPosition(sf::Vector2f(170, 200));
131+
132+
target.draw(bit_num, states);
133+
134+
bit_num.setString(std::to_string(((int)(((int)timer.getElapsedTime().asSeconds()) / 60))) + " : " + std::to_string(((int)(((int)timer.getElapsedTime().asSeconds()) % 60))));
135+
bit_num.setCharacterSize(48);
136+
bit_num.setPosition(sf::Vector2f(208, 260));
137+
138+
target.draw(bit_num, states);
139+
140+
bit_num.setString("Press F2 to restart & ESC to exit");
141+
bit_num.setCharacterSize(14);
142+
bit_num.setPosition(sf::Vector2f(150, 330));
143+
144+
target.draw(bit_num, states);
145+
}
146+
147+
bool tag_puzzle::is_win() {
148+
for(int i{0}; i < 15; i++){
149+
if(bits[i] != i + 1) return false;
150+
}
151+
152+
return true;
109153
}

src/tag_puzzle.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ class tag_puzzle : public sf::Drawable, public sf::Transformable
3131

3232
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
3333

34+
bool is_win();
3435
private:
3536
sf::Font num_font;
3637

38+
sf::Clock timer;
39+
3740
int bits[16];
3841

3942
int null_index;

0 commit comments

Comments
 (0)