首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

基于MATLAB的贪吃蛇(完美运行)

大数据 60.69KB 27 需要积分: 1
立即下载

资源介绍:

贪吃蛇(Snake)是一款经典的电子游戏,最早由苹果公司开发并发布于1976年。游戏中,玩家操控一条蛇在一个有边界的区域内移动并吃食物,每吃到一块食物,蛇的长度就会增加。同时,蛇不能碰到自己的身体或碰到边界,否则游戏结束。游戏的目标是尽可能地吃更多的食物,同时保持蛇的活动空间。随着时间的推移,蛇的移动速度会逐渐加快,难度也会逐渐增加。贪吃蛇是一款简单而有趣的游戏,经常被用于娱乐和休闲。
function varargout = Snake(varargin) % SNAKE M-file for Snake.fig % SNAKE, by itself, creates a new SNAKE or raises the existing % singleton*. % % H = SNAKE returns the handle to a new SNAKE or the handle to % the existing singleton*. % % SNAKE('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in SNAKE.M with the given input arguments. % % SNAKE('Property','Value',...) creates a new SNAKE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Snake_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Snake_OpeningFcn via varargin. % % *See GUI Options on GUIDE's 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 Snake % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Snake_OpeningFcn, ... 'gui_OutputFcn', @Snake_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end mainfc; if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before Snake is made visible. function Snake_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % 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 Snake (see VARARGIN) % Choose default command line output for Snake %% ha=axes('units','normalized','position',[0 0 1 1]); uistack(ha,'down') II=imread('background.jpg'); image(II) colormap gray set(ha,'handlevisibility','off','visible','off'); %% mainfc; line( 'Visible', 'on','Tag', 'MoveBlock', 'Markersize', 18, 'HitTest', 'off','Parent',handles.axes1,... 'Marker', 's', 'MarkerEdgeColor', 'k', 'XData',nan, 'YData',nan , 'LineStyle', 'none','MarkerFaceColor',[0 0 1] ) ; line( 'Visible', 'on','Tag', 'HeadBlock', 'Markersize', 18, 'HitTest', 'off','Parent',handles.axes1,... 'Marker', 's', 'MarkerEdgeColor', 'k', 'XData',nan, 'YData',nan , 'LineStyle', 'none','MarkerFaceColor',[0 0 1] ) ; % Update handles structure handles = guihandles(hObject); handles.output = hObject; setappdata(handles.figure1,'gamelevel',1); setappdata(handles.figure1,'direction','rightarrow'); setappdata(handles.figure1,'flag',1); setappdata(handles.figure1,'headreq',1); guidata(hObject, handles); pos = get(handles.axes1,'position'); pos = [0 0 pos(3) pos(4)]; rectangle('Position',pos,'EdgeColor','r', 'LineWidth',2 ) % UIWAIT makes Snake wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = Snake_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % -------------------------------------------------------------------- function Start_Callback(hObject, eventdata, handles) % hObject handle to Start (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) TextHandle = findobj( 'Parent', handles.axes1, 'Type', 'text' ) ; delete( TextHandle ) ; setappdata(handles.figure1,'flag',0); setappdata(handles.figure1,'direction','rightarrow'); setappdata(handles.figure1,'gamelevel',1); set(handles.MoveBlock,'XData',[170 190 210],'YData',[210 210 210]); set(handles.score,'string','0'); while ishandle(hObject) if getappdata(handles.figure1,'flag'); text( 100, 240, 'GameOver', 'Parent', handles.axes1,... 'FontSize', 30, 'Color', 'r', 'FontAngle', 'italic' ) ; text( 100, 200, strcat('得分:',get(handles.score,'string')), 'Parent', handles.axes1,... 'FontSize', 30, 'Color', 'r', 'FontAngle', 'italic' ) ; break; end if getappdata(handles.figure1,'headreq'); [Xpos,Ypos] = randblock(handles); set(handles.HeadBlock,'XData',Xpos,'YData',Ypos); setappdata(handles.figure1,'headreq',0); end while ( ishandle(hObject) & ~getappdata(handles.figure1,'flag') & ~getappdata(handles.figure1,'headreq') ) snake_move(handles); level = getappdata(handles.figure1,'gamelevel'); pausetime = 1 - 0.099 * level; pause(pausetime); end end % -------------------------------------------------------------------- function File_Callback(hObject, eventdata, handles) % hObject handle to File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on key press over figure1 with no controls selected. function figure1_KeyPressFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) CurrentKey = get( handles.figure1, 'CurrentKey' ) ; olddire = getappdata(handles.figure1,'direction'); switch olddire case 'leftarrow' if( strcmp(CurrentKey,'rightarrow')) return; end case 'rightarrow' if( strcmp(CurrentKey,'leftarrow')) return; end case 'uparrow' if( strcmp(CurrentKey,'downarrow')) return; end case 'downarrow' if( strcmp(CurrentKey,'uparrow')) return; end otherwise return; end switch CurrentKey case {'leftarrow','rightarrow','uparrow','downarrow'} if ~getappdata(handles.figure1,'flag') setappdata(handles.figure1,'direction',CurrentKey); end otherwise return; end; % pause(0.4); % -------------------------------------------------------------------- function Exit_Callback(hObject, eventdata, handles) % hObject handle to Exit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close; % -------------------------------------------------------------------- function About_Callback(hObject, eventdata, handles) % hObject handle to About (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) msgbox('matlab snake version 1.0 by palsword'); % -------------------------------------------------------------------- function Help_Callback(hObject, eventdata, handles) % hObject handle to Help (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) msgbox('上下左右键控制贪吃蛇的移动方向!'); % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Start_Callback(hObject, eventdata, handles);

资源文件列表:

基于MATLAB的贪吃蛇(完美运行).zip 大约有9个文件
  1. 基于MATLAB的贪吃蛇(完美运行)/
  2. 基于MATLAB的贪吃蛇(完美运行)/Snake/
  3. 基于MATLAB的贪吃蛇(完美运行)/Snake/background.jpg 59.07KB
  4. 基于MATLAB的贪吃蛇(完美运行)/Snake/mainfc.p 202B
  5. 基于MATLAB的贪吃蛇(完美运行)/Snake/modifyscore.m 357B
  6. 基于MATLAB的贪吃蛇(完美运行)/Snake/randblock.m 437B
  7. 基于MATLAB的贪吃蛇(完美运行)/Snake/Snake.fig 5.39KB
  8. 基于MATLAB的贪吃蛇(完美运行)/Snake/Snake.m 7.81KB
  9. 基于MATLAB的贪吃蛇(完美运行)/Snake/snake_move.m 3.75KB
0评论
提交 加载更多评论
其他资源 pojo、mapper文件自动生成
通过表名自动生成pojo层和mapper文件以及mapper.xml映射文件。内部包含所有配置文件以及说明文档。
百度百科新闻小说word2vec预训练中文模型
百度语料库的Word2Vec模型 百度的Word2Vec模型是基于其内部收集的大量中文文本数据训练而成的。这些数据涵盖了新闻、网页、社交媒体等多种来源,确保了模型的广泛性和实用性。百度的Word2Vec模型通常具有以下特点: 大规模:训练数据集巨大,覆盖了丰富的语言现象。 高质量:经过精心清洗和处理,保证了模型的准确性。 开放性:百度有时会公开发布这些模型,供学术界和工业界免费使用。 一旦下载了模型,用户需要了解如何加载并使用这些词向量。通常,这涉及到将模型文件导入到Python环境中,使用如gensim这样的库来读取和操作模型。
《灰色预测理论及其应用》Matlab程序.zip
《灰色预测理论及其应用》Matlab程序.zip
【C语言指针】深入浅出:指针与取值、数组、函数; 详细剖析:指针函数、函数指针、指针数组、数组指针、双重指针、指针与动态内存分配
深入浅出:指针与取值、数组、函数; 详细剖析:指针函数、函数指针、指针数组、数组指针、双重指针、指针与动态内存分配 个人总结要点: 本质: 地址要用指针来存储,指针是用来存储地址的!!! 重难点: 指针指向的地址,也就是指针存储的地址!!! 就像整型数据要用整型变量来存储,整型变量是用来存储整型数据的! 地址: 地址值: ptr/∑ 取出地址所存的值: *a/sum; 地址所存的值的类型 : int 典例:函数指针 void(* Fun)(void) 地址值: Fun 取出地址所存的值: * Fun 地址所存的值的类型: void (即为函数类型) Tips: 指针(*)则右边是它指向的地址的标识符(也可以称为指针变量),左边为它指向的地址所存的值的类型; 函数(Function)则右边为参数,左边为返回值;
基于MATLAB的数字图像处理(完美运行)
数字图像处理是指利用计算机科学和数字信号处理的技术来改进和增强图像的质量、改变图像的外观、提取图像的特征以及实现图像分析和理解的过程。数字图像处理可以包括图像增强、图像复原、图像压缩、图像分割、图像识别等多个方面。 在数字图像处理中,常用的技术包括滤波、边缘检测、图像配准、图像重建、图像融合等。滤波可以通过去噪、增强细节等方式改善图像的质量。边缘检测可以找出图像中物体的边界。图像配准可以将多幅图像对齐,用于图像拼接或者图像叠加。图像重建可以根据有损压缩后的图像进行恢复,以提高图像质量。图像融合可以将多个图像的信息融合成一个图像,用于提高图像的观看效果。 数字图像处理在许多领域中都有广泛的应用,包括医学图像处理、遥感图像处理、安全监控、计算机视觉等。医学图像处理可以用于诊断和治疗,例如通过图像分割和特征提取来辅助疾病检测。遥感图像处理可以用于地理信息系统和环境监测,例如通过图像分类和变化检测来分析土地利用和覆盖变化。安全监控可以通过图像识别和分析来实现人脸识别和行为分析。计算机视觉可以用于机器人导航、自动驾驶等领域。 总的来说,数字图像处理是一门利用计算机和数字信号处理技术来处理和
课件,技术分享课件上传
课件,技术分享课件上传
课件,技术分享课件上传 课件,技术分享课件上传 课件,技术分享课件上传
Kinovea.Setup.0.8.15.zip
Kinovea.Setup.0.8.15.zip
Google Chrome下载程序ChromeSetup83.0.和VSCodeUserSetup-x64-1.89.1.exe
Google Chrome下载程序ChromeSetup83.0.和VSCodeUserSetup-x64-1.89.1.exe