Skip to content

Graphical Minesweeper game using C++, Qt framework demonstrating OOP design, signal-slot mechanism, and GUI handling.

Notifications You must be signed in to change notification settings

soh2970/CPP-minesweeper

Repository files navigation

Minesweeper (Qt GUI Project)

Overview

This project is a graphical implementation of the classic Minesweeper game using the Qt framework in C++. It demonstrates object-oriented design principles such as modularity, encapsulation, and GUI-driven event handling.

Features

  • Graphical Minesweeper grid with configurable board and mine count
  • Left-click to reveal cells, right-click to flag
  • Automatic win/loss detection
  • Game reset via menu
  • Visual indicators for adjacent mines
  • Custom icons for flags and mines

Project Structure

File Purpose
main.cpp Application entry point
mainwindow.cpp/h Handles the main window UI and menu actions
gameboard.cpp/h Manages game grid, mine placement, logic, and gameplay flow
minecell.cpp/h Represents a single cell in the Minesweeper grid
resources.qrc Qt resource file containing icons (e.g., flags, mines)
Minesweeper.pro Qt project file for compilation and build setup

How to Build

Requirements

  • Qt 5 or 6 (tested with Qt 5.x)
  • Qt Creator or command-line qmake and make

Steps

qmake Minesweeper.pro
make
./Minesweeper

Alternatively, open Minesweeper.pro in Qt Creator and click Build & Run.

Gameplay

  • A 30x16 grid with 99 hidden mines is generated at game start
  • Clicking a cell reveals its content:
    • A number: shows count of adjacent mines
    • Blank: recursively reveals empty neighbors
    • Mine: ends the game
  • Right-click toggles flag, question mark, or clears the cell
  • Winning or losing triggers a dialog prompt with reset option

UI Elements

  • Menu Bar: Contains options to start a new game or exit
  • Game Grid: Interactive cells respond to left/right clicks
  • Icons: Used for mines and flags

Object-Oriented Design

  • Encapsulation: Classes like MineCell and GameBoard manage internal state
  • Modularity: Separated UI (MainWindow) from logic (GameBoard, MineCell)
  • Signal-Slot Mechanism: Used to communicate cell clicks and game state changes

License

This project is part of CS 3307B – Object-Oriented Design and Analysis at Western University. For academic use only.

About

Graphical Minesweeper game using C++, Qt framework demonstrating OOP design, signal-slot mechanism, and GUI handling.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published