华容道小游戏Word文档格式.docx
- 文档编号:21989463
- 上传时间:2023-02-02
- 格式:DOCX
- 页数:22
- 大小:68.47KB
华容道小游戏Word文档格式.docx
《华容道小游戏Word文档格式.docx》由会员分享,可在线阅读,更多相关《华容道小游戏Word文档格式.docx(22页珍藏版)》请在冰豆网上搜索。
%*SeeGUIOptionsonGUIDE'
sToolsmenu.Choose"
GUIallowsonlyone
%instancetorun(singleton)"
.
%Seealso:
GUIDE,GUIDATA,GUIHANDLES
%Edittheabovetexttomodifytheresponsetohelpuntitled
%LastModifiedbyGUIDEv2.518-Jul-201823:
26:
39
%Begininitializationcode-DONOTEDIT
gui_Singleton=1;
gui_State=struct('
gui_Name'
mfilename,...
'
gui_Singleton'
gui_Singleton,...
gui_OpeningFcn'
@untitled_OpeningFcn,...
gui_OutputFcn'
@untitled_OutputFcn,...
gui_LayoutFcn'
[],...
gui_Callback'
[]);
ifnargin&
&
ischar(varargin{1})
gui_State.gui_Callback=str2func(varargin{1});
end
ifnargout
[varargout{1:
nargout}]=gui_mainfcn(gui_State,varargin{:
});
else
gui_mainfcn(gui_State,varargin{:
%Endinitializationcode-DONOTEDIT
%---Executesjustbeforeuntitledismadevisible.
functionuntitled_OpeningFcn(hObject,eventdata,handles,varargin)
%Thisfunctionhasnooutputargs,seeOutputFcn.
%hObjecthandletofigure
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%varargincommandlineargumentstountitled(seeVARARGIN)
%Choosedefaultcommandlineoutputforuntitled
handles.output=hObject;
%Updatehandlesstructure
guidata(hObject,handles);
%UIWAITmakesuntitledwaitforuserresponse(seeUIRESUME)
%uiwait(handles.figure1);
%---Outputsfromthisfunctionarereturnedtothecommandline.
functionvarargout=untitled_OutputFcn(hObject,eventdata,handles)
%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);
%Getdefaultcommandlineoutputfromhandlesstructure
varargout{1}=handles.output;
%---Executesonbuttonpressinpushbutton1.
functionpushbutton1_Callback(hObject,eventdata,handles)
globalA;
A=[2113;
2113;
4665;
4775;
7007];
cla
holdon
%在1的位置上写上曹操
[IJ]=find(A==1);
x1=min(J)-1;
x2=max(J);
y1=5-(min(I)-1);
y2=5-max(I);
drawrect([x1,y1],[x2,y1],[x2,y2],[x1,y2],'
r'
)
text(0.5*(x1+x2)-0.5,0.5*(y1+y2),'
曹操'
fontsize'
28)
%在2的位置上写上黄忠
[I,J]=find(A==2);
y'
text(0.5*(x1+x2)-0.26,0.5*(0.5*(y1+y2)+y1),'
黄'
text(0.5*(x1+x2)-0.26,0.5*(0.5*(y1+y2)+y2),'
忠'
%在3的位置上写上张飞
[I,J]=find(A==3);
张'
飞'
%在4的位置上写上马超
[I,J]=find(A==4);
马'
超'
%在5的位置上写上赵云
[I,J]=find(A==5);
赵'
云'
%在6的位置上写上关羽
[I,J]=find(A==6);
text(0.5*(x1+0.5*(x1+x2))-0.26,0.5*(y1+y2),'
关'
text(0.5*(0.5*(x1+x2)+x2)-0.26,0.5*(y1+y2),'
羽'
%在7的位置上写上小卒
[I,J]=find(A==7);
fori=1:
length(I)
x1=J(i)-1;
x2=J(i);
y1=5-(I(i)-1);
y2=5-I(i);
drawrect([x1,y1],[x2,y1],[x2,y2],[x1,y2],'
g'
text(0.5*(x1+x2)-0.26,0.5*(y1+y2),'
卒'
%画背景
line([04],[00],'
color'
b'
linewidth'
4)
line([04],[55],'
line([00],[05],'
line([44],[05],'
4
line([04],[ii],'
linestyle'
--'
3
line([ii],[05],'
axisequal
axis([0405])
axisoff
functiondrawrect(x1,x2,x3,x4,color)
x=[x1
(1)x2
(1)x3
(1)x4
(1)];
y=[x1
(2)x2
(2)x3
(2)x4
(2)];
fill(x,y,color)
%hObjecthandletopushbutton1(seeGCBO)
%---Executesonmousepressoveraxesbackground.
functionaxes1_ButtonDownFcn(hObject,eventdata,handles)
%hObjecthandletoaxes1(seeGCBO)
%---Executesduringobjectcreation,aftersettingallproperties.
functionaxes1_CreateFcn(hObject,eventdata,handles)
%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled
%Hint:
placecodeinOpeningFcntopopulateaxes1
%---Executesonbuttonpressinpushbutton2.
functionpushbutton2_Callback(hObject,eventdata,handles)
step_number=0;
globalA
while1
str=[num2str(step_number),'
步'
];
set(handles.edit2,'
string'
str);
ifA(5,2)==1&
A(5,3)==1
ch=menu('
曹操成功逃出华容道!
如果要继续玩,按“是”,否则按“否”'
是'
否'
);
switchch
case1
untitled
case2
return
end
[xpos,ypos]=ginput
(1);
col=ceil(xpos);
row=5-ceil(ypos)+1;
juese=A(row,col);
switchjuese
case1%点击了曹操
[I,J]=find(A==1);
rm=max(I);
rn=min(I);
lm=max(J);
ln=min(J);
%判断是否能向左移
ifln>
1&
A([rn,rm],ln-1)==[0;
0]
A([rn,rm],ln-1)=[1;
1];
A([rn,rm],lm)=[0;
0];
drawmap(A)
step_number=step_number+1;
%判断是否能向右移
iflm<
4&
A([rn,rm],lm+1)==[0;
A([rn,rm],lm+1)=[1;
A([rn,rm],ln)=[0;
%判断是否能向下移
ifrn>
(A(rn-1,[ln,lm])==[0,0])
A(rn-1,[ln,lm])=[1,1];
A(rn+1,[ln,lm])=[0,0];
%判断是否能向上移
ifrm<
5&
A(rm+1,[ln,lm])==[0,0]
A(rm+1,[ln,lm])=[1,1];
A(rm-1,[ln,lm])=[0,0];
case2%点击了黄忠
[I,J]=find(A==2);
A([rn,rm],ln-1)=[2;
2];
A([rn,rm],lm+1)=[2;
A(rn-1,ln)==0
A(rm+1,ln)==0%如果又能上移又能下移,则要点击的部位
ch=menu('
请选择移到的方向:
'
上'
下'
case1%上移
A(rn-1,ln)=2;
A(rn+1,ln)=0;
case2%下移
A(rm+1,ln)=2;
A(rm-1,ln)=0;
else%只能上移
elseifrm<
A(rm+1,ln)==0
case3%张飞
[I,J]=find(A==3);
(A([rn,rm],ln-1)==[0;
0])
A([rn,rm],ln-1)=[3;
3];
A([rn,rm],lm+1)=[3;
A(rn-1,ln)=3;
A(rm+1,ln)=3;
case4%马超
[I,J]=find(A==4);
A([rn,rm],ln-1)=[4;
4];
A([rn,rm],lm+1)=[4;
A(rm+1,ln)==0%如果又能上移又能下移,则要点击的部位
A(rn-1,ln)=4;
A(rm+1,ln)=4;
step_number=step_number+1
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 华容道 小游戏
![提示](https://static.bdocx.com/images/bang_tan.gif)