您当前的位置: 首页 >  游戏

slandarer

暂无认证

  • 4浏览

    0关注

    248博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

matlab 生命游戏 可自己输入图像

slandarer 发布时间:2019-02-28 14:04:31 ,浏览量:4

制作了一个生命游戏的小游戏 上下左右移动红点 空格绘制生命 按键B开始运动 按键C暂停 按键A清空 按键backspace删除生命

游戏截图 在这里插入图片描述 在这里插入图片描述 动图 在这里插入图片描述 代码部分

function lifecontrol
% life game which can input point as you will.
% move the red cross with the key
% 'uparrow','downarrow','leftarrow','rightarrow'
% use the key 'space'to input
% 'bacspace'to delete
% 'b' to begin 'c'to stop and 'a' to restart
    n=50;
    %n=input('the board size is:');
    axis equal
    axis(0.5+[0,n,0,n])
    set(gca,'xtick',[],'ytick',[],'xcolor','w','ycolor','w')
    set(gca,'color','w')
    hold on
    %axis set.........................................................................
    %A=randi(9,[n,n]);
    %A(A2)=1;
    A=zeros(n,n);
    %A=[input sqare with only ones and zeros]
    [a,b]=find(A(:,:)==1);
    B=[b,length(sum(A,2))-a];
    postion=[floor(n/2),floor(n/2)];
    control=1;
    plotl=scatter(gca,B(:,1),B(:,2),1200/n,'ks','filled');
    plotpostion=scatter(gca,postion(1,1),postion(1,2),150,'rx');
    set(gcf, 'KeyPressFcn', @key)                                                     
    fps = 20;                                    
    game = timer('ExecutionMode', 'FixedRate', 'Period',1/fps, 'TimerFcn', @lifeGame);
    start(game) 
%beginning set.............................................................................
set(gcf,'tag','co','CloseRequestFcn',@clo);
    function clo(~,~)
        stop(game)
        delete(findobj('tag','co'))
        clf
        close
    end
    function lifeGame(~,~)
        
        chang=length(sum(A,2));
        postion(postion>chang)=postion(postion>chang)-chang;
        postion(postion            
关注
打赏
1664692598
查看更多评论
0.0357s