📄 game.txt
字号:
% 用matlab写的推箱子游戏:第0关
close all;clc;clear;
figure('NumberTitle','off','Name','欢迎光临推箱子游戏:第0关');
uicontrol(gcf,'style','text',...
'unit','normalized','position',[0.09,0.06,0.82,0.14],...
'BackgroundColor',0.7*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...
'fontsize',12,'fontname','times new roman','string',...
{'规则很简单,只需把所有的''b''都推到''p''上面去(会变成绿色)',...
'就过关了。但是玩起来难度可是相当大的,不要轻视喔。 ',...
'h是代表推箱子的手,请使用方向键来控制手h的移动。 '});
Gx=uicontrol(gcf,'style','text',...
'unit','normalized','position',[0.3,0.85,0.3,0.1],...
'BackgroundColor',0.8*[1,1,1],'ForegroundColor',[0.8,0.1,0.1],...
'fontsize',12,'fontname','times new roman');
for m=1:8;
for n=1:8;
h(m,n)=uicontrol(gcf,'style','text',...
'unit','normalized','position',[0.2+0.06*n,0.9-0.08*m,0.05,0.07],...
'BackgroundColor',0.7*[1,1,1],'fontsize',16,...
'fontname','times new roman');
end
end
set([h(2,3),h(2,7),h(3,7)],'BackgroundColor','w',...
'string','p','fontsize',16,'fontname','times new roman');
set([h(3:7,3)',h(5:7,4)',h(3,5:6)],'BackgroundColor','w');
set([h(4,6:7),h(5:6,7)',h(6,6)],'BackgroundColor','w');
set([h(4,4:5),h(5,5)],'BackgroundColor','w','style','push',...
'string','b','fontsize',16,'fontname','times new roman');
set(h(5,6),'BackgroundColor','w','style','push',...
'string','h','fontsize',16,'fontname','times new roman');
S=zeros(8);
S(2,3)=1;S(2:3,7)=1;
S(3:7,3)=1;S(5:7,4)=1;S(3,5:6)=1;
S(4,6:7)=1;S(5:6,7)=1;S(6,6)=1;
S(4,4:5)=2;S(5,5)=2;S(5,6)=1;
mt=5;nt=6;Pz=[2+3i,2+7i,3+7i];
Fen=[0,0,0];
set(gcf,'KeyPressFcn',['K=get(gcf,''CurrentKey'');',...
'if K(1)==117;dm=-1;dn= 0;end;',...
'if K(1)==100;dm= 1;dn= 0;end;',...
'if K(1)==108;dm= 0;dn=-1;end;',...
'if K(1)==114;dm= 0;dn= 1;end;',...
'mtn=mt+dm;ntn=nt+dn;',...
'if S(mtn,ntn)==1;',...
'set(h(mt,nt),''style'',''text'',''string'','''');',...
'if min(abs(mt+nt*i-Pz))<0.5;',...
'set(h(mt,nt),''String'',''p'');end;',...
'set(h(mtn,ntn),''style'',''push'',''string'',''h'');',...
'mt=mtn;nt=ntn;end;',...
'if S(mtn,ntn)==2&S(mtn+dm,ntn+dn)==1;',...
'set(h(mt,nt),''style'',''text'',''string'','''');',...
'set(h(mtn,ntn),''style'',''push'',''string'',''h'');',...
'set(h(mtn+dm,ntn+dn),''style'',''push'',''string'',''b'');',...
'S(mtn+dm,ntn+dn)=2;S(mtn,ntn)=1;mt=mtn;nt=ntn;end;',...
'if S(2,3)==2;Fen(1)=1;set(h(2,3),''BackgroundColor'',''g'');',...
'else Fen(1)=0;set(h(2,3),''BackgroundColor'',''w'');end;',...
'if S(2,7)==2;Fen(2)=1;set(h(2,7),''BackgroundColor'',''g'');',...
'else Fen(2)=0;set(h(2,7),''BackgroundColor'',''w'');end;',...
'if S(3,7)==2;Fen(3)=1;set(h(3,7),''BackgroundColor'',''g'');',...
'else Fen(3)=0;set(h(3,7),''BackgroundColor'',''w'');end;',...
'if sum(Fen)==3;set(Gx,''string'',''恭喜你通过第0关'');end;']);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -