-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.h
108 lines (107 loc) · 2.99 KB
/
functions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#pragma once
const extern sf::Color black, grey, green, yellow;
const std::vector<std::string> alfabet = { "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M", ""};
std::vector<tile> create_all()
{
std::vector<tile> all;
tile a("", grey, false);
for (int i = 0; i < 30; ++i)
{
a.setPosition(105 + (i % 5) * 60, 20 + (i / 5) * 60);
all.emplace_back(a);
}
a.setCollide(true);
for (int i = 0; i < 10; ++i)
{
a.setContent(alfabet[i]);
a.setPosition(50 * i, 440);
all.emplace_back(a);
}
for (int i = 10; i < 19; ++i)
{
a.setContent(alfabet[i]);
a.setPosition(50 * (i - 10) + 25, 493);
all.emplace_back(a);
}
for (int i = 19; i < alfabet.size(); ++i)
{
a.setContent(alfabet[i]);
a.setPosition(50 * (i - 19) + 50, 546);
all.emplace_back(a);
}
return all;
}
void ustaw_pierdolniki(sf::Sprite& restart, sf::Sprite &backspace, tile& reset, tile& lose, sf::Texture& res, sf::Texture& back, sf::RectangleShape& obramowka)
{
obramowka.setFillColor(sf::Color::Transparent);
obramowka.setOutlineThickness(1);
obramowka.setOutlineColor(sf::Color(255, 255, 255, 170));
res.loadFromFile("res\\restart.png");
back.loadFromFile("res\\delete.png");
restart.setTexture(res);
backspace.setTexture(back);
restart.setTextureRect(sf::IntRect(0, 0, 32, 32));
backspace.setTextureRect(sf::IntRect(0, 0, 32, 32));
restart.setPosition(sf::Vector2f(19, 19));
backspace.setPosition(sf::Vector2f(409, 555));
lose.setPosition(200, 380);
lose.setSize(100, 50);
reset.setPosition(10, 10);
}
void wczytaj_slownik(std::vector<std::string>& list, std::map<std::string, bool>& dictionary)
{
std::ifstream plik("res\\slowa.txt");
std::string linia;
while (plik >> linia)
{
list.push_back(linia);
dictionary[linia] = true;
}
plik.close();
}
bool czy_zle(const std::string h)
{
std::vector<bool> uzyte(26, false);
bool ans = false;
for (int i = 0; i < h.size(); ++i)
{
if (uzyte[h[i] - 97])
{
ans = true;
break;
}
uzyte[h[i] - 97] = true;
}
return ans;
}
void to_lower(std::string& s)
{
for (int i = 0; i < s.size(); ++i)
s[i] = s[i] + 32;
}
void porownaj(const int row, const std::string i, const std::string h, std::vector<tile> &all)
{
for (int z = 0; z < 5; ++z)
{
for (int x = 0; x < 5; ++x)
{
if (i[z] != h[x])
continue;
if (z == x)
{
all[row * 5 + z].setColor(green);
for (int j = 30; j < all.size(); ++j)
if (i[z] - 32 == all[j].getText().toAnsiString()[0])
all[j].setColor(green);
continue;
}
all[row * 5 + z].setColor(yellow);
for (int j = 30; j < all.size(); ++j)
if (i[z] - 32 == all[j].getText().toAnsiString()[0] && all[j].getBody().getFillColor() != green)
all[j].setColor(yellow);
}
for (int j = 30; j < all.size(); ++j)
if (i[z] - 32 == all[j].getText().toAnsiString()[0] && all[j].getBody().getFillColor() == grey)
all[j].setColor(black);
}
}