Matlab 版 (精华区)
文件名是snake_set.m
以下是文件内容
clc
close all
w=0;
St=1;
K=6;
S=6;
tp=0.2;
figure('venuBar','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;
uicontrol(gcf,'style','push',...
'unit','normalized','position',[0.79,0.5,0.07,0.07],...
'BackgroundColor','g','ForegroundColor','r',...
'string','Up','callback','D=i;');
uicontrol(gcf,'style','push',...
'unit','normalized','position',[0.71,0.40,0.07,0.07],...
'BackgroundColor','g','ForegroundColor','r',...
'string','Left','callback','D=-1;');
uicontrol(gcf,'style','push',...
'unit','normalized','position',[0.79,0.4,0.07,0.07],...
'BackgroundColor','g','ForegroundColor','r',...
'string','Down','callback','D=-i;');
uicontrol(gcf,'style','push',...
'unit','normalized','position',[0.87,0.40,0.07,0.07],...
'BackgroundColor','g','ForegroundColor','r',...
'string','Right','callback','D=1;');
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);
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:7.131毫秒