-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadfile.m
39 lines (37 loc) · 1.44 KB
/
loadfile.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
function [Board,sg]=loadfile()
% This function is to load a valid saved game of Pentago to continue
% playing.
% Format of Call: loadfile()
% Returns Board and sg data structure
% MH1401 ALGORITHMS & COMPUTING I Project
% This command opens the open file dialog box.
filename = uigetfile;
% From here, filename is the variable with the string value of the name of
% the file in mat extension.
try
load(filename) % Load data structure sg from valid file
catch
o=questdlg('No Saved Game Selected!!','Error','Return to Main Menu','Exit','Exit'); % If invalid file detected, it prompts for dialog box
switch o
case 'Return to Main Menu'
Pentago % This recursives the function back to the main Pentago script.
return
case 'Exit' % Ends function
return
end
end
try
Board=sg.a; % Board matrix is the first array of the data structure.
catch
z=questdlg('Invalid File Detected!! File must contain structure sg.','Error','Load another file','Return to Main Menu','Exit','Exit');
switch z % This prompts another dialog box to load another file or return to main menu or exit.
case 'Load another file'
[Board,sg]=loadfile(); % This recursives this load file function again.
case 'Return to Main Menu'
Pentago % This recursives back to the Pentago main script.
return
case 'Exit' % This ends the function
return
end
end
end