1). 选择图形用户界面
2). 选择第一个选项
3).设计如此页面
4). 将文件保存文.fig格式,会自动生成相应的函数文件
axes(handles.axes1);
img=imread('sjj/background.jpg');
image(img);
set(handles.pushbutton1,'String','start game');
set(handles.text1,'String','guess the idiom');
close('old'); %关掉原有的页面
run('game'); %打开一个新的页面
1). 初始页面(第一题)
ensure按钮,提交本题答案,答对加一分,答错不得分,然后自动切换下一题。
next按钮,跳过本题,但不可再回头重做此题。
score按钮,计算分数,无论题目是否全部做完,直接结算分数,然后退出。
2). 回答正确,弹出提示框,分数加一
3). 回答错误,弹出提示框,切换下一题
4). 结束时,结算分数
主程序调用开始页面的函数文件,而开始页面控制游戏开始的页面。
主页面即run(‘old’); 一句。
run('old');
function varargout = old(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @old_OpeningFcn, ...
'gui_OutputFcn', @old_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{
1})
gui_State.gui_Callback = str2func(varargin{
1});
end
if nargout
[varargout{
1:nargout}] = gui_mainfcn(gui_State, varargin{
:});
else
gui_mainfcn(gui_State, varargin{
:});
end
function old_OpeningFcn(hObject, eventdata, handles, varargin)
axes(handles.axes1);
img=imread('sjj/background.jpg');
image(img);
set(handles.pushbutton1,'String','start game');
set(handles.text1,'String','guess the idiom');
handles.output = hObject;
guidata(hObject, handles);
function varargout = old_OutputFcn(hObject, eventdata, handles)
varargout{
1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
close('old');
run('game');
function varargout = game(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @game_OpeningFcn, ...
'gui_OutputFcn', @game_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{
1})
gui_State.gui_Callback = str2func(varargin{
1});
end
if nargout
[varargout{
1:nargout}] = gui_mainfcn(gui_State, varargin{
:});
else
gui_mainfcn(gui_State, varargin{
:});
end
function game_OpeningFcn(hObject, eventdata, handles, varargin)
global count;
count=0;
global i;
i=0;
axes(handles.axes1);
pic=imread(['sjj/',int2str(i),'.jpg']);
image(pic);
global elem;
elem=['0','drmj','1','rymf','2','zstb','3','pfqs','4','sbml','5','kkpx','6','hlyh'];
handles.output = hObject;
guidata(hObject, handles);
function varargout = game_OutputFcn(hObject, eventdata, handles)
varargout{
1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function pushbutton2_Callback(hObject, eventdata, handles)
global count;
helpdlg(['report:',int2str(count)]);
pause(1.5);
close('game');
function pushbutton1_Callback(hObject, eventdata, handles)
global i;
global count;
global elem;
index=[];
for a=1:35
if elem(a)==int2str(i)
for j=a+1:a+4
index=[index,elem(j)];
end
end
end
answer=get(handles.edit1,'String');
if answer==index
helpdlg('CORRECT!!!');
pause(1);
count=count+1;
if i<6&&i>=0
i=i+1;
axes(handles.axes1);
pic=imread(['sjj/',int2str(i),'.jpg']);
image(pic);
set(handles.edit1,'String','');
end
if i==6
helpdlg('the last');
if(get(handles.edit1,'String')~='')
helpdlg(['report:',int2str(count)]);
pause(1.5);
close('game');
end
end
end
if answer~=index
error=errordlg('WRONG!!!');
pause(1);
close(error);
i=i+1;
axes(handles.axes1);
pic=imread(['sjj/',int2str(i),'.jpg']);
image(pic);
set(handles.edit1,'String','');
end
function pushbutton3_Callback(hObject, eventdata, handles)
global i;
if i<6
i=i+1;
axes(handles.axes1);
pic=imread(['sjj/',int2str(i),'.jpg']);
image(pic);
set(handles.edit1,'String','');
end
if i==6
helpdlg('the last');
end