📄 snake_set.m
字号:
clc
close all
w=0;
St=1;
K=6;
S=6;
Tp=0.2;
app='rightarrow';
figure('MenuBar','none');
Hq=uimenu(gcf,'label','help');
uimenu(Hq,'label','about this game...','callback','')
uimenu(Hq,'label','Help for playing','callback','!help.txt;');
Kh=uimenu(gcf,'label','choose a difficulty');
uimenu(Kh,'label','easy','callback','Tp=0.2;chooseTp;');
uimenu(Kh,'label','normal','callback','Tp=0.15;chooseTp;');
uimenu(Kh,'label','hard','callback','Tp=0.1;chooseTp;');
set(gcf,'color','w')
Ht=uicontrol(gcf,'style','text',...
'unit','normalized','position',[0.03,0.92,0.12,0.05],...
'BackgroundColor',[0.7 0.8 0.9],'ForegroundColor','b',...
'string','easy','fontsize',14);
hold on
N=40;
for k=0:N;
h=line([0,N],[k,k]);
set(h,'color',[0.1 0.2 0.3])
h=line([k,k],[0,N-1]);
set(h,'color',[0.1 0.2 0.3])
end
axis square
set(gca,'Position',[-0.07 0.11 0.775 0.815])
set(gcf,'Position',[34 177 921 501])
axis off
x=2*N/8:3*N/8;
y=N/2*ones(1,length(x));
filll(x,y,'g');
xc=N*3/10;
yc=N*6/10;
Z=xc+yc*i;
filll(xc,yc,'r');
T=[x;y];
T=fliplr(T);
% D=1;
set(gcf,'KeyPressFcn','app=get(gcf,''CurrentKey'');direction;')
uicontrol(gcf,'style','text',...
'unit','normalized','position',[0.71,0.40,0.3,0.07],...
'BackgroundColor','w','ForegroundColor','b',...
'string','移动上下左右键来控制方向',...
'fontsize',14);
uicontrol(gcf,'style','push',...
'unit','normalized','position',[0.61,0.60,0.07,0.07],...
'BackgroundColor','r','ForegroundColor','black',...
'string','cancel','callback',...
'St=0;set(gcf,''Visible'',''off'')','fontsize',14);
uicontrol(gcf,'style','push',...
'unit','normalized','position',[0.61,0.50,0.07,0.07],...
'BackgroundColor','g','ForegroundColor','black',...
'string','Stop','callback','St=0;','fontsize',14);
uicontrol(gcf,'style','push',...
'unit','normalized','position',[0.61,0.40,0.07,0.07],...
'BackgroundColor','g','ForegroundColor','black',...
'string','Start','callback','St=1;snake_run;','fontsize',14);
aaa=uicontrol(gcf,'style','push',...
'unit','normalized','position',[0.61,0.30,0.10,0.07],...
'BackgroundColor','g','ForegroundColor','black',...
'string','over again','callback','snake','fontsize',14);
uicontrol(gcf,'style','edit',...
'unit','normalized','position',[0.62,0.87,0.17,0.06],...
'BackgroundColor',[0.7 0.7 0.7],'ForegroundColor','black',...
'string','state of the snake','fontsize',14);
hf=uicontrol(gcf,'style','edit',...
'unit','normalized','position',[0.62,0.80,0.17,0.06],...
'BackgroundColor',[0.7 0.7 0.7],'ForegroundColor','black',...
'string','Walking','fontsize',14);
uicontrol(gcf,'style','edit',...
'unit','normalized','position',[0.80,0.87,0.17,0.06],...
'BackgroundColor',[0.7 0.7 0.7],'ForegroundColor','black',...
'string','length of the snake','fontsize',14);
hd=uicontrol(gcf,'style','edit',...
'unit','normalized','position',[0.80,0.80,0.17,0.06],...
'BackgroundColor',[0.7 0.7 0.7],'ForegroundColor','black',...
'string',num2str(K),'fontsize',14);
tx=uicontrol(gcf,'style','text',...
'unit','normalized','position',[0.61,0.70,0.26,0.07],...
'BackgroundColor','w','ForegroundColor','r',...
'string','','fontsize',14);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -