forked from CostardRouge/Cuby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCuby.cpp
More file actions
152 lines (132 loc) · 2.76 KB
/
Copy pathCuby.cpp
File metadata and controls
152 lines (132 loc) · 2.76 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
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 "Cuby.hpp"
Cuby::Cuby(void)
{
// Init Attributes
this->quit = false;
this->ressources = new Ressources();
this->settings = new Settings("xml configuration file");
this->display = new SDLDisplay(PROJECT_NAME, this->settings);
// Doing some stuff
this->display->EnableTransparentWindows();
}
Cuby::~Cuby(void)
{
std::list<ASection *>::iterator it;
delete this->display;
delete this->settings;
delete this->ressources;
it = this->sections.begin();
while (it != this->sections.end())
{
delete (*it);
it++;
}
}
void Cuby::UpdateSection(void)
{
std::list<ASection *>::iterator it;
it = this->sections.begin();
while (it != this->sections.end())
{
if ((*it)->getSection() == this->current)
(*it)->UpdateObjects();
it++;
}
}
void Cuby::DrawSection(void)
{
std::list<ASection *>::iterator it;
it = this->sections.begin();
while (it != this->sections.end())
{
if ((*it)->getSection() == this->current)
(*it)->DrawObjects();
it++;
}
}
ASection * Cuby::GetSection(eSection section)
{
std::list<ASection *>::iterator it;
it = this->sections.begin();
while (it != this->sections.end())
{
if ((*it)->getSection() == section)
return ((*it));
it++;
}
exit(11);
return (NULL);
}
void Cuby::HandleEvents(void)
{
eKey pressed;
eEvent event;
event = this->display->HandleEvents();
pressed = this->display->PressedKey();
if (pressed != NOKEY)
{
if (pressed == ESC)
this->quit = true;
}
if (event != NOEVENT)
{
if (event == QUIT)
this->quit = true;
}
}
void Cuby::CreateBlocks(eSection _section)
{
ASection *section;
unsigned int x = 0;
unsigned int y = 0;
unsigned int vertical_blocks;
unsigned int horizontal_blocks;
vertical_blocks = this->display->getHeight() / this->settings->getBlocksize();
horizontal_blocks = this->display->getWidth() / this->settings->getBlocksize();
section = this->GetSection(_section);
if (section != NULL)
while (y <= vertical_blocks)
{
x = 0;
while (x < horizontal_blocks)
{
section->AddObject(new Block(this->settings->getBlocksize(), x, y));
x++;
}
y++;
}
}
void Cuby::Run(void)
{
ASection *section;
this->current = SCREENSAVER;
section = new ASection(SCREENSAVER, this->ressources);
this->sections.push_back(section);
this->sections.push_back(new ASection(HOME, this->ressources));
this->sections.push_back(new ASection(LOGO, this->ressources));
this->CreateBlocks(SCREENSAVER);
while (!this->quit)
{
this->display->Clear();
this->HandleEvents();
this->UpdateSection();
this->DrawSection();
this->display->Refresh();
}
}
int main(int ac, char **av)
{
Cuby *core;
try
{
core = new Cuby();
core->Run();
}
catch (const Exception & e)
{
std::cerr << PROJECT_NAME << " " << e.what() << std::endl;
exit(1);
}
delete core;
return (0);
}