⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 engine.m

📁 这是用Matlab编写的贪食蛇游戏
💻 M
字号:
%=====This script is used with "snake.m" as a part of the program
%=====By Valery Garmider=========================================
%=====Updated 27/03/03===========================================
		%===Evaluates next values of snake's head coordinates==
		ih=ih+xdrn;
		jh=jh+ydrn;
		%===The snake catches a prey==============
		if [ih==ir jh==jr]
			%===Evaluates next prey coordinates==
			SNK=sparse(i,j,1,m,m);
			[nsi,nsj]=find(~SNK);
			pr=floor((m^2-k)*rand)+1;
			ir=nsi(pr);
			jr=nsj(pr);
			set(Prey,'xdata',ir,'ydata',jr,'Color','y');
			%===Updates comment window===========
         if timer>9
            set(uic(4),'String',' Catched it! Go! ');
         else
            set(uic(4),'String','At last! Come on! Move your ass!');
         end;
			%===Updates play variables=========	
			score=score+floor(timer/10);
			level=level+1;
			timer=109;
         incrmnt=incrmnt-6;
         %===Define colors=======================
         SnakColor=[(cos(level*pi/100))^2  (sin(level*pi/130))^2  (cos(level*pi/60))^2];   
         HeadColor=1-SnakColor;   
         %===Updates score and level indicators==
			set(ScoreHndl,'String',int2str(score));
         set(LevelHndl,'String',int2str(level));
		end;
		%===Updates snake image=====================
		if incrmnt<6
			incrmnt=incrmnt+1;
			k=k+1;
			i=[ih i];
			j=[jh j];
		else
			i=[ih i(1:k-1)];
			j=[jh j(1:k-1)];
			set(PlotHndl,'xdata',itl,'ydata',jtl,'color',[0.4 0.8 0.4]);
      end;
		set(HeadHndl,'xdata',ih,'ydata',jh,'color',HeadColor);
		set(HeadHndl,'xdata',i(3),'ydata',j(3),'color',SnakColor);
      set(PlotHndl,'xdata',i(3),'ydata',j(3),'color',SnakColor);
      PreyColor=[0.5+timer/218 timer/109 0];
      set(Prey,'Color',PreyColor);
		%==="A stupid snake catches his own tail" indicator=====
      CMP=(i==ih)&(j==jh);
      %===Pause the game======================================
      PausGm=strcmp(get(ValNumber,'SelectionType'),'alt');
		%===Decreasing the score timer===============
		if timer>9
			timer=timer-1;
		end;
		drawnow;
		%===Some comments============================
		%if xPt<0|xPt>m+1|yPt<0|yPt>m+1 
		%	 InsdprStr= ...
		%        [' Press inside the play area!                       ']; 
		%	set(uic(4),'String',InsdprStr);
		if [timer<50 timer>9]
			set(uic(4),'String',' Hurry!');
		elseif timer==9
			LateStr= ...
			[' Too late!                                         '
			 ' Next time move your ass quicker!                  '];
			set(uic(4),'String',LateStr);
		end;  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -