2048游戏matlab代码.docx
文本预览下载声明
说明:本代码为2048游戏matlab代码,程序未进行游戏结束判定,节目如下。function g2048(action)global totalscore flag score_boardif nargin1 figure_h=figure; set(figure_h,Units,points) set(figure_h,UserData,figure_h); totalscore=0; flag=0; score_board=zeros(1,16); action=initialize;endswitch actioncaseinitialize; figure_h=get(gcf,UserData); set(figure_h,...Color,[0.4 0.4 0.4],...Menubar,none,...Name,2048,...NumberTitle,off,...Position,[200 200 320 355],...Resize,off); axis(off)game_score=uicontrol(figure_h,...BackgroundColor,[1 1 1],...ForegroundColor,[0 0 0], ...HorizontalAlignment,center,...FontSize,12,...Units,points,...Position,[235 305 65 30],...String,Score,...Style,edit,...Tag,game_score); new_game_h=uicontrol(figure_h,...Callback,g2048 restart,...FontSize,12, ...Units,points,...Position,[35 30 65 30],...String,New Game,...Style,pushbutton);% close close_h=uicontrol(figure_h,...Callback,close(gcf),...Fontsize,12, ...Units,points,...Position,[225 30 65 30],...String,Close,...Style,pushbutton);% right move_right=uicontrol(figure_h,...Callback,g2048 right,...Fontsize,12, ...Units,points,...Position,[255 185 60 30],...String,Right,...Style,pushbutton);% left move_left=uicontrol(figure_h,...Callback,g2048 left,...Fontsize,12, ...Units,points,...Position,[5 185 60 30],...String,Left,...Style,pushbutton);% up move_up=uicontrol(figure_h,...Callback,g2048 up,...Fontsize,12, ...Units,points,...Position,[130 300 60 30],...String,Up,...Style,pushbutton);% down move_down=uicontrol(figure_h,...Callback,g2048 down,...Fontsize,12, ...Units,points,...Position,[130 80 60 30],...String,Down,...Style,pushbutton);% setup the game board irows=1;for counter=1:16 jcols=rem(counter,4);if jcols==0 jcols=4;end position=[40*jcols+40 85+40*irows 40 40]; index=(irows-1)*4+jcols;if jcols==4 irows=irows+1;end board.squares(index)=uicontrol(figure_h,...FontSize,18,...FontWeight,bold,...Units,points,...Position,position,...Style,pushbutton,...Tag,num2str(index));end set(f
显示全部