Games: Use new format functions.

This commit is contained in:
asynts 2020-10-15 12:26:33 +02:00 committed by Andreas Kling
parent 56cf272ed5
commit 80e23d1b98
Notes: sideshowbarker 2024-07-19 01:52:22 +09:00
3 changed files with 8 additions and 7 deletions

View file

@ -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();

View file

@ -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);

View file

@ -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();