-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (47 loc) · 1.18 KB
/
main.cpp
File metadata and controls
60 lines (47 loc) · 1.18 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
//
// Created by Arthur Yuzeev on 10/18/23.
//
#include <SFML/Graphics.hpp>
#include "game.h"
static sf::RenderWindow window(sf::VideoMode(width, height), "GameOfLife");
extern void app();
sf::RectangleShape getCell(const int i, const int j, const sf::Color color) {
sf::RectangleShape cell(sf::Vector2f(size_cell, size_cell));
cell.setFillColor(color);
cell.setPosition(i * size_cell, j * size_cell);
return cell;
}
void draw(const unsigned int i, const unsigned int j, const bool live) {
if (live) {
window.draw(getCell(i, j, sf::Color::Red));
return;
}
window.draw(getCell(i, j, sf::Color::White));
}
bool flush() {
if (!window.isOpen()) {
return false;
}
window.display();
window.clear();
return true;
}
void initGame() {
window.setFramerateLimit(60);
srand(time(NULL));
}
void checkClose() {
sf::Event event{};
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed ||
event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
window.close();
return;
}
}
}
int main() {
initGame();
app();
return 0;
}