A list,

Matlab based minesweeper game

Ii. Source code

clear 
row=10;
col=10;
num=30;
jieshu=0; %global flag; flag=zeros(row,col); flag1=ones(row,col); minenum=zeros(row,col); minefield=rand(row,col); [temp,index]=sort(minefield(:)); minefield=(minefield<=minefield(index(num))); % generates the corresponding minesweeper10*10Matrix, where1Minefield count=0;
for i=1: the row %forThe loop detects the number of mines around each position in the Minefield matrix and stores the results in the matrix Minenumfor j=1:col
      x1=i- 1; y1=j- 1;
      x2=i- 1; y2=j; x3=i- 1; y3=j+1;
      x4=i;  y4=j- 1;
      x5=i;  y5=j+1;
      x6=i+1; y6=j- 1;
      x7=i+1; y7=j; x8=i+1; y8=j+1;
      if x1>0&&y1>0
          if minefield(x1,y1)= =1
              count=count+1;
          end
      end
      if x2>0
          if minefield(x2,y2)= =1
        count=count+1;
          end
      end
      if x3>0&&y3<11
          if minefield(x3,y3)= =1
              count=count+1;
          end
      end
      if y4>0
          if minefield(x4,y4)= =1
          count=count+1;
          end
      end
      if y5<11
          if minefield(x5,y5)= =1
              count=count+1;
          end
      end
      if x6<11&&y6>0
          if minefield(x6,y6)= =1
              count=count+1;
          end
      end
      if x7<11
          if minefield(x7,y7)= =1
              count=count+1;
          end
      end
      if x8<11&&y8<11
          if minefield(x8,y8)= =1
              count=count+1;
          end
      end
    minenum(i,j)=count;
    count=0;
    end
end


tic;

hf=figure('NumberTitle'.'off'.'Name'.'mine'.'menubar'.'none'); % Call figure to generate a graphical interface uh1=uimenu('label'.'games'); % Next few uIMenu application menu bar uimenu(uh1,'label'.'Background color selection'.'callback'.'c=uisetcolor([0 0 1],''Select color''); set(hf,''color'',c); ');
uh2=uimenu('label'.'help'); %callback, left-click to trigger a label in the menu bar, and then proceed with the following operations, such as selecting the color uimenu(uh2,'label'.'Rules of the game'.'callback'['the text (0.05, 0,''Similar to regular minesweeper, except that after right-clicking, it is marked in red as a possible minefield, while real minefields are marked in black.'', ''fontsize'', 12,'fontname'', ''宋体''); '.'hold on; The text (0.12, 0.07, ''A Hallelujah song for you when you lose & voice prompt, and voice prompt when you win! '', ''fontsize'', 12,'fontname'', ''宋体''); axis off ']);
uimenu(uh2,'label'.'Make a message'.'callback'.'msgbox(''copyright:Wteng  Thanks for using!'') ');
for m=1:row
    for n=1:col
       h(m,n)=uicontrol(gcf,'style'.'push'. The %uicontrol function creates a uicontrol uicontrol that implements the graphical user interface, where GCF refers to the current figure and the style is pushbutton'foregroundColor'.0.7* [1.1.1],...
            'string'.strcat(num2str(m),num2str(n)),... %num2str converts numbers to characters,strcatThe function is a function that concatenates characters horizontally'unit'.'normalized'.'position'[0.16+0.053*n,0.90.073*m,0.05.0.07],...
            'BackgroundColor'.0.7* [1.1.1].'fontsize'.17.'fontname'.'times new roman'.'ButtonDownFcn'['if isequal(get(gcf,''SelectionType''), ''alt'') '. The %ButtonDownFcn function is called when the mouse key (left, right, or middle) is pressed on the control.' if ~get(gco,''Value'') if isequal(get(gco,''Tag''), ''y'') '. %gco returns the handle value for the current mouse click'set(gco,''style'', ''push'', ''string'', '' ' '.''backgroundcolor'', 0.7 * [1 1 1)); '.Copy the code

3. Operation results

Fourth, note

Version: 2014a complete code or write plus 1564658423