Section ๐ฅ Minesweeper
Subsection Simon Game
The simon game we coded in class shares many features to your minesweeper game. Download the full code base for this game on Canvas.
This should be a very helpful resource for wiring up your callback functions and updating your gui components.
Subsection Difficulty Effects
| \(\textbf{Difficulty Level}\) | \(\textbf{Grid Size}\) | \(\textbf{Percent Mines}\) | \(\textbf{Time Limit (secs)}\) |
| โtestโ | \(5 \times 5\) | \(10\%\) | \(30\) |
| โeasyโ | \(10 \times 10\) | \(10\%\) | \(\infty\) |
| โnormalโ | \(15 \times 15\) | \(13\%\) | \(150\) |
| โhardโ | \(20 \times 20\) | \(16\%\) | \(100\) |
| โbrutalโ | \(20 \times 20\) | \(19\%\) | \(80\) |
Subsection MATLAB Text Object
MATLABโs has a built-in
timer class to create a countdown clock. You can read about it in the official documentation: MATLAB Timer Documentation.
The timer,
x, can be configured with various properties. This table lists a few:
text Properties| \(\textbf{Name}\) | \(\textbf{Options}\) | \(\textbf{Description}\) |
String |
Any string | Display string |
FontSize |
Any integer | Font size |
HorizontalAlignment |
"left", "center", "right" |
Position anchor |
FontWeight |
"bold", "normal" |
Font thickness |
ButtonDownFcn |
function handle | Call if clicked |
Subsection Saving and Retrieving Game Data
Saving and Retrieving the updated game components is a critical part of event driven programs.
Whenever the game data changes in anyway, we must save the updated version inside the figure.
- Saving data to a figure is done with the command:
guidata(fig, game); % saves updated game data to the figure - Retrieving/loading data from a figure is done with the command:
g = guidata(fig); % loads data from the figure
Subsection MATLAB Clock Timer
MATLABโs has a built-in
timer class to create a countdown clock. You can read about it in the official documentation: MATLAB Timer Documentation.
The timer,
x, can be configured with various properties. This table lists a few:
timer Properties| Name | Options | Description |
ExecutionMode |
"fixedRate" |
|
TimerFcn |
@(src,evt) func_handle |
|
Period |
\((1\times 1)\) double | \(\sfrac{1}{\text{Period}}\) = checks\(/\)second |
StopFcn |
@(src,evt) func_handle |
timer Functions| Name | Example | Description |
start |
start(x) |
Starts the timer, x
|
stop |
stop(x) |
Stops the timer, x
|
Subsection Minesweeper Main Function
Rather than starting with something that doesnโt work, you may optionally start with something that works and slowly replace the provided helpers with your own.
- Step 1
- Download the Helper Keys.
- Step 2
- Create an isolated folder and extract ALL the helper keys inside this folder.
- Step 3
- Inside the same folder, create a new function called
minesweeper.mwith the following code:% FINAL PROJECT ========================================= % ๐ = BONUS Feature % == MAIN =============================================== function minesweeper(difficulty, seed) % Clean up clear game; close all; % Default difficulty if nargin < 1, difficulty = "test"; elseif nargin == 2, rng(seed,"twister"); end game.settings = init_settings(difficulty); game.state = init_state(game.settings.gridSize); [game.gui, fig] = init_gui(game.settings); game.clock = init_clock(fig); % <-- ๐ --> guidata(fig, game); end - Step 4
- Run the function as normal to play the game.
- Step 5
- As you write the different helpers for this assignment, replace the helper keys with your helper code.
