mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Games: Use new format functions.
This commit is contained in:
parent
56cf272ed5
commit
80e23d1b98
Notes:
sideshowbarker
2024-07-19 01:52:22 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/80e23d1b985 Pull-request: https://github.com/SerenityOS/serenity/pull/3776 Reviewed-by: https://github.com/alimpfard
3 changed files with 8 additions and 7 deletions
|
@ -101,7 +101,7 @@ int main(int argc, char** argv)
|
||||||
auto update = [&]() {
|
auto update = [&]() {
|
||||||
board_view.set_board(&game.board());
|
board_view.set_board(&game.board());
|
||||||
board_view.update();
|
board_view.update();
|
||||||
statusbar.set_text(String::format("Score: %d", game.score()));
|
statusbar.set_text(String::formatted("Score: {}", game.score()));
|
||||||
};
|
};
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
@ -160,7 +160,7 @@ int main(int argc, char** argv)
|
||||||
case Game::MoveOutcome::Won:
|
case Game::MoveOutcome::Won:
|
||||||
update();
|
update();
|
||||||
GUI::MessageBox::show(window,
|
GUI::MessageBox::show(window,
|
||||||
String::format("You reached %d in %zu turns with a score of %d", game.target_tile(), game.turns(), game.score()),
|
String::formatted("You reached {} in {} turns with a score of {}", game.target_tile(), game.turns(), game.score()),
|
||||||
"You won!",
|
"You won!",
|
||||||
GUI::MessageBox::Type::Information);
|
GUI::MessageBox::Type::Information);
|
||||||
start_a_new_game();
|
start_a_new_game();
|
||||||
|
@ -168,7 +168,7 @@ int main(int argc, char** argv)
|
||||||
case Game::MoveOutcome::GameOver:
|
case Game::MoveOutcome::GameOver:
|
||||||
update();
|
update();
|
||||||
GUI::MessageBox::show(window,
|
GUI::MessageBox::show(window,
|
||||||
String::format("You reached %d in %zu turns with a score of %d", game.largest_tile(), game.turns(), game.score()),
|
String::formatted("You reached {} in {} turns with a score of {}", game.largest_tile(), game.turns(), game.score()),
|
||||||
"You lost!",
|
"You lost!",
|
||||||
GUI::MessageBox::Type::Information);
|
GUI::MessageBox::Type::Information);
|
||||||
start_a_new_game();
|
start_a_new_game();
|
||||||
|
|
|
@ -45,7 +45,7 @@ SnakeGame::SnakeGame()
|
||||||
|
|
||||||
auto config = Core::ConfigFile::get_for_app("Snake");
|
auto config = Core::ConfigFile::get_for_app("Snake");
|
||||||
m_high_score = config->read_num_entry("Snake", "HighScore", 0);
|
m_high_score = config->read_num_entry("Snake", "HighScore", 0);
|
||||||
m_high_score_text = String::format("Best: %u", m_high_score);
|
m_high_score_text = String::formatted("Best: {}", m_high_score);
|
||||||
}
|
}
|
||||||
|
|
||||||
SnakeGame::~SnakeGame()
|
SnakeGame::~SnakeGame()
|
||||||
|
@ -146,10 +146,10 @@ void SnakeGame::timer_event(Core::TimerEvent&)
|
||||||
if (m_head == m_fruit) {
|
if (m_head == m_fruit) {
|
||||||
++m_length;
|
++m_length;
|
||||||
++m_score;
|
++m_score;
|
||||||
m_score_text = String::format("Score: %u", m_score);
|
m_score_text = String::formatted("Score: {}", m_score);
|
||||||
if (m_score > m_high_score) {
|
if (m_score > m_high_score) {
|
||||||
m_high_score = m_score;
|
m_high_score = m_score;
|
||||||
m_high_score_text = String::format("Best: %u", m_high_score);
|
m_high_score_text = String::formatted("Best: {}", m_high_score);
|
||||||
update(high_score_rect());
|
update(high_score_rect());
|
||||||
auto config = Core::ConfigFile::get_for_app("Snake");
|
auto config = Core::ConfigFile::get_for_app("Snake");
|
||||||
config->write_num_entry("Snake", "HighScore", m_high_score);
|
config->write_num_entry("Snake", "HighScore", m_high_score);
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <LibGUI/MenuBar.h>
|
#include <LibGUI/MenuBar.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -48,7 +49,7 @@ int main(int argc, char** argv)
|
||||||
window->resize(SolitaireWidget::width, SolitaireWidget::height);
|
window->resize(SolitaireWidget::width, SolitaireWidget::height);
|
||||||
|
|
||||||
auto widget = SolitaireWidget::construct(window, [&](uint32_t score) {
|
auto widget = SolitaireWidget::construct(window, [&](uint32_t score) {
|
||||||
window->set_title(String::format("Score: %u - Solitaire", score));
|
window->set_title(String::formatted("Score: {} - Solitaire", score));
|
||||||
});
|
});
|
||||||
|
|
||||||
auto menubar = GUI::MenuBar::construct();
|
auto menubar = GUI::MenuBar::construct();
|
||||||
|
|
Loading…
Reference in a new issue