Skip to content

Commit

Permalink
Added files
Browse files Browse the repository at this point in the history
  • Loading branch information
nanda-gopal-sb committed Nov 21, 2024
1 parent 9135be7 commit b97275c
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,49 @@
#define CELL_SIZE 64
#define COLUMNS 8
#define ROWS 8
#define FONT_HEIGHT = 16
struct Cell {
int x;
int y;
bool open;
bool openToPeek;
Cell(int x1, int y1) {
x = x1;
y = y1;
open = false;
}
};

std::vector<Cell> cells;

void fillCell() {
for (int a = 0; a < ROWS; a++) {
for (int b = 0; b < COLUMNS; b++) {
cells.push_back(Cell(b, a));
}
}
}
void drawRec(sf::RenderWindow& window) {
sf::RectangleShape cell_shape(sf::Vector2f(CELL_SIZE - 3, CELL_SIZE - 3));
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLUMNS; j++) {
cell_shape.setPosition(CELL_SIZE * i, CELL_SIZE * j);
cell_shape.setFillColor(sf::Color(73, 98, 185));
if (!cells[i + COLUMNS * j].open)
cell_shape.setFillColor(sf::Color(73, 98, 185));
else
cell_shape.setFillColor(sf::Color(100, 100, 100));
window.draw(cell_shape);
}
}
}

int main() {
auto window = sf::RenderWindow({510u, 510u}, "memory-match");
fillCell();
sf::RenderWindow window = sf::RenderWindow({510u, 510u}, "memory-match");
window.setFramerateLimit(144);
sf::RectangleShape rectangle(sf::Vector2f(50, 50));
while (window.isOpen()) {
for (auto event = sf::Event(); window.pollEvent(event);) {
switch (event.type) {
// If the user clicked the close window button
case sf::Event::Closed: {
// We close the window
window.close();
break;
}
Expand All @@ -35,15 +56,14 @@ int main() {
case sf::Mouse::Left: {
int mouse_x = sf::Mouse::getPosition(window).x / CELL_SIZE;
int mouse_y = sf::Mouse::getPosition(window).y / CELL_SIZE;
std::cout << mouse_x << " " << mouse_y << "\n";
std::cout << "clicked" << "\n";
cells[mouse_x + mouse_y * COLUMNS].open = true;
}
window.clear();
drawRec(window); // PASS BY REFERENCE
window.display();
}
}
}
}
window.clear();
drawRec(window); // PASS BY REFERENCE
window.display();
}
}

0 comments on commit b97275c

Please sign in to comment.