- “gfc” function: https://www.mathworks.com/help/matlab/ref/gcf.html
- “figure” function: https://www.mathworks.com/help/matlab/ref/figure.html
Need help with getting my function to work properly
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I created a function for my hangman game that creates body parts after every incorrect guess that creates a skeleton but whenever i add call and use function in my script, the skeleton updates like its supposed to but stays minimized without popping back up while running the game. I tried "figure(1)", i tried "hold on". Is there a fix with the function or script?
I need help getting the interface to pop up on the screen after every incorrect guess instead of staying minimized
This is my function
function HangingMan(incorrectGuesses, difficulty)
D1P = cell(12, 1);
for i = 1:12
D1P{i} = imread(sprintf('D1I%d.jpg', i));
end
if difficulty == 1 && incorrectGuesses >= 1 && incorrectGuesses <= 12
image(D1P{incorrectGuesses});
end
D2P = cell(9, 1);
for i = 1:9
D2P{i} = imread(sprintf('D2I%d.jpg', i));
end
if difficulty == 2 && incorrectGuesses >= 1 && incorrectGuesses <= 9
image(D2P{incorrectGuesses});
end
D3P = cell(7, 1);
for i = 1:7
D3P{i} = imread(sprintf('D3I%d.jpg', i));
end
if difficulty == 3 && incorrectGuesses >= 1 && incorrectGuesses <= 7
image(D3P{incorrectGuesses});
end
end
0 commentaires
Réponses (1)
Aishwarya
le 7 Nov 2023
Hi Laith,
As per my understanding, in the provided function, the figure window should pop up after every incorrect guess.
After reviewing the code, I would suggest to add “figure(gcf)” command before each “image” function to pop up the updated figure window. After making the changes, the modified function is as shown below.
function HangingMan(incorrectGuesses, difficulty)
D1P = cell(12, 1);
for i = 1:12
D1P{i} = imread(sprintf('D1I%d.jpg', i));
end
if difficulty == 1 && incorrectGuesses >= 1 && incorrectGuesses <= 12
figure(gcf);
image(D1P{incorrectGuesses});
end
D2P = cell(9, 1);
for i = 1:9
D2P{i} = imread(sprintf('D2I%d.jpg', i));
end
if difficulty == 2 && incorrectGuesses >= 1 && incorrectGuesses <= 9
figure(gcf);
image(D2P{incorrectGuesses});
end
D3P = cell(7, 1);
for i = 1:7
D3P{i} = imread(sprintf('D3I%d.jpg', i));
end
if difficulty == 3 && incorrectGuesses >= 1 && incorrectGuesses <= 7
figure(gcf);
image(D3P{incorrectGuesses});
end
end
Please refer to the below MathWorks documentation for more information about the functions used:
I hope this helps!
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!