1、% *See GUI Options on GUIDEs Tools menu. Choose GUI allows only one% instance to run (singleton).% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help untitled% Last Modified by GUIDE v2.5 18-Jul-2018 23:26:39% Begin initialization code - DO NOT EDITgui_Singleton
2、 = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, .gui_OpeningFcn, untitled_OpeningFcn, .gui_OutputFcn, untitled_OutputFcn, .gui_LayoutFcn, , .gui_Callback, );if nargin & ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargout1:nargout = gui_
3、mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:% End initialization code - DO NOT EDIT% - Executes just before untitled is made visible.function untitled_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure%
4、 eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to untitled (see VARARGIN)% Choose default command line output for untitledhandles.output = hObject;% Update handles structureguidata(hObject
5、, handles);% UIWAIT makes untitled wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the command line.function varargout = untitled_OutputFcn(hObject, eventdata, handles)% varargout cell array for returning output args (see VARARGOUT);% Get
6、 default command line output from handles structurevarargout1 = handles.output;% - Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles) global A; A = 2 1 1 3; 2 1 1 3; 4 6 6 5; 4 7 7 5; 7 0 0 7;clahold on%在1的位置上写上曹操I J = find(A=1);x1 = min(J)-1;x2 = max(
7、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);ytext(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的位置上写上
8、赵云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);for i = 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+y
9、2),卒% 画背景line(0 4,0 0,colorblinewidth,4)line(0 4,5 5,line(0 0,0 5,line(4 4,0 5,4 line(0 4,i i,linestyle-3 line(i i,0 5,axis equalaxis(0 4 0 5)axis offfunction drawrect(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)% hObject handle to pushbutton1 (see GCBO)%
10、 - Executes on mouse press over axes background.function axes1_ButtonDownFcn(hObject, eventdata, handles)% hObject handle to axes1 (see GCBO)% - Executes during object creation, after setting all properties.function axes1_CreateFcn(hObject, eventdata, handles)% handles empty - handles not created un
11、til after all CreateFcns called% Hint: place code in OpeningFcn to populate axes1% - Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)step_number=0; global A while 1 str=num2str(step_number),步; set(handles.edit2,string,str);if A(5,2)=1&A(5,3)=1ch = me
12、nu(曹操成功逃出华容道!如果要继续玩,按“是”,否则按“否”是否); switch ch case 1 untitled case 2 return end xpos,ypos = ginput(1); col = ceil(xpos); row = 5-ceil(ypos)+1; juese = A(row,col); switch juese case 1%点击了曹操 I,J = find(A=1); rm = max(I); rn = min(I); lm = max(J); ln = min(J); %判断是否能向左移 if ln1&A(rn,rm,ln-1)=0;0 A(rn,rm
13、,ln-1)=1;1; A(rn,rm,lm)=0;0; drawmap(A) step_number=step_number+1; %判断是否能向右移 if lm(A(rn-1,ln,lm)=0,0) A(rn-1,ln,lm)=1,1; A(rn+1,ln,lm)=0,0; %判断是否能向上移 if rm5&A(rm+1,ln,lm)=0,0 A(rm+1,ln,lm)=1,1; A(rm-1,ln,lm)=0,0;case 2% 点击了黄忠 I,J = find(A=2); A(rn,rm,ln-1)=2;2; A(rn,rm,lm+1)=2;A(rn-1,ln)=0A(rm+1,ln)
14、=0%如果又能上移又能下移,则要点击的部位 ch = menu(请选择移到的方向:上下 case 1%上移 A(rn-1,ln) = 2; A(rn+1,ln) = 0; case 2%下移 A(rm+1,ln) = 2; A(rm-1,ln) = 0; else%只能上移 elseif rmA(rm+1,ln)=0 case 3%张飞 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; case 4%马超 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
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1