Create a highscore im matlab GUI video game

30 ビュー (過去 30 日間)
Ruslan Avramenko
Ruslan Avramenko 2022 年 5 月 1 日
コメント済み: Ruslan Avramenko 2022 年 5 月 6 日
Hi everyone. I need some help. I do small projekt for my matlab classes and there is a game created in matlab app designer. Everything is fine but I want to create a highscore in my videogame. Now I can write a last score but I need somehow to write the highest. I did it with function max but it dosen't work. Need some help please.
PS: my cod in attached files. It's GUI but I also use obvius matlab to write cod and now I need to create a highscore in GUI :)

採用された回答

Geoff Hayes
Geoff Hayes 2022 年 5 月 6 日
@Ruslan Avramenko - in the restart button callback, you will want to compare the number in the high score field with that in the current score field. Something like
function RestartButtonPushed(app, event)
stop(app.t);
app.Label_3.Text = num2str(max(str2double(app.Label.Text), str2double(app.Label_3.Text)))
app.Label.Text = num2str(0);
app.Label_2.Text = num2str(60);
app.t = timer;
StartButtonPushed(app,event);
end
I think that you could make these two fields, Label and Labe_3, numeric text fields so that you could avoid the conversion to and from strings.
  1 件のコメント
Ruslan Avramenko
Ruslan Avramenko 2022 年 5 月 6 日
Thank you so much! Now it works :)

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 5 月 6 日
You can store the high score in a file. Test if the file exists and if so load the previous high score information. Each time a game completes save the high score information
Or... you can use https://www.mathworks.com/help/matlab/ref/setpref.html setpref to record the high score without writing a file.

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by