NOTE: If you has been already using a version of Minesweeper Clone prior to version 2006 release 1 (verison 0.97 beta and earlier) and want to keep using your previous history file, it is important to remember to import it to the new Clone 2006/2007 format. Download this game from Microsoft Store for Windows 10, Windows 10 Mobile, Windows 10 Team (Surface Hub), HoloLens. See screenshots, read the latest customer reviews, and compare ratings for Microsoft Minesweeper. In fact, an accurate clone is the only way to create a bootable backup of a Mac OS X disk—a backup that lets you get back up and running in a matter of minutes, as opposed to the hours it might.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Audio & Multimedia|Business Software|Development Tools|Education|Games|Graphics Software|Network & Internet|System Utilities|Mac Tools|Linux Programs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
free. software downloads|Submit Software|Contact Us|Privacy Policy|Disclaimer|Link to Download32|Bookmark Us | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
All software information on this site, is solely based on what our users submit. Download32.com disclaims that any right and responsibility for the information go to the user who submit the software, games, drivers. Some software may not have details explanation or their price, program version updated. You should contact the provider/actual author of the software for any questions. There are also user reviews/comments posted about various software downloads, please contact us if you believe someone has posted copyrighted information contained on this web site. Copyright © 1996-2015 Download 32. |
Moonsweeper is a single-player puzzle video game. The objective of the game is to explore the area around your landed space rocket, without coming too close to the deadly B'ug aliens. Your trusty tricounter will tell you the number of B'ugs in the vicinity.
This a simple single-player exploration game modelled on Minesweeper where you must reveal all the tiles without hitting hidden mines. This implementation uses custom QWidget
objects for the tiles, which individually hold their state as mines, status and the adjacent count of mines. In this version, the mines are replaced with alien bugs (B'ug) but they could just as easily be anything else.
Installers for Windows, Linux and Mac are available to download above, along with the complete source code.
Running from source
Download the source archive, or check it out from Github here. Install requirements using:
You can then run Moonsweeper with:
Read on for a walkthrough of how the code works. The code is compatible with PyQt5 or PySide2 (Qt for Python), the only thing that changes is the imports and signal signature (see later).
- PyQt5
- PySide2
Playing Field
The playing area for Moonsweeper is a NxN grid, containing a set number of mines. The dimensions and mine counts we'll used are taken from the default values for the Windows version of Minesweeper. The values used are shown in the table below:
Level | Dimensions | Number of Mines |
---|---|---|
Easy | 8 x 8 | 10 |
Medium | 16 x 16 | 40 |
Hard | 24 x 24 | 99 |
We store these values as a constant LEVELS
defined at the top of the file. Sinceall the playing fields are square we only need to store the value once (8, 16 or 24).
The playing grid could be represented in a number of ways, including for example a 2D 'list of lists' representing the different states of the playing positions (mine, revealed, flagged).
However, this implementation uses an object-orientated approach. Individual squares on the map hold all relevant data about their current state and are also responsible for drawing themselves. In Qt we can do this simply by subclassing from QWidget
and then implementing a custom paint function.
Since our tile objects are subclassing from QWidget
we can lay them out like any other widget. We do this, by setting up a QGridLayout
.
We can set up the playing around by creating our position tile widgets and adding them our grid. The initial setup for the level reads from LEVELS
and assigns a number of variables to the window. The window title and mine counter are updated, and then the setup of the grid starts.
The setup functions will be covered next.
The Pos
class represents a tile, and holds all the relevant information for its relevant position in the map — including, for example, whether it is a mine, revealed, flagged and the number of mines in the immediate vicinity.
Each Pos
object also has 3 custom signals clicked, revealed and expandable which we connect to custom slosts. Finally, we call resize to adjust the size of the window to the new contents. This is actually only necessary when the window shrinks — Qt will grow it automatically.
- The
singleShot
timer is required to ensure the resize runs after we've returned to the event loop and Qt is aware of the new contents.
Now we have our grid of positional tile objects in place, we canbegin creating the initial conditions of the playing board. Thisis broken down into a number offunctions. We name them _reset
(the leading underscore is a convention to indicate a private function, not intended for external use). The main function reset_map
calls these functionsin turn to set it up.
The process is as follows —
- Remove all mines (and reset data) from the field.
- Add new mines to the field.
- Calculate the number of mines adjacent to each position.
- Add a starting marker (the rocket) and trigger initial exploration.
- Reset the timer.
The code to do this:
The separate steps from 1-5 are described in detail in turn below,with the code for each step.
The first step is to reset the data for each position on themap. We iterate through every position on the board, calling.reset()
on the widget at each point. The code for the .reset()
function is defined on our custom Pos
class, we'll explore indetail later. For now it's enough to know it clears mines, flagsand sets the position back to being unrevealed.
Now all the positions are blank, we can begin the process of addingmines to the map. The maximum number of mines n_mines
is definedby the level settings, described earlier.
With mines in position, we can now calculate the 'adjacency' numberfor each position — simply the number of mines in the immediate vicinity, using a 3x3 grid around the given point. The custom function get_surrounding
simply returns those positions around a given x
and y
location. We count the number of these that is a mine is_mine True
and store.
Pre-calculating the adjacent counts here helps simplify the reveal logic later. But it means we can't allow the user to choose their initial move — we can explain this away as the 'initial exploration around the rocket' and make it sound completely sensible.
Try and solve this yourself by postponing the calculation!
A starting marker is used to ensure that the first move is alwaysvalid. This is implemented as a brute force search throughthe grid space, effectively trying random positions until wefind a position which is not a mine. Since we don't know howmany attempts this will take, we need to wrap it in ancontinuous loop.
Once that location is found, we mark it as the start locationand then trigger the exploration of all surrounding positions.We break out of the loop, and reset the ready status.
Initial starting state for Moonsweeper
Position Tiles
The game is structure game so that individualtile positions hold their own state information. This means thatPos
tiles are able to handle their own game logic.
Since the Pos
class is relatively complex, it is broken down hereto a few parts, which are discussed in turn. The initialsetup __init__
block is simple, accepting an x
and y
positionand storing it on the object. Pos
positions never change once created.
To complete setup the .reset()
function is called which resets allobject attributes back to default, zero values. This flags the mine asnot the start position, not a mine, not revealed and not flagged.We also reset the adjacent count.
Microsoft Minesweeper Free Download
- PyQt5
- PySide2
Gameplay is centered around mouse interactions withthe tiles in the playfield, so detecting and reactingto mouse clicks is central. In Qt we catch mouseclicks by detecting the mouseReleaseEvent
. To do this forour custom Pos
widget we define a handler on the class.This receives QMouseEvent
with the information containingwhat happened. In this case we are only interested in whetherthe mouse release occurred from the left or the right mousebutton.
For a left mouse click we check whether the tile is flaggedor already revealed.If it is either, we ignore the click — making flagged tiles 'safe',unable to be click by accident. If the tile is not flaggedwe simply initiation the .click()
method (see later).
For a right mouse click, on tiles which are not revealed, wecall our .toggle_flag()
method to toggle a flag on and off.
The methods called by the mouseReleaseEvent
handlerare defined below.
The .toggle_flag
handler simply sets .is_flagged
tothe inverse of itself (True
becomes False
, False
becomesTrue
) having the effect of toggling it on and off. Notethat we have to call .update()
to force a redraw havingchanged the state. We also emit our custom .clicked
signal,which is used to start the timer — because placing a flag should alsocount as starting, not just revealing a square.
The .click()
method handles a left mouse click, and in turntriggers the reveal of the square. If the number of adjacentmines to this Pos
is zero, we trigger the .expandable
signalto begin the process of auto-expanding the region explored(see later).Finally, we again emit .clicked
to signal the start of the game.
Finally, the .reveal()
method checks whether the tile isalready revealed, and if not sets .is_revealed
to True
. Again wecall .update()
to trigger a repaint of the widget.
The optional emit of the .revealed
signal is used only for theendgame full-map reveal. Because each reveal triggers a furtherlookup to find what tiles are also revealable, revealing theentire map would create a large number of redundant callbacks.By suppressing the signal here we avoid that.
Finally, we define a custom paintEvent
method for our Pos
widget to handle the display of the current position state. As described in [chapter] to perform custom paint over a widget canvas we take a QPainter
and the event.rect()
which provides the boundaries in which we are to draw — in this case the outer border of the Pos
widget.
Revealed tiles are drawn differently depending on whether the tile is a start position, bomb or empty space. The first two are represented by icons of a rocket and bomb respectively. These are drawn into the tile QRect
using .drawPixmap
. Note we need to convert the QImage
constants to pixmaps, by passing through QPixmap
by passing.
You might think 'why not just store these as QPixmap
objects since that's what we're using? Unfortunately you can't create QPixmap
objects before your QApplication
is up and running.
For empty positions (not rockets, not bombs) we optionally show the adjacency number if it is larger than zero. To draw text onto our QPainter
we use .drawText()
passing in the QRect
, alignmentflags and the number to draw as a string. We've defined a standard color for each number (stored in NUM_COLORS
) for usability.
For tiles that are not revealed we draw a tile, by filling a rectangle with light gray and draw a 1 pixel border of darker grey. If .is_flagged
is set, we also draw a flag icon over the top of the tile using drawPixmap
and the tile QRect
.
Mechanics
We commonly need to get all tiles surrounding a given point, so we have a custom function for that purpose. It simple iterates across a 3x3 grid around the point, with a check to ensure we do not go out of bounds on the grid edges (0 ≥ x ≤ self.b_size
). The returned list contains a Pos
widget from each surrounding location.
The expand_reveal
method is triggered in response to a click on a tile with zero adjacent mines. In this case we want to expand the area around the click to any spaces which also have zero adjacent mines, and also reveal any squares around the border of that expanded area (which aren't mines).
We start with a list to_expand
containing the positions to check on the next iteration, a list to_reveal
containing the tile widgets to reveal, and a flag any_added
to determine when to exit the loop. The loop stops the first time no new widgets are added to to_reveal
.
Inside the loop we reset any_added
to False
, and empty the to_expand
list, keeping a temporary store in l
for iterating over.
For each x
and y
location we get the 8 surrounding widgets. If any of these widgets is not a mine, and is not already in the to_reveal
list we add it. This ensures that the edges of the expanded area are all revealed. If the position has no adjacent mines, we append the coordinates onto to_expand
to be checked on the next iteration.
By adding any non-mine tiles to to_reveal
, and only expandingtiles that are not already in to_reveal
, we ensure that we won'tvisit a tile more than once.
Endgames
Endgame states are detected during the reveal process following a click on a title. There are two possible outcomes —
- Tile is a mine, game over.
- Tile is not a mine, decrement the
self.end_game_n
.
This continues until self.end_game_n
reaches zero, which triggers the win game process by calling either game_over
or game_won
. Success/failure is triggered by revealing the map and setting the relevant status, in both cases.
Oh no. Eaten by a B'ug.
Further ideas
If you want to have a go at expanding Moonsweeper, here are a few ideas —
Minesweeper X Download
- Allow the player to take their own first turn. Try postponing the calculation of mine positions til after the user first clicks, and then generate positions until you get a miss.
- Add power-ups, e.g. a scanner to reveal a certain area of the board automatically.
- Let the hidden B'ugs move around between each turn. Keep a list of free-unrevealed positions, and allow the B'ugs to move into them. You'll need to recalculate the adjacencies after each click.
If you want a little more inspiration, see this PR from Keith Hall which modifies startup to be selectable, among other things!
Minesweeper For Mac
The full source is available for download below, along with installers for Windows, Mac and Linux.
For information on packaging and distributing PyQt5 applications see this section.
Comments are closed.