CS152 · CS152 - Object-Oriented Programming
Minesweeper
A Minesweeper coursework project using dynamic memory, structures, linked queues, binary file handling, timers, and mouse interaction, recreated as a responsive browser game.
Overview
Minesweeper was developed as an Object-Oriented Programming coursework project using C++ and the Windows Console API.
The original implementation combines dynamic memory allocation, structures, linked data structures, binary file handling, mouse input, timing, mine generation, neighbour counting, cascade opening, flags, and win detection.
The project was later recreated as a responsive browser game using HTML, CSS, and Vanilla JavaScript.
Dynamic Grid
The C++ implementation dynamically allocates a two-dimensional grid of Cell structures.
Each cell stores:
- Whether it contains a mine
- Whether it is flagged
- Its neighbouring-mine count
- Whether it is open
- Whether it is currently queued for cascade processing
The grid is explicitly released through a matching destruction function.
Cascade Opening
Empty connected areas are opened using a linked queue of Box nodes.
Each queue node stores:
- A row
- A column
- A pointer to the next pending cell
This avoids recursive opening and demonstrates dynamic linked-memory management.
Binary Save and Load
The original game saves its state to a binary file.
Saved information includes:
- Rows and columns
- Mine count
- Opened-cell count
- Flag count
- Game-over state
- Win state
- Elapsed time
- Complete cell data
The load process reconstructs the dynamic grid and restores the saved game state.
Windows Console Interaction
The original version includes:
- Mouse-controlled cell selection
- Open mode
- Flag mode
- Save control
- Load control
- Quit control
- Colored console output
- Live elapsed-time display
Browser Recreation
The web version includes:
- Beginner difficulty
- Intermediate difficulty
- Expert difficulty
- Custom rows, columns, and mine count
- First-open safety
- Open mode
- Flag mode
- Right-click flagging
- Random mine generation
- Neighbour counts
- Queue-based cascade opening
- Live timer
- Win detection
- Mine reveal after loss
- Incorrect-flag indication
- Save and load through browser storage
- Prominent win and loss messages
- Activity log
- Responsive desktop and mobile layout
Technical Approach
The C++ dynamic grid was represented using JavaScript arrays of cell objects.
The linked-queue cascade algorithm was preserved conceptually through an iterative queue that opens connected empty regions without recursion.
Binary file persistence was translated into structured browser local storage.
Corrections
The corrected C++ version conservatively improves:
- Mouse-event type validation
- Actual left-click detection
- Non-numeric input recovery
- Practical grid-size validation
- Saved-file validation
- Mine reveal after a losing move
- Minor naming and dead-code issues
The original submitted source is preserved separately.
Repository Structure
The repository includes:
cpp/— corrected C++ coursework sourcecpp/original/— original submitted source- website root — browser recreation
docs/— fixes and feature-parity documentation
Outcome
The project demonstrates dynamic memory allocation, structures, linked queues, two-dimensional grids, binary serialization, file validation, timing, event-driven interaction, breadth-first expansion, and conversion of a Windows Console game into a polished browser experience.