From b97275c556939641dafe12efab83618b108af64c Mon Sep 17 00:00:00 2001 From: Nandagopal Date: Thu, 21 Nov 2024 21:34:29 +0530 Subject: [PATCH] Added files --- src/main.cpp | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index fbe6944..6cab925 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 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; } @@ -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(); } } \ No newline at end of file