Skip to main content

Crate egui_minesweeper

Crate egui_minesweeper 

Source
Expand description

§egui-minesweeper

crates.io docs.rs deps.rs CI Rust version License Live demo

A self-contained Minesweeper game library for egui.

§Features

  • Pure game logic struct (MinesweeperGame) with no egui dependency — usable headlessly or with any renderer
  • Ready-to-use egui Widget (MinesweeperWidget) that renders a fully interactive board
  • Safe first click: mines are placed on the first reveal, guaranteeing the player can never lose immediately
  • Iterative flood-fill reveal (no recursion, safe on large boards)
  • Classic Minesweeper cell styling: raised hidden cells, numbered revealed cells, flagging, mine reveal on loss

§Usage

Add the dependency:

[dependencies]
egui-minesweeper = "0.1"

Then use it in your egui app:

use egui_minesweeper::{MinesweeperGame, MinesweeperWidget};

// Store the game in your app state
let mut game = MinesweeperGame::new(16, 16, 40);

// Inside your egui update/UI closure:
ui.add(MinesweeperWidget::new(&mut game));

// Optionally set a fixed cell size (otherwise fills available space):
ui.add(MinesweeperWidget::new(&mut game).cell_size(32.0));

After each frame you can inspect game.status to check for a win or loss:

use egui_minesweeper::GameStatus;

match game.status {
    GameStatus::Playing => {}
    GameStatus::Won => println!("You won!"),
    GameStatus::Lost => println!("You lost!"),
}

To start a new game with the same settings:

game.reset();

§egui version compatibility

egui-minesweeperegui
0.10.34

§License

Licensed under either of MIT or Apache-2.0 at your option.

Structs§

Cell
A single cell on the Minesweeper board.
MinesweeperGame
The Minesweeper game state.
MinesweeperWidget
An egui widget that renders the minesweeper grid.

Enums§

CellState
The visibility state of a single cell.
GameStatus
The current status of the game.