- You can merge task one with two, by tracking the number of clicks, if it's the first click, then it's time to initialise the matrix. Otherwise, if any field in the matrix have different value from the default ones, then initial matrix shouldn't be generated.
- Let's say that you have generated a matrix from the step 1. and by clicking on one button, it will generate an array of elements (mine fields) to be uncovered. Depending on the element values you can generate a list of actions: if the field is mine, display M on button, if it's empty, change color, if it's next to mines, display number, and lastly, if it's mine.
- You can use condition of ButtonDownFcn (right mouse click) to detect if user wants to place a mark, but it is not easy to detect on which field your cursor is on. You can have a toggle button for mine, which might be impractical.
Matlab AppDesigner Project Problems
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello
I'm making a school project where I have to create an 8x8 Minesweeper using Matlab Appdesigner buttons and I have a few problems with the different callbacks:
1st- Generate the matrix numbers when you click the first button instead of clicking a "Start" button I have created
2nd- Activate the callback of one button from another when the button is blank and the other button is not a mine
3rd- Mark the mines instead of exploding them
Any help will be appreciated
I write the code below
Start button code:
app.A=zeros(8);
app.A(1:8)=nan;
orden=randperm(64);
app.A=app.A(orden);
app.A=reshape(app.A,8,8);
for k=1:8
for j=1:8
if app.A(k,j)==0
min([k-1,1]);
app.A(k,j)=sum(sum(isnan(app.A(max([k-1,1]):min([k+1,8]),max([j-1,1]):min([j+1,8])))));
end
end
end
First button code:
TF=isnan(app.A);
if TF(1,1)~=1
a=app.A(1,1);
end
app.Button.BackgroundColor="white";
if a==1
app.Button.Text="1";
elseif a==2
app.Button.Text="2";
elseif a==3
app.Button.Text="3";
elseif a==4
app.Button.Text="4";
elseif a==5
app.Button.Text="5";
elseif a==6
app.Button.Text="6";
elseif a==7
app.Button.Text="7";
elseif a==8
app.Button.Text="8";
elseif a==0
if app.tr2~=1 && TF(2,1)~=1
b = uibutton(app.UIFigure);
b.ButtonPushedFcn = @app.Button_2;
end
if app.tr9~=1 && TF (1,2)~=1
b = uibutton(app.UIFigure);
b.ButtonPushedFcn = @app.Button_9;
end
if app.tr10~=1 && TF(2,2)~=1
b = uibutton(app.UIFigure);
b.ButtonPushedFcn = @app.Button_10;
end
elseif TF(1,1)==1
app.Button.Text="M";
app.Nota.Text="Has perdido, PULSA RESET";
end
app.tr1=1;
1 Commento
Mario Malic
il 9 Gen 2021
Hi Daniel,
I'd suggest to break down your problem in tinier pieces, it is hard for us to easily understand your code because there are no comments.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Entering Commands in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!