Skip to content

Commit a0cc933

Browse files
committed
Initial
1 parent 0c4082e commit a0cc933

21 files changed

+823
-0
lines changed

.gitignore

Whitespace-only changes.

font/graphiti.ttf

63.6 KB
Binary file not shown.

font/ubuntu.ttf

346 KB
Binary file not shown.

font/ukraine.otf

28.8 KB
Binary file not shown.

images/Button.png

2.32 KB
Loading

images/Button2.png

2.16 KB
Loading

images/Cell.png

495 Bytes
Loading

images/Inform.png

4.44 KB
Loading

images/background.jpg

90 KB
Loading

screenshots/Gameplay1.png

42.9 KB
Loading

screenshots/MainMenu.png

421 KB
Loading

screenshots/Success.png

43.3 KB
Loading

src/Button.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "Button.hpp"
2+
3+
Button::Button(int posX, int posY, String ButtonTexture, String ButtonText , String ButtonFont)
4+
{
5+
this->posX = posX;
6+
this->posY = posY;
7+
this->ButtonText = ButtonText;
8+
isPressed = false;
9+
this->ButtonTexture.loadFromFile("images/" + ButtonTexture);
10+
ButtonSprite.setTexture(this->ButtonTexture);
11+
ButtonSprite.setPosition(this->posX, this->posY);
12+
font.loadFromFile("font/" + ButtonFont);
13+
text.setFont(font);
14+
text.setString(ButtonText);
15+
text.setPosition(this->posX + 30, this->posY + 20);
16+
text.setCharacterSize(45);
17+
text.setColor(Color::Black);
18+
isActivated = true;
19+
}
20+
21+
void Button::ShowButton(RenderWindow & window)
22+
{
23+
window.draw(ButtonSprite);
24+
window.draw(text);
25+
}
26+
27+
void Button::IsCursorOnButton(Vector2f MousePos )
28+
{
29+
if (ButtonSprite.getGlobalBounds().contains(MousePos.x, MousePos.y))
30+
ButtonSprite.setColor(Color(129 , 163 , 220));
31+
else
32+
ButtonSprite.setColor(Color::White);
33+
}
34+
35+
void Button::IsButtonActivated()
36+
{
37+
if (isActivated == true)
38+
ButtonSprite.setColor(Color::Green);
39+
else
40+
ButtonSprite.setColor(Color(127,127,127));
41+
}
42+
43+
void Button::setButtonActivated(bool isActivated)
44+
{
45+
this->isActivated = isActivated;
46+
}
47+
48+
bool Button::getButtonActivated()
49+
{
50+
return isActivated;
51+
}
52+
53+
bool Button::IsClicked(Vector2f MousePos)
54+
{
55+
if (ButtonSprite.getGlobalBounds().contains(MousePos.x, MousePos.y))
56+
return true;
57+
else
58+
return false;
59+
}

src/Button.hpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
#include <SFML\Graphics.hpp>
3+
using namespace sf;
4+
5+
class Button
6+
{
7+
private:
8+
int posX; // позиція кнопки по x
9+
int posY; // позиція кнопки по y
10+
Texture ButtonTexture; // текстура кнопки
11+
Sprite ButtonSprite; // спрайт кнопки
12+
bool isPressed; // чи нажата кнопка
13+
bool isActivated; // чи активна
14+
String ButtonText; // текст кнопки
15+
Font font;
16+
Text text;
17+
public:
18+
Button(int posX, int posY, String ButtonTexture, String ButtonText , String ButtonFont);
19+
void ShowButton(RenderWindow & window); // показує кнопку
20+
void IsCursorOnButton(Vector2f MousePos); // якщо курсор на кнопці , то виділяє його
21+
void IsButtonActivated(); // функція , що зафарбовує клавішу сірим кольором , якщо вона неактивна
22+
bool IsClicked(Vector2f MousePos); // функція , що повертає true якщо клавіша нажата
23+
void setButtonActivated(bool isActivated); // функція , що дозволяє змінити стан клавіши
24+
bool getButtonActivated(); // функція , що дозволяє отримати стан активації клавіши
25+
};

src/GameDesk.cpp

+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
#include "GameDesk.hpp"
2+
#include <iostream>
3+
4+
GameDesk::GameDesk(String DeskTexture , RenderWindow& window)
5+
{
6+
texture = DeskTexture;
7+
GameDeskTexture.loadFromFile("images/" + texture);
8+
SelectCellNum = -1;
9+
isSelected == false;
10+
font.loadFromFile("font/ubuntu.ttf");
11+
text.setFont(font);
12+
text.setColor(Color::Black);
13+
text.setCharacterSize(80);
14+
int tmpi = -2, tmpj = 3;
15+
// у подальшій конструкції ініціалізуються спрайти та виставляються на свої позиції
16+
for (int i = 1; i <= 16; i++)
17+
{
18+
if (i % 4 == 1)
19+
{
20+
tmpi = -2;
21+
tmpj--;
22+
}
23+
GameDeskSprite[i-1].setTexture(GameDeskTexture);
24+
GameDeskSprite[i-1].setPosition(window.getSize().x/2 +tmpi*100 , window.getSize().y/2 - tmpj*100);
25+
tmpi++;
26+
}
27+
// ініціалізується матриця стану клітинок
28+
for (int i = 0; i < 4; i++)
29+
for (int j = 0; j < 4; j++)
30+
DeskStatus[i][j] = 0;
31+
}
32+
33+
// Відображає ігрове поле
34+
void GameDesk::ShowDesk(RenderWindow& window)
35+
{
36+
37+
for (int i = 0; i < 16; i++)
38+
{
39+
int row = i / 4; // отримуємо номер рядка
40+
int col = i % 4; // номер колонки
41+
window.draw(GameDeskSprite[i]);
42+
Vector2f posofSprite = GameDeskSprite[i].getPosition();
43+
posofSprite.x += 23;
44+
posofSprite.y;
45+
if (DeskStatus[row][col] == 'a')
46+
{
47+
text.setPosition(posofSprite);
48+
text.setString("A");
49+
window.draw(text);
50+
}
51+
else if (DeskStatus[row][col] == 'b')
52+
{
53+
text.setPosition(posofSprite);
54+
text.setString("B");
55+
window.draw(text);
56+
}
57+
else if (DeskStatus[row][col] == 'c')
58+
{
59+
text.setPosition(posofSprite);
60+
text.setString("C");
61+
window.draw(text);
62+
}
63+
else if (DeskStatus[row][col] == 'd')
64+
{
65+
text.setPosition(posofSprite);
66+
text.setString("D");
67+
window.draw(text);
68+
}
69+
}
70+
71+
}
72+
73+
void GameDesk::SelectCell(Vector2f pos)
74+
{
75+
for (int i = 0; i < 16; i++)
76+
{
77+
if (GameDeskSprite[i].getGlobalBounds().contains(pos.x, pos.y))
78+
{
79+
if (SelectCellNum != i)
80+
{
81+
82+
GameDeskSprite[i].setColor(Color::Blue); // розфарбовуємо в потрібний колір теперішню клітинку
83+
if (SelectCellNum != -1)
84+
GameDeskSprite[SelectCellNum].setColor(Color::White); //знімаємо виділення з попередньої клітинки
85+
SelectCellNum = i;
86+
isSelected = true;
87+
}
88+
}
89+
}
90+
}
91+
92+
void GameDesk::UpdateGameDeskStatus(Event event)
93+
{
94+
int row = SelectCellNum / 4; // отримуємо номер рядка
95+
int col = SelectCellNum % 4; // номер колонки
96+
if(event.key.code == Keyboard::A)
97+
{
98+
DeskStatus[row][col] = 'a';
99+
}
100+
else if (event.key.code == Keyboard::B)
101+
{
102+
DeskStatus[row][col] = 'b';
103+
}
104+
else if (event.key.code == Keyboard::C)
105+
{
106+
DeskStatus[row][col] = 'c';
107+
}
108+
else if (event.key.code == Keyboard::D)
109+
{
110+
DeskStatus[row][col] = 'd';
111+
}
112+
else if (event.key.code == Keyboard::BackSpace)
113+
{
114+
DeskStatus[row][col] = 0;
115+
}
116+
}
117+
118+
bool GameDesk::IsCellSelect()
119+
{
120+
return isSelected;
121+
}
122+
123+
bool GameDesk::isDeskFull()
124+
{
125+
for (int i = 0; i < 4; i++)
126+
{
127+
for (int j = 0; j < 4; j++)
128+
{
129+
if (DeskStatus[i][j] == 0)
130+
return false;
131+
}
132+
}
133+
return true;
134+
}
135+
136+
137+
138+
bool GameDesk::isWin()
139+
{
140+
//Логіка перевірки така - кожній букві присвоюється певне число . Під час кожного проходу по стовпчиках та рядках буде отримуватись певний добуток , якщо
141+
//він під час якогось проходу відрізняється від потрібного , то тоді виходить що користувач неправильно заповнив поле
142+
//Значення для букв підбирались так , щоб отримати певний добуток можна було отримати однозначно . Викоростовувались значення простих чисел та основна властивість арифметики
143+
int dobutok; // зберігає добуток
144+
// прохід по рядках
145+
for (int i = 0; i < 4; i++)
146+
{
147+
dobutok = 1;
148+
for (int j = 0; j < 4; j++)
149+
{
150+
if (DeskStatus[i][j] == 'a')
151+
dobutok *= 2;
152+
else if (DeskStatus[i][j] == 'b')
153+
dobutok *= 3;
154+
else if (DeskStatus[i][j] == 'c')
155+
dobutok *= 5;
156+
else if (DeskStatus[i][j] == 'd')
157+
dobutok *= 7;
158+
}
159+
if (dobutok != 210)
160+
return false;
161+
}
162+
//прохід по стовпчиках
163+
for (int j = 0; j < 4; j++)
164+
{
165+
dobutok = 1;
166+
for (int i = 0; i < 4; i++)
167+
{
168+
if (DeskStatus[i][j] == 'a')
169+
dobutok *= 2;
170+
else if (DeskStatus[i][j] == 'b')
171+
dobutok *= 3;
172+
else if (DeskStatus[i][j] == 'c')
173+
dobutok *= 5;
174+
else if (DeskStatus[i][j] == 'd')
175+
dobutok *= 7;
176+
}
177+
if (dobutok != 210)
178+
return false;
179+
}
180+
return true;
181+
}
182+
183+
void GameDesk::ReloadGameDesk()
184+
{
185+
for (int i = 0; i < 4; i++)
186+
{
187+
for (int j = 0; j < 4; j++)
188+
{
189+
DeskStatus[i][j] = 0;
190+
}
191+
}
192+
}
193+
194+
int ReurnYourGameTime(int level)
195+
{
196+
if (level <= 6)
197+
return 120;
198+
else if (level <= 10)
199+
return 80;
200+
else if (level <= 14)
201+
return 50;
202+
}

src/GameDesk.hpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
#include <SFML\Graphics.hpp>
3+
using namespace sf;
4+
5+
6+
// клас ігрового поля
7+
class GameDesk
8+
{
9+
private:
10+
String texture;
11+
int DeskStatus[4][4]; // зберігає стан клітинок поля (0 - якщо пуста , а якщо ні , то зберігає код літери)
12+
Texture GameDeskTexture; // зберігає текстуру клітинки поля
13+
Sprite GameDeskSprite[16]; // зберігає спрайти ігрового поля
14+
bool isSelected; // чи вибрана якась клітинка
15+
int SelectCellNum; // зберігає номер виділенної клітинки
16+
Font font;
17+
Text text;
18+
19+
public:
20+
GameDesk(String pathtoTexture , RenderWindow& window); // конструктор , що приймає шлях до текстури поля
21+
void ShowDesk(RenderWindow& window); // відображує поле гри , в параметрах приймає вікно
22+
void SelectCell(Vector2f pos); // виділяємо клітку
23+
void UpdateGameDeskStatus(Event event); // оновлюємо матрицю стану
24+
void ReloadGameDesk(); // очищає ігрове поле
25+
bool IsCellSelect(); // повертає значення isSelected
26+
bool isDeskFull(); // чи заповнене поле до кінця
27+
bool isWin(); // функця , що повертає true якщо користувач виграв
28+
29+
30+
};
31+
32+
// повертає час для режиму гри 1 відповідно до рівня гри
33+
int ReurnYourGameTime(int level);

0 commit comments

Comments
 (0)