フィルターのクリア

Need help with getting my function to work properly

1 回表示 (過去 30 日間)
Laith
Laith 2023 年 10 月 30 日
回答済み: Aishwarya 2023 年 11 月 7 日
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

回答 (1 件)

Aishwarya
Aishwarya 2023 年 11 月 7 日
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 “imagefunction 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!

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by