Projects Inventory

Game of Life (Graphics Version) Gaming Project in C++

Explanation:

  1. Game of Life Rules (updateGrid):
    • The updateGrid function updates the grid according to Conway’s Game of Life rules:
      • A live cell with 2 or 3 live neighbors remains alive; otherwise, it dies.
      • A dead cell with exactly 3 live neighbors becomes alive.
  2. Neighbor Counting (countLiveNeighbors):
    • A lambda function counts the number of live neighbors for a given cell. It iterates over adjacent cells, excluding the cell itself.
  3. Main Function (main):
    • Initializes an SFML window with a specific size.
    • Creates a grid of cells and sets an initial pattern (a glider in this case).
    • Uses a Clock to control the update interval of the grid.
    • Handles events and updates the grid at regular intervals.
    • Clears the window, draws the grid cells, and displays the result.
  4. SFML Graphics:
    • The RectangleShape class is used to draw each cell in the grid. Cells are drawn as black or white rectangles depending on their state (alive or dead).

Possible Enhancements:

Exit mobile version