-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (77 loc) · 2.75 KB
/
main.cpp
File metadata and controls
85 lines (77 loc) · 2.75 KB
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
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "setting.h"
#include "render.h"
#include "source.h"
#include "sandData.h"
#include "update.h"
#include "placement.h"
#include "stat.h"
int main()
{
sf::RenderWindow window(
sf::VideoMode(render::windowW, render::windowH),
"Tetrisand",
sf::Style::Titlebar | sf::Style::Close
);
window.setActive(false);
statistics::loadHighScore();
sand::initSandData();
status::curStatus = status::START;
sf::Thread renderThread(render::renderThread, &window);
renderThread.launch();
sf::Thread updateThread(update::updateThread, &window);
updateThread.launch();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
if (status::curStatus == status::START)
{
if (event.key.code == sf::Keyboard::W)
status::curMode = (status::GameMode)std::max(0, status::curMode - 1);
else if (event.key.code == sf::Keyboard::S)
status::curMode = (status::GameMode)std::min((int)status::SURVIVAL, status::curMode + 1);
else if (event.key.code == sf::Keyboard::Enter)
status::curStatus = status::IN_GAME;
}
else if (status::curStatus == status::IN_GAME)
{
if (event.key.code == sf::Keyboard::Left)
placement::curShape.leftRotate();
else if (event.key.code == sf::Keyboard::Right)
placement::curShape.rightRotate();
else if (event.key.code == sf::Keyboard::Escape)
{
sand::reset();
statistics::saveHighScore();
statistics::score = 0;
source::refreshHints();
status::curStatus = status::START;
}
}
else if (status::curStatus == status::FAILED)
{
sand::reset();
statistics::saveHighScore();
statistics::score = 0;
source::refreshHints();
status::curStatus = status::START;
}
break;
case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Left)
placement::placeSand(&window);
}
}
}
statistics::saveHighScore();
return 0;
}