-
Notifications
You must be signed in to change notification settings - Fork 0
/
MineSweeper_GUI.m
67 lines (62 loc) · 2.39 KB
/
MineSweeper_GUI.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function MineSweeper_GUI()
% GUI base
%
% width of figure
global fig_width;
% height of figure
global fig_height;
% The figure template
global fig;
global Smiley;
% build figure with background
fig = figure('Position' , [200,200,fig_width,fig_height],...
'Resize','off',...
'MenuBar','none',...
'Name','MineSweeper',...
'NumberTitle','off');
axis tight;
ha = axes('units','normalized', ...
'position',[0 0 1 1]);
frame_img = imresize(imread('images/frame.png'),[fig_width,fig_height]);
uistack(image(frame_img),'bottom');
% Create menus and their callbacks
% Game menu
gamem = uimenu(fig,'Label','Game');
% level menus
beginner_cb = @(s,e)SetBoard('BEGINNER');
uimenu(gamem,'Label','Beginner', ...
'Callback',beginner_cb, ...
'Accelerator','1');
intermediate_cb = @(s,e)SetBoard('INTERMEDIATE');
uimenu(gamem,'Label','Intermediate', ...
'Callback',intermediate_cb, ...
'Accelerator','2');
expert_cb = @(s,e)SetBoard('EXPERT');
uimenu(gamem,'Label','Expert', ...
'Callback',expert_cb, ...
'Accelerator','3');
% reset board button and define it's callback
uimenu(gamem,'Label','Reset Board', ...
'Callback',@(s,e)ResetBoard(), ...
'Separator','on', ...
'Accelerator','R');
% close button and define it's callback
uimenu(gamem,'Label','Close', ...
'Callback',@(s,e)CloseGUI(), ...
'Separator','on', ...
'Accelerator','W');
%hint button and define it's callback
hintm = uimenu(fig,'Label','Hint');
uimenu(hintm,'Label','Hint...', ...
'Callback',@(s,e)hint_cb(), ...
'Accelerator','H');
%show happy smiley at first
Smiley_im_orig = imread('images/Happy.png');
im_sized = imresize(Smiley_im_orig, [ fig_height*0.1 , fig_width*0.1]);
Smiley = uicontrol('style','push',...
'units','normalized',...
'position',[0.45,0.86, 0.1, 0.1],...
'fontsize',14,...
'callback',@(s,e)ResetBoard());
set(Smiley,'CData',im_sized);
end