-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
152 lines (139 loc) · 5.98 KB
/
main.cpp
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <iostream>
#include <SFML/graphics.hpp>
#include <SFML/Window.hpp>
#include <vector>
#include <string>
#include "textures.h"
#include "board.h"
#include "leaker.h"
using namespace std;
void debug(sf::RenderWindow &window, string s, sf::Font &font) {
sf::Text text(s, font);
text.setFillColor(sf::Color::White);
text.setStyle(sf::Text::Bold | sf::Text::Underlined);
window.draw(text);
}
int main() {
//textures
vector<string> filenamevect = {"files/images/debug.png", "files/images/digits.png", "files/images/face_happy.png", "files/images/face_lose.png",
"files/images/face_win.png", "files/images/flag.png", "files/images/leaderboard.png", "files/images/mine.png",
"files/images/number_1.png", "files/images/number_2.png", "files/images/number_3.png", "files/images/number_4.png",
"files/images/number_5.png", "files/images/number_6.png", "files/images/number_7.png", "files/images/number_8.png",
"files/images/pause.png", "files/images/play.png", "files/images/tile_hidden.png", "files/images/tile_revealed.png"};
textures texturemanager(filenamevect);
board gameboard(&texturemanager);
string name = gameboard.welcomewindow();
gameboard.setname(name);
bool showleaderboard = false;
bool gameover = false;
bool paused = false;
bool staypaused = false;
bool firstclick = true;
bool gamecontinue = true;
bool pollevents = true;
bool gameend = false;
sf::RenderWindow window(sf::VideoMode(gameboard.getWIDTH(), gameboard.getHEIGHT()), "yay minesweeper", sf::Style::Close);
sf::Clock clock;
if (name.empty())
return 0;
while (window.isOpen())
{
if (showleaderboard) {
gameboard.doleaderboard();
if (!gameover and !firstclick) {
clock.restart();
paused = false;
gameboard.pause();
}
if (staypaused) {
paused = true;
gameboard.pause();
cout << "jaja" << endl;
}
showleaderboard = false;
staypaused = false;
}
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type) {
case sf::Event::Closed:
gameboard.clearall();
window.close();
gameend = true;
break;
case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Left and pollevents)
{
if (event.mouseButton.y < gameboard.getHEIGHT() - 100 and gamecontinue and !paused)
{
int x = event.mouseButton.x / 32;
int y = event.mouseButton.y / 32;
bool temp = gameboard.leftclick(y*gameboard.getboardwidth() +x);
if (firstclick) {
clock.restart();
firstclick = false;
}
if (!temp)
gameover = true;
}
else
{
showleaderboard = false;
string temp = gameboard.buttonclick(sf::Vector2f(event.mouseButton.x, event.mouseButton.y));
if (temp == "restart") {
clock.restart();
gameboard.updateclock(clock.getElapsedTime());
firstclick = true;
gameover = false;
paused = false;
}
if (temp == "paused" and !gameover) {
gameboard.savetime(clock.restart().asSeconds());
clock.restart();
paused = true;
}
if (temp == "unpaused") {
clock.restart();
paused = false;
}
if (temp == "leaderboard") {
if (paused)
staypaused = true;
if (!gameover and !firstclick and !paused) {
cout << "hi" << endl;
gameboard.savetime(clock.restart().asSeconds());
clock.restart();
gameboard.pause();
paused = true;
}
pollevents = false;
showleaderboard = true;
cout << "lol" << endl;
}
temp = "";
}
}
else if (event.mouseButton.button == sf::Mouse::Right and pollevents)
{
if (event.mouseButton.y < gameboard.getHEIGHT() - 100 and gamecontinue) {
int x = event.mouseButton.x / 32;
int y = event.mouseButton.y / 32;
gameboard.rightclick(y*gameboard.getboardwidth() +x);
}
}
}
}
if (gameend)
break;
if (!showleaderboard)
pollevents = true;
if (!gameover and !paused and !firstclick)
gameboard.updateclock(clock.getElapsedTime());
window.clear(sf::Color(215, 215, 215));
gameboard.updatesprites(window);
gameboard.updatebuttons(window);
window.display();
}
return 0;
}